読者です 読者をやめる 読者になる 読者になる

Text::Xslate 3.3.6 released

perl

https://metacpan.org/release/SYOHEX/Text-Xslate-3.3.6

I released Text::Xslate 3.3.6. This version fixed include issue.

Include Issue

Perl VM stack pointer goes wrong by each include call. For example.

#!perl
use strict;
use warnings;
use Text::Xslate;

my $tx = Text::Xslate->new(
    path => {
        'body.tx' => ': block body | reverse -> { include text }',
        'text.tx' => 'foo',
    },
    function => {
        reverse => sub { scalar reverse $_[0] },
    },
);

print $tx->render('body.tx');

reverse function takes foo as first argument but it is undefined value.

% perl test.pl
Text::Xslate: Use of uninitialized value $_[0] in reverse at test.pl line 12.
 (<string>:1) at test.pl line 12.
    main::__ANON__(undef, foo) called at test.pl line 16
    eval {...} called at test.pl line 1

Why this behavior ? Because foo is 2nd argument. Following code works well.

#!perl
use strict;
use warnings;
use Text::Xslate;

my $tx = Text::Xslate->new(
    path => {
        'body.tx' => ': block body | reverse -> { include text }',
        'text.tx' => 'foo',
    },
    function => {
        reverse => sub { scalar reverse $_[1] },
    },
);

print $tx->render('body.tx');

oof is printed. If include is called two times, foobar is 3rd argument. 1st and 2nd arguments are undef.

#!perl
use strict;
use warnings;
use Text::Xslate;

my $tx = Text::Xslate->new(
    path => {
        'body.tx' => ': block body | reverse -> { include text; include text2 }',
        'text.tx' => 'foo',
        'text2.tx' => 'bar',
    },
    function => {
        reverse => sub { scalar reverse $_[2] },
    },
);

print $tx->render('body.tx');

Conclusion

I released Text::Xslate 3.3.6. Please report us via github issues if you have any problems.