Skip to content

Instantly share code, notes, and snippets.

@nihen
Created May 31, 2013 11:19
Show Gist options
  • Save nihen/5684352 to your computer and use it in GitHub Desktop.
Save nihen/5684352 to your computer and use it in GitHub Desktop.
package MyCounter;
sub new { my $class = shift;bless {@_} => $class }
sub incr { shift->{count}++ }
sub decr { shift->{count}-- }
sub count { shift->{count} }
package main;
use Text::Xslate;
my $tx = Text::Xslate->new(
cache => 1,
syntax => 'TTerse',
path => {
'recurse.tt' => q{
[%- MACRO mymacro BLOCK -%]
[%- CALL recurse_count.decr -%]
[%- IF recurse_count.count -%]
[%- mymacro() -%]
[%- END -%]
[%- END -%]
[%- mymacro() -%]
},
},
);
say '-- try 1 --';
eval { say $tx->render('recurse.tt', { recurse_count => MyCounter->new(count => 101) }); } or say $@;
say '-- try 2 --';
eval { say $tx->render('recurse.tt', { recurse_count => MyCounter->new(count => 101) }); } or say $@;
say '-- try 3 --';
eval { say $tx->render('recurse.tt', { recurse_count => MyCounter->new(count => 102) }); } or say $@;
say '-- try 4 --';
eval { say $tx->render('recurse.tt', { recurse_count => MyCounter->new(count => 101) }); } or say $@;
__END__
-- try 1 --
-- try 2 --
-- try 3 --
Text::Xslate: Macro call is too deep (> 100) at tmp/test.pl line 45.
(<string>:5) at tmp/test.pl line 45.
eval {...} called at tmp/test.pl line 45
-- try 4 --
Text::Xslate: Macro call is too deep (> 100) at tmp/test.pl line 48.
(<string>:5) at tmp/test.pl line 48.
eval {...} called at tmp/test.pl line 48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment