Skip to content

Instantly share code, notes, and snippets.

@soh335
Last active December 27, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soh335/7330291 to your computer and use it in GitHub Desktop.
Save soh335/7330291 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Text::Xslate::Syntax::Kolon;
# simple.tx
# : cascade hoge {
# : hoge => 'fuga'
# : }
#
# : around content -> {
# : }
bad("simple.tx");
# Text::Xslate::Syntax::Kolon: Invalid expression found, while parsing templates (<string>:2) at /Users/kitahara-so/prog/kayac/nakamap/web/test.pl line 21.
# ----------------------------------------------------------------------------
# : cascade hoge {
# : hoge => 'fuga'
# : }
# ----------------------------------------------------------------------------
safe("simple.tx");
# ok
# https://github.com/clintongormley/locale-maketext-lexicon/blob/master/lib/Locale/Maketext/Extract.pm#L540
sub bad {
my $file = shift;
local ( $/, *FH );
open FH, $file or die "Error reading from file '$file' : $!";
my $content = scalar <FH>;
my $parser = Text::Xslate::Syntax::Kolon->new(
verbose => 1,
warnings => 1,
);
$parser->parse($content);
close FH;
}
sub safe {
my $file = shift;
open my $fh, '<', $file or die $!;
my $content = do { local $/; <$fh> };
my $parser = Text::Xslate::Syntax::Kolon->new(
verbose => 1,
warnings => 1,
);
$parser->parse($content);
close $fh;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment