Permalink
Browse files

better GLOB detection

  • Loading branch information...
1 parent 4a1508b commit 3f61fd08698efb96184dec18bad7a7e4ae3600a2 @tomill committed Mar 3, 2010
Showing with 16 additions and 1 deletion.
  1. +3 −1 lib/Template/Semantic.pm
  2. +13 −0 t/01_load-template.t
View
@@ -4,6 +4,7 @@ use warnings;
use 5.008000;
our $VERSION = '0.04';
use Carp;
+use Scalar::Util qw/blessed/;
use XML::LibXML;
use Template::Semantic::Document;
use Template::Semantic::Filter;
@@ -48,7 +49,8 @@ sub process {
my $source;
if (ref($template) eq 'SCALAR') {
$source = $$template;
- } elsif (ref $template) {
+ } elsif (ref($template) eq 'GLOB'
+ or blessed($template) && $template->isa('GLOB')) {
$source = do { local $/; <$template> };
} else {
open(my $fh, '<', $template) or croak $!;
View
@@ -1,6 +1,7 @@
use strict;
use warnings;
use Test::More;
+use Test::Requires;
use Template::Semantic;
@@ -53,4 +54,16 @@ subtest 'file' => sub {
is($output, $expected);
};
+subtest 'unknown object' => sub {
+ test_requires('Path::Class');
+ plan tests => 1;
+
+ my $ts = Template::Semantic->new;
+ my $output = $ts->process(file('t/01_load-template.xml'), {
+ 'span' => 'HELLO WORLD',
+ });
+
+ is($output, $expected);
+};
+
done_testing;

0 comments on commit 3f61fd0

Please sign in to comment.