1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
use Test::More tests => 7;
use HTML::Template::Pluggable;
use HTML::Template::Plugin::Dot;
use Carp 'croak';
sub render {
my( $template, @vars ) = @_;
my $t = HTML::Template::Pluggable->new(
scalarref => \$template
);
eval { $t->param( @vars ) };
return $t->output;
}
my $out;
$out = render(
"<tmpl_var testobj.attribute>",
testobj => testclass->new()
);
is( $out, 'attribute_value' );
$out = render(
"<tmpl_var testobj.hello>",
testobj => testclass->new()
);
is( $out, 'hello' );
$out = render(
"<tmpl_var testobj.echo('1')>",
testobj => testclass->new()
);
is( $out, '1' );
$out = render(
"<tmpl_var testobj.echo(somevar)>",
testobj => testclass->new(),
somevar => 'somevalue4'
);
is( $out, 'somevalue4' );
$out = render(
"<tmpl_var name=\"testobj.test(somevar)\">",
testobj => testclass->new(),
somevar => 'somevalue5'
);
# contribution expected 'somevalue5', but since test() isn't
# a method of testclass, this should return nothing.
is( $out, '' );
$out = render(
"<tmpl_var name='somevar'><tmpl_var testobj.echo(somevar)>",
testobj => testclass->new(),
somevar => 'somevalue'
);
is( $out, 'somevaluesomevalue' );
$out = render(
"<tmpl_var name='somevar'>",
somevar => 'somevalue6',
testobj => testclass->new(),
nope => 42,
);
is( $out, 'somevalue6' );
package testclass;
sub new {
my $class = shift;
my $self = { attribute => 'attribute_value' };
return bless $self, $class;
}
sub echo {
shift;
return join(', ', @_);
}
sub hello {
return 'hello';
}
__END__
|