Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
xslate行数調整
#!/usr/bin/env perl
use strict;
use warnings;
use Text::Xslate;
use IO::All;
my $tx = Text::Xslate->new(
syntax => 'TTerse',
verbose => 2,
header => [qw/header.inc/],
footer => [qw/footer.inc/],
macro => [qw/macro.inc/],
);
$tx->{warn_handler} = sub {
my @macro = @{ $tx->{macro} || [] };
my @header = @{ $tx->{header} || [] };
my $line_num;
my $base_path = $tx->{path}->[0];
for my $mh (@macro,@header) {
$line_num += io("${base_path}/${mh}")->getlines;
}
for (@_) {
if (m/\(([^:]+):(\d+)\) at/) {
chomp;
$_ = sprintf("%s adjusted line number: (%s:%s)", $_, $1, $2-$line_num);
}
}
Text::Xslate->note( @_ );
};
my %vars = (
title => 'A list of books',
books => [{
title => 'Islands in the stream'
},{
title => 'Programming Perl'
}],
);
my $template = q{
[% INCLUDE 'include.inc' -%]
[% FOR book IN books -%]
[% book.hogeee # warning %]
[% END -%]
};
print $tx->render_string($template, \%vars);
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment