Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • c6699af
  • /
  • external
  • /
  • perl
  • /
  • Text-Template-1.56
  • /
  • t
  • /
  • template-encoding.t
Raw File
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:2dafe779fb026d8b503a6982eff64574db9b5d1b
directory badge Iframe embedding
swh:1:dir:7f3413dd469356106299d911badbf763182377dc
template-encoding.t
#!perl

use utf8;
use strict;
use warnings;
use Test::More;
use Encode;
use File::Temp;

# Non-CORE module(s)
unless (eval { require Test::More::UTF8; 1; } ) {
    plan skip_all => '[ Test::More::UTF8 ] is required for testing';
}

plan tests => 3;

use_ok 'Text::Template' or exit 1;

my $tmp_fh = File::Temp->new;

print $tmp_fh encode('UTF-8', "\x{4f60}\x{597d} {{\$name}}");

$tmp_fh->flush;

# UTF-8 encoded template file
my $str = Text::Template->new(
    TYPE     => 'FILE',
    SOURCE   => $tmp_fh->filename,
    ENCODING => 'UTF-8'
)->fill_in(HASH => { name => 'World' });

is $str, "\x{4f60}\x{597d} World";

$tmp_fh = File::Temp->new;

print $tmp_fh encode('iso-8859-1', "Ol\x{e1} {{\$name}}");

$tmp_fh->flush;

# ISO-8859-1 encoded template file
$str = Text::Template->new(
    TYPE     => 'FILE',
    SOURCE   => $tmp_fh->filename,
    ENCODING => 'iso-8859-1'
)->fill_in(HASH => { name => 'World' });

is $str, "Ol\x{e1} World";

ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top