Last active
December 27, 2015 12:59
-
-
Save soh335/7330291 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
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