X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Debbugs%2FText.pm;h=353392013c90e621780d1febc76290e40954d075;hb=426fe0ee1b5fc70e19769f872922e99d72ed5d89;hp=c49981411eb8a7ed1f502896a7d7aaa6dea0e344;hpb=343464a69a83b5b2f1e956386482baaaccbc835c;p=debbugs.git diff --git a/Debbugs/Text.pm b/Debbugs/Text.pm index c499814..3533920 100644 --- a/Debbugs/Text.pm +++ b/Debbugs/Text.pm @@ -119,7 +119,7 @@ sub fill_in_template{ output => {type => HANDLE, optional => 1, }, - safe => {type => OBJECT, + safe => {type => OBJECT|UNDEF, optional => 1, }, hole_var => {type => HASHREF, @@ -141,6 +141,7 @@ sub fill_in_template{ ref(\$param{template}) eq 'GLOB') { $tt_type = 'FILE_HANDLE'; $tt_source = $param{template}; + binmode($tt_source,":encoding(UTF-8)"); } elsif (ref($param{template}) eq 'SCALAR') { $tt_type = 'STRING'; @@ -154,55 +155,62 @@ sub fill_in_template{ die "Unable to find template $param{template} with language $param{language}"; } - if (defined $param{safe}) { - $safe = $param{safe}; - } - else { - print STDERR "Created new safe\n" if $DEBUG; - $safe = Safe->new() or die "Unable to create safe compartment"; - $safe->permit_only(':base_core',':base_loop',':base_mem', - qw(padsv padav padhv padany), - qw(rv2gv refgen srefgen ref), - qw(caller require entereval), - qw(gmtime sprintf prtf), - ); - $safe->share('*STDERR'); - $safe->share('%config'); - $hole->wrap(\&Debbugs::Text::include,$safe,'&include'); - my $root = $safe->root(); - # load variables into the safe - for my $key (keys %{$param{variables}||{}}) { - print STDERR "Loading $key\n" if $DEBUG; - if (ref($param{variables}{$key})) { - no strict 'refs'; - print STDERR $safe->root().'::'.$key,qq(\n) if $DEBUG; - *{"${root}::$key"} = $param{variables}{$key}; - } - else { - no strict 'refs'; - ${"${root}::$key"} = $param{variables}{$key}; - } - } - for my $key (keys %{exists $param{hole_var}?$param{hole_var}:{}}) { - print STDERR "Wraping $key as $param{hole_var}{$key}\n" if $DEBUG; - $hole->wrap($param{hole_var}{$key},$safe,$key); - } - } +# if (defined $param{safe}) { +# $safe = $param{safe}; +# } +# else { +# print STDERR "Created new safe\n" if $DEBUG; +# $safe = Safe->new() or die "Unable to create safe compartment"; +# $safe->permit_only(':base_core',':base_loop',':base_mem', +# qw(padsv padav padhv padany), +# qw(rv2gv refgen srefgen ref), +# qw(caller require entereval), +# qw(gmtime time sprintf prtf), +# qw(sort), +# ); +# $safe->share('*STDERR'); +# $safe->share('%config'); +# $hole->wrap(\&Debbugs::Text::include,$safe,'&include'); +# my $root = $safe->root(); +# # load variables into the safe +# for my $key (keys %{$param{variables}||{}}) { +# print STDERR "Loading $key\n" if $DEBUG; +# if (ref($param{variables}{$key})) { +# no strict 'refs'; +# print STDERR $safe->root().'::'.$key,qq(\n) if $DEBUG; +# *{"${root}::$key"} = $param{variables}{$key}; +# } +# else { +# no strict 'refs'; +# ${"${root}::$key"} = $param{variables}{$key}; +# } +# } +# for my $key (keys %{exists $param{hole_var}?$param{hole_var}:{}}) { +# print STDERR "Wraping $key as $param{hole_var}{$key}\n" if $DEBUG; +# $hole->wrap($param{hole_var}{$key},$safe,$key); +# } +# } $language = $param{language}; my $tt; if ($tt_type eq 'FILE' and defined $tt_templates{$tt_source} and + ($tt_templates{$tt_source}{mtime} + 60) < time and (stat $tt_source)[9] <= $tt_templates{$tt_source}{mtime} ) { $tt = $tt_templates{$tt_source}{template}; } else { + my $passed_source = $tt_source; + my $passed_type = $tt_type; if ($tt_type eq 'FILE') { $tt_templates{$tt_source}{mtime} = (stat $tt_source)[9]; + $passed_source = IO::File->new($tt_source,'r'); + binmode($passed_source,":encoding(UTF-8)"); + $passed_type = 'FILEHANDLE'; } - $tt = Text::Template->new(TYPE => $tt_type, - SOURCE => $tt_source, + $tt = Text::Template->new(TYPE => $passed_type, + SOURCE => $passed_source, UNTAINT => 1, ); if ($tt_type eq 'FILE') { @@ -212,7 +220,14 @@ sub fill_in_template{ if (not defined $tt) { die "Unable to create Text::Template for $tt_type:$tt_source"; } - my $ret = $tt->fill_in(SAFE => $safe, + my $ret = $tt->fill_in(#SAFE => $safe, + PACKAGE => 'DTT', + HASH => {%{$param{variables}//{}}, + (map {my $t = $_; $t =~ s/^\&//; ($t => $param{hole_var}{$_})} + keys %{$param{hole_var}//{}}), + include => \&Debbugs::Text::include, + config => \%config, + }, defined $param{output}?(OUTPUT=>$param{output}):(), ); if (not defined $ret) { @@ -222,10 +237,10 @@ sub fill_in_template{ if ($DEBUG) { no strict 'refs'; no warnings 'uninitialized'; - my $temp = $param{nosafe}?'main':$safe->{Root}; +# my $temp = $param{nosafe}?'main':$safe->{Root}; print STDERR "Variables for $param{template}\n"; - print STDERR "Safe $temp\n"; - print STDERR map {"$_: ".*{$_}."\n"} keys %{"${temp}::"}; +# print STDERR "Safe $temp\n"; +# print STDERR map {"$_: ".*{$_}."\n"} keys %{"${temp}::"}; } return $ret;