Template-Toolkit
view release on metacpan or search on metacpan
t/unicode.t view on Meta::CPAN
COMPILE_DIR => $args{tempdir},
COMPILE_EXT => ".ttcache");
}
sub test_it {
local $Test::Builder::Level = $Test::Builder::Level + 1;
my $name = shift;
my $tt = shift;
my $filenames = shift;
my $string = shift;
foreach my $encoding (keys %{ $filenames })
{
my $output;
$tt->process($filenames->{ $encoding },{},\$output)
or $output = $tt->error;
is(reasciify($output), reasciify($string), "$name - $encoding");
}
}
#------------------------------------------------------------------------
# reascify($string)
#
# escape all the high and low chars to \x{..} sequences
#------------------------------------------------------------------------
sub reasciify {
my $string = shift;
$string = join '', map {
my $ord = ord($_);
($ord > 127 || ($ord < 32 && $ord != 10))
? sprintf '\x{%x}', $ord
: $_
} split //, $string;
return $string;
}
#------------------------------------------------------------------------
# write_to_temp_file( dir => $dir, filename => $file, text => $text)
#
# escape all the high and low chars to \x{..} sequences
#------------------------------------------------------------------------
sub write_to_temp_file {
my %args = @_;
# use a temp dir unless one was specified. We automatically
# delete the contents when we're done with the tempdir, where
# otherwise we just leave the files lying around.
unless (exists $args{dir}) {
$args{dir} = tempdir( CLEANUP => 1 );
}
# work out where we're going to store it
my $temp_filename = catfile($args{dir}, $args{filename});
# open a filehandle with some PerlIO magic to convert data into
# the correct encoding with the correct BOM on the front
open my $temp_fh, ">:raw", $temp_filename
or die "Can't write to '$temp_filename': $!";
# write the data out
print $temp_fh $args{text};
close $temp_fh;
# return where we've created it
return $temp_filename;
}
( run in 0.367 second using v1.01-cache-2.11-cpan-5a3173703d6 )