line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
56
|
|
2
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
252
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Template::Transformer; |
5
|
|
|
|
|
|
|
$Template::Transformer::VERSION = '1.14'; |
6
|
|
|
|
|
|
|
# ABSTRACT: Transformer used by Template::Resolver |
7
|
|
|
|
|
|
|
# PODNAME: Template::Transformer |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
16
|
use Carp; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
138
|
|
10
|
2
|
|
|
2
|
|
895
|
use Data::Dumper; |
|
2
|
|
|
|
|
15009
|
|
|
2
|
|
|
|
|
182
|
|
11
|
2
|
|
|
2
|
|
835
|
use Hash::Util qw(lock_hashref); |
|
2
|
|
|
|
|
6838
|
|
|
2
|
|
|
|
|
16
|
|
12
|
2
|
|
|
2
|
|
402
|
use Log::Any; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
18
|
|
13
|
2
|
|
|
2
|
|
1577
|
use Safe; |
|
2
|
|
|
|
|
83843
|
|
|
2
|
|
|
|
|
1825
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $logger = Log::Any->get_logger(); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
11
|
|
|
11
|
0
|
52
|
return bless( {}, shift )->_init(@_); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _boolean { |
22
|
0
|
|
|
0
|
|
0
|
my ( $self, $value ) = @_; |
23
|
0
|
0
|
|
|
|
0
|
return $self->_default($value) ? 'true' : 'false'; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _default { |
27
|
26
|
|
|
26
|
|
54
|
my ( $self, $value ) = @_; |
28
|
26
|
|
|
|
|
82
|
my ( $key, $default ) = split( /:/, $value, 2 ); |
29
|
26
|
|
|
|
|
171
|
my $return_value = $self->_property($key); |
30
|
26
|
50
|
|
|
|
54
|
$return_value = $default unless ( defined($return_value) ); |
31
|
26
|
50
|
|
|
|
44
|
croak("undefined value without default, '$value'") |
32
|
|
|
|
|
|
|
unless ( defined($return_value) ); |
33
|
26
|
|
|
|
|
61
|
return $return_value; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _env { |
37
|
0
|
|
|
0
|
|
0
|
my ( $self, $value ) = @_; |
38
|
0
|
|
|
|
|
0
|
return $ENV{$value}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _init { |
42
|
11
|
|
|
11
|
|
39
|
my ( $self, $os, $properties, %options ) = @_; |
43
|
11
|
|
|
|
|
34
|
$logger->debug( 'initializing transformer for ', $os ); |
44
|
|
|
|
|
|
|
|
45
|
11
|
|
|
|
|
438
|
$self->{os} = $os; |
46
|
11
|
|
|
|
|
25
|
$self->{properties} = $properties; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$self->{wrapped_transforms} = { |
49
|
11
|
|
|
|
|
49
|
'boolean' => $self->_wrap_transform( \&_boolean ), |
50
|
|
|
|
|
|
|
'default' => $self->_wrap_transform( \&_default ), |
51
|
|
|
|
|
|
|
'env' => $self->_wrap_transform( \&_env ), |
52
|
|
|
|
|
|
|
'os_path' => $self->_wrap_transform( \&_os_path ), |
53
|
|
|
|
|
|
|
'perl' => $self->_wrap_transform( \&_perl ), |
54
|
|
|
|
|
|
|
'xml_escape' => $self->_wrap_transform( \&_xml_escape ) |
55
|
|
|
|
|
|
|
}; |
56
|
11
|
50
|
|
|
|
42
|
if ( $options{additional_transforms} ) { |
57
|
0
|
|
|
|
|
0
|
foreach my $transform ( keys( %{ $options{additional_transforms} } ) ) { |
|
0
|
|
|
|
|
0
|
|
58
|
|
|
|
|
|
|
$self->{wrapped_transforms}{$transform} = |
59
|
0
|
|
|
|
|
0
|
$self->_wrap_transform( $options{additional_transforms}{$transform} ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
11
|
|
|
|
|
71
|
lock_hashref( $self->{wrapped_transforms} ); |
63
|
|
|
|
|
|
|
|
64
|
11
|
|
|
|
|
314
|
return $self; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _safe_compartment { |
68
|
1
|
|
|
1
|
|
3
|
my ($self) = @_; |
69
|
1
|
50
|
|
|
|
5
|
if ( !$self->{safe_compartment} ) { |
70
|
1
|
|
|
|
|
10
|
$self->{safe_compartment} = Safe->new(); |
71
|
1
|
|
|
|
|
927
|
*{ $self->{safe_compartment}->varglob('property') } = |
|
1
|
|
|
|
|
7
|
|
72
|
|
|
|
|
|
|
$self->_wrap_transform( \&_property ); |
73
|
1
|
|
|
|
|
18
|
foreach my $transform ( keys( %{ $self->{wrapped_transforms} } ) ) { |
|
1
|
|
|
|
|
4
|
|
74
|
6
|
|
|
|
|
12
|
*{ $self->{safe_compartment}->varglob($transform) } = |
75
|
6
|
|
|
|
|
48
|
$self->{wrapped_transforms}{$transform}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
14
|
return $self->{safe_compartment}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _property { |
83
|
26
|
|
|
26
|
|
40
|
my ( $self, $key ) = @_; |
84
|
26
|
|
|
|
|
64
|
return $self->{properties}{$key}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _os_path { |
88
|
0
|
|
|
0
|
|
0
|
my ( $self, $value ) = @_; |
89
|
0
|
|
|
|
|
0
|
$value = $self->_default($value); |
90
|
0
|
0
|
|
|
|
0
|
if ( $self->{os} eq 'cygwin' ) { |
91
|
0
|
|
|
|
|
0
|
$value =~ s/\\/\\\\/g; |
92
|
0
|
|
|
|
|
0
|
$value = `cygpath --absolute --mixed $value 2> /dev/null`; |
93
|
0
|
|
|
|
|
0
|
chomp($value); |
94
|
|
|
|
|
|
|
} |
95
|
0
|
|
|
|
|
0
|
return $value; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _perl { |
99
|
1
|
|
|
1
|
|
3
|
my ( $self, $value ) = @_; |
100
|
1
|
|
|
|
|
14
|
return $self->_safe_compartment()->reval($value); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub transform { |
104
|
27
|
|
|
27
|
0
|
61
|
my ( $self, $value, $transform_name ) = @_; |
105
|
27
|
|
100
|
|
|
107
|
$transform_name ||= 'default'; |
106
|
27
|
|
|
|
|
78
|
$logger->debug( 'applying [', $transform_name, '] to [', $value, ']' ); |
107
|
|
|
|
|
|
|
|
108
|
27
|
|
|
|
|
996
|
my $transform = $self->{wrapped_transforms}{$transform_name}; |
109
|
27
|
50
|
|
|
|
69
|
croak("unknown transform '$transform'") unless ($transform); |
110
|
27
|
|
|
|
|
58
|
return &$transform($value); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _xml_escape { |
114
|
0
|
|
|
0
|
|
0
|
my ( $self, $value ) = @_; |
115
|
0
|
|
|
|
|
0
|
$value = $self->_default($value); |
116
|
0
|
|
|
|
|
0
|
$value =~ s/&/&/sg; |
117
|
0
|
|
|
|
|
0
|
$value =~ s/</sg; |
118
|
0
|
|
|
|
|
0
|
$value =~ s/>/>/sg; |
119
|
0
|
|
|
|
|
0
|
$value =~ s/"/"/sg; |
120
|
0
|
|
|
|
|
0
|
$value =~ s/'/'/sg; |
121
|
0
|
|
|
|
|
0
|
return $value; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _wrap_transform { |
125
|
67
|
|
|
67
|
|
120
|
my ( $self, $transform ) = @_; |
126
|
|
|
|
|
|
|
return sub { |
127
|
27
|
|
|
27
|
|
61
|
&$transform( $self, @_ ); |
128
|
|
|
|
|
|
|
} |
129
|
67
|
|
|
|
|
319
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |