prevent unexpected Data::Dumper config to mess with the output
Tina Mueller
8 years ago
448 | 448 |
|
449 | 449 |
sub dump_string {
|
450 | 450 |
my ($self, $string) = @_;
|
451 | |
my $dump = Data::Dumper->Dump([\$string], ['string']);
|
452 | |
$dump =~ s#^\$string *= *\\##;
|
|
451 |
my $dump = HTML::Template::Compiled->dump_var($string, 'string');
|
|
452 |
$dump =~ s#^\$string *= *## or die "dump_string() failed";
|
453 | 453 |
$dump =~ s/;$//;
|
454 | 454 |
return $dump;
|
455 | 455 |
}
|
|
815 | 815 |
|
816 | 816 |
my $join_code = '';
|
817 | 817 |
if (defined (my $join = $attr->{JOIN})) {
|
818 | |
my $dump = Data::Dumper->Dump([$join], ['join']);
|
819 | |
$dump =~ s{\$join = }{};
|
|
818 |
my $dump = HTML::Template::Compiled->dump_var($join, 'join');
|
|
819 |
$dump =~ s{\$join *= *}{};
|
|
820 |
$dump =~ s{;$}{};
|
820 | 821 |
$join_code = <<"EOM";
|
821 | 822 |
\{
|
822 | 823 |
unless (\$__ix__ == \$[) \{
|
702 | 702 |
return Data::Dumper->Dump( [$var], ['DUMP'] );
|
703 | 703 |
}
|
704 | 704 |
|
|
705 |
sub dump_var {
|
|
706 |
my ($class, $var, $varname) = @_;
|
|
707 |
local $Data::Dumper::Terse = 0;
|
|
708 |
local $Data::Dumper::Indent = 2;
|
|
709 |
local $Data::Dumper::Purity = 0;
|
|
710 |
local $Data::Dumper::Pad = "";
|
|
711 |
local $Data::Dumper::Useqq = 0;
|
|
712 |
local $Data::Dumper::Deepcopy = 0;
|
|
713 |
local $Data::Dumper::Quotekeys = 1;
|
|
714 |
local $Data::Dumper::Bless = 'bless';
|
|
715 |
local $Data::Dumper::Pair = ' => ';
|
|
716 |
local $Data::Dumper::Maxdep = 0;
|
|
717 |
local $Data::Dumper::Useperl = 0;
|
|
718 |
local $Data::Dumper::Sortkeys = 1;
|
|
719 |
return Data::Dumper->Dump( [$var], [$varname] );
|
|
720 |
}
|
|
721 |
|
705 | 722 |
sub init_cache {
|
706 | 723 |
my ($self, $args) = @_;
|
707 | 724 |
my $cachedir = $args->{file_cache_dir};
|
|
0 |
use strict;
|
|
1 |
use warnings;
|
|
2 |
use Test::More tests => 2;
|
|
3 |
use HTML::Template::Compiled;
|
|
4 |
use lib 't';
|
|
5 |
|
|
6 |
{
|
|
7 |
local $Data::Dumper::Terse = 1;
|
|
8 |
local $Data::Dumper::Pad = "FOO";
|
|
9 |
my %args = (
|
|
10 |
scalarref => \<<"EOM",
|
|
11 |
foo: <%= foo %>
|
|
12 |
|
|
13 |
<%loop list join=", " %><%= _ %><%/loop list %>
|
|
14 |
EOM
|
|
15 |
cache => 0,
|
|
16 |
pre_chomp => 0,
|
|
17 |
post_chomp => 1,
|
|
18 |
# debug => 1,
|
|
19 |
);
|
|
20 |
my $htc = HTML::Template::Compiled->new(
|
|
21 |
%args,
|
|
22 |
);
|
|
23 |
$htc->param(
|
|
24 |
foo => 23,
|
|
25 |
list => [2 .. 5],
|
|
26 |
);
|
|
27 |
my $out = $htc->output;
|
|
28 |
#warn __PACKAGE__.':'.__LINE__.": $out\n";
|
|
29 |
cmp_ok($out, '=~', "foo: 23", "[Data::Dumper] literal template strings");
|
|
30 |
cmp_ok($out, '=~', "2, 3, 4, 5", "[Data::Dumper] 'join' strings in loops");
|
|
31 |
}
|
|
32 |
|
|
33 |
|