Created
July 15, 2013 21:23
-
-
Save ian-kent/6003638 to your computer and use it in GitHub Desktop.
Some examples - working, erroring and segfaulting
This file contains hidden or 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 obj2; | |
sub new { my ($package, %args) = @_; bless { %args }, 'obj2' }; | |
sub render { shift->{obj}->() }; | |
package obj; | |
sub new { bless {}, 'obj' }; | |
sub capture { return obj2->new(obj => pop) } | |
package main; | |
use Data::Dumper; | |
use Text::Xslate; | |
my $count = 0; | |
my $macro = undef; | |
my $xslate = Text::Xslate->new( | |
path => { | |
'test.tx' => qq{ | |
: \$obj.capture(-> { | |
Rendering <: count() :> | |
: }).render | |
} | |
}, | |
cache => 1, | |
function => { | |
count => sub { | |
++$count; | |
}, | |
capture => sub { | |
$macro = bless { macro => shift }, 'test'; | |
undef; | |
}, | |
render => sub { | |
$macro->{macro}->(); | |
} | |
} | |
); | |
# This fails | |
print $xslate->render('test.tx', { obj => obj->new } ); | |
print $xslate->render('test.tx', { obj => obj->new } ); | |
print $xslate->render('test.tx', { obj => obj->new } ); |
This file contains hidden or 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
39,43c39,42 | |
< # This works | |
< my $param = { obj => obj->new }; | |
< print $xslate->render('test.tx', $param ); | |
< print $xslate->render('test.tx', $param ); | |
< print $xslate->render('test.tx', $param ); | |
--- | |
> # This fails | |
> print $xslate->render('test.tx', { obj => obj->new } ); | |
> print $xslate->render('test.tx', { obj => obj->new } ); | |
> print $xslate->render('test.tx', { obj => obj->new } ); |
This file contains hidden or 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 obj2; | |
sub new { bless { obj => pop }, 'obj2' }; | |
sub render { shift->{obj}->() }; | |
package obj; | |
sub new { bless {}, 'obj' }; | |
sub capture { return obj2->new(pop) } | |
package main; | |
use Data::Dumper; | |
use Text::Xslate; | |
my $count = 0; | |
my $macro = undef; | |
my $xslate = Text::Xslate->new( | |
path => { | |
'test.tx' => qq{ | |
: \$obj.capture(-> { | |
Rendering <: count() :> | |
: }).render | |
} | |
}, | |
cache => 1, | |
function => { | |
count => sub { | |
++$count; | |
}, | |
capture => sub { | |
$macro = bless { macro => shift }, 'test'; | |
undef; | |
}, | |
render => sub { | |
$macro->{macro}->(); | |
} | |
} | |
); | |
# This fails | |
print $xslate->render('test.tx', { obj => obj->new } ); | |
print $xslate->render('test.tx', { obj => obj->new } ); | |
print $xslate->render('test.tx', { obj => obj->new } ); |
This file contains hidden or 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 obj2; | |
sub new { my ($package, %args) = @_; bless { %args }, 'obj2' }; | |
sub render { shift->{obj}->() }; | |
package obj; | |
sub new { bless {}, 'obj' }; | |
sub capture { return obj2->new(obj => pop) } | |
package main; | |
use Data::Dumper; | |
use Text::Xslate; | |
my $count = 0; | |
my $macro = undef; | |
my $xslate = Text::Xslate->new( | |
path => { | |
'test.tx' => qq{ | |
: \$obj.capture(-> { | |
Rendering <: count() :> | |
: }).render | |
} | |
}, | |
cache => 1, | |
function => { | |
count => sub { | |
++$count; | |
}, | |
capture => sub { | |
$macro = bless { macro => shift }, 'test'; | |
undef; | |
}, | |
render => sub { | |
$macro->{macro}->(); | |
} | |
} | |
); | |
# This segfaults | |
my $param = { obj => obj->new }; | |
print $xslate->render('test.tx', $param ); | |
print $xslate->render('test.tx', $param ); | |
print $xslate->render('test.tx', $param ); |
This file contains hidden or 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 obj2; | |
sub new { bless { obj => pop }, 'obj2' }; | |
sub render { shift->{obj}->() }; | |
package obj; | |
sub new { bless {}, 'obj' }; | |
sub capture { return obj2->new(pop) } | |
package main; | |
use Data::Dumper; | |
use Text::Xslate; | |
my $count = 0; | |
my $macro = undef; | |
my $xslate = Text::Xslate->new( | |
path => { | |
'test.tx' => qq{ | |
: \$obj.capture(-> { | |
Rendering <: count() :> | |
: }).render | |
} | |
}, | |
cache => 1, | |
function => { | |
count => sub { | |
++$count; | |
}, | |
capture => sub { | |
$macro = bless { macro => shift }, 'test'; | |
undef; | |
}, | |
render => sub { | |
$macro->{macro}->(); | |
} | |
} | |
); | |
# This works | |
my $param = { obj => obj->new }; | |
print $xslate->render('test.tx', $param ); | |
print $xslate->render('test.tx', $param ); | |
print $xslate->render('test.tx', $param ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment