arg-passing.t 1.21 KB
Newer Older
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
#!/usr/bin/perl
package MyApp::Templates;
use strict;
use warnings;
use Template::Declare::Tags;
use base 'Template::Declare';

template inner => sub {
   my ($self, $arg) = @_;

   div { "inner: $arg" }
};

template outer => sub {
   my ($self, $arg) = @_;

   show('inner', uc $arg);
   div { "outer: $arg" }
};

template add  => sub {
    my ($self, $a, $b) = @_;
    outs "$a + $b";
};

template host => sub {
    my $self = shift;
    show('add', 3, 7);
};

package main;
use strict;
use warnings;
34
use Test::More tests => 9;
35
use Template::Declare;
36
use Template::Declare::Tags;
37
Template::Declare->init(dispatch_to => ['MyApp::Templates']);
38 39 40

my $out = Template::Declare->show('inner', 'inside');
like($out, qr/inner: inside/);
41
is(show('inner', 'inside'), $out, 'show and TD->show are the same');
42 43 44 45

$out = Template::Declare->show('outer', 'xyzzy');
like($out, qr/outer: xyzzy/);
like($out, qr/inner: XYZZY/);
46
is(show('outer', 'xyzzy'), $out, 'show and TD->show are the same');
47 48 49

$out = Template::Declare->show('add', '32', '56');
is($out, '32 + 56');
50
is(show('add', '32', '56'), $out, 'show and TD->show are the same');
51 52 53

$out = Template::Declare->show('host');
is($out, '3 + 7');
54
is(show('host'), $out, 'show and TD->show are the same');