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