line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
43
|
|
2
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
89
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Template::Transformer; |
5
|
|
|
|
|
|
|
$Template::Transformer::VERSION = '1.16'; |
6
|
|
|
|
|
|
|
# ABSTRACT: Transformer used by Template::Resolver |
7
|
|
|
|
|
|
|
# PODNAME: Template::Transformer |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
80
|
|
10
|
2
|
|
|
2
|
|
960
|
use Data::Dumper; |
|
2
|
|
|
|
|
12037
|
|
|
2
|
|
|
|
|
112
|
|
11
|
2
|
|
|
2
|
|
832
|
use Hash::Util qw(lock_hashref); |
|
2
|
|
|
|
|
4345
|
|
|
2
|
|
|
|
|
10
|
|
12
|
2
|
|
|
2
|
|
134
|
use Log::Any; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
8
|
|
13
|
2
|
|
|
2
|
|
849
|
use Safe; |
|
2
|
|
|
|
|
57742
|
|
|
2
|
|
|
|
|
1331
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $logger = Log::Any->get_logger(); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
13
|
|
|
13
|
0
|
40
|
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
|
27
|
|
|
27
|
|
46
|
my ( $self, $value ) = @_; |
28
|
27
|
|
|
|
|
71
|
my ( $key, $default ) = split( /:/, $value, 2 ); |
29
|
27
|
|
|
|
|
59
|
my $return_value = $self->_property($key); |
30
|
27
|
50
|
|
|
|
68
|
$return_value = $default unless ( defined($return_value) ); |
31
|
27
|
50
|
|
|
|
39
|
croak("undefined value without default, '$value'") |
32
|
|
|
|
|
|
|
unless ( defined($return_value) ); |
33
|
27
|
|
|
|
|
62
|
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
|
13
|
|
|
13
|
|
29
|
my ( $self, $os, $properties, %options ) = @_; |
43
|
13
|
|
|
|
|
37
|
$logger->debug( 'initializing transformer for ', $os ); |
44
|
|
|
|
|
|
|
|
45
|
13
|
|
|
|
|
704
|
$self->{os} = $os; |
46
|
13
|
|
|
|
|
24
|
$self->{properties} = $properties; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$self->{wrapped_transforms} = { |
49
|
13
|
|
|
|
|
38
|
'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
|
13
|
100
|
|
|
|
37
|
if ( $options{additional_transforms} ) { |
57
|
1
|
|
|
|
|
2
|
foreach my $transform ( keys( %{ $options{additional_transforms} } ) ) { |
|
1
|
|
|
|
|
4
|
|
58
|
|
|
|
|
|
|
$self->{wrapped_transforms}{$transform} = |
59
|
1
|
|
|
|
|
2
|
$self->_wrap_transform( $options{additional_transforms}{$transform} ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
13
|
|
|
|
|
48
|
lock_hashref( $self->{wrapped_transforms} ); |
63
|
|
|
|
|
|
|
|
64
|
13
|
|
|
|
|
284
|
return $self; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _safe_compartment { |
68
|
6
|
|
|
6
|
|
9
|
my ($self) = @_; |
69
|
6
|
100
|
|
|
|
13
|
if ( !$self->{safe_compartment} ) { |
70
|
1
|
|
|
|
|
6
|
$self->{safe_compartment} = Safe->new(); |
71
|
1
|
|
|
|
|
927
|
*{ $self->{safe_compartment}->varglob('property') } = |
|
1
|
|
|
|
|
4
|
|
72
|
|
|
|
|
|
|
$self->_wrap_transform( \&_property ); |
73
|
1
|
|
|
|
|
16
|
foreach my $transform ( keys( %{ $self->{wrapped_transforms} } ) ) { |
|
1
|
|
|
|
|
10
|
|
74
|
6
|
|
|
|
|
10
|
*{ $self->{safe_compartment}->varglob($transform) } = |
75
|
6
|
|
|
|
|
45
|
$self->{wrapped_transforms}{$transform}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
6
|
|
|
|
|
39
|
return $self->{safe_compartment}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _property { |
83
|
35
|
|
|
35
|
|
62
|
my ( $self, $key ) = @_; |
84
|
35
|
|
|
|
|
123
|
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
|
6
|
|
|
6
|
|
12
|
my ( $self, $value ) = @_; |
100
|
6
|
|
|
|
|
12
|
return $self->_safe_compartment()->reval($value); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub transform { |
104
|
34
|
|
|
34
|
0
|
54
|
my ( $self, $value, $transform_name ) = @_; |
105
|
34
|
|
100
|
|
|
106
|
$transform_name ||= 'default'; |
106
|
34
|
|
|
|
|
124
|
$logger->debug( 'applying [', $transform_name, '] to [', $value, ']' ); |
107
|
|
|
|
|
|
|
|
108
|
34
|
|
|
|
|
2055
|
my $transform = $self->{wrapped_transforms}{$transform_name}; |
109
|
34
|
50
|
|
|
|
72
|
croak("unknown transform '$transform'") unless ($transform); |
110
|
34
|
|
|
|
|
54
|
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
|
80
|
|
|
80
|
|
110
|
my ( $self, $transform ) = @_; |
126
|
|
|
|
|
|
|
return sub { |
127
|
38
|
|
|
38
|
|
632
|
&$transform( $self, @_ ); |
128
|
|
|
|
|
|
|
} |
129
|
80
|
|
|
|
|
298
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |