Created
May 31, 2013 11:19
-
-
Save nihen/5684352 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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