line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Template::Process; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
79960
|
use 5; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
96
|
|
5
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
64
|
|
6
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
138
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.0006'; |
9
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
12
|
use base qw(Class::Accessor); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2269
|
|
12
|
|
|
|
|
|
|
Template::Process->mk_accessors(qw(tt)); |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
5284
|
use Carp qw(carp croak); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
176
|
|
15
|
2
|
|
|
2
|
|
3497
|
use Template; |
|
2
|
|
|
|
|
108745
|
|
|
2
|
|
|
|
|
76
|
|
16
|
2
|
|
|
2
|
|
1249
|
use Data::IO; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
53
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
1
|
|
|
1
|
1
|
24
|
return shift->SUPER::new({ tt => Template->new }); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=begin private |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=item B<_process> |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$tt->_process(TT => $tt, DATA => \@hashes, OUT => $handle); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=end private |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _process { |
33
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
34
|
1
|
|
|
|
|
4
|
my %args = @_; |
35
|
|
|
|
|
|
|
# warn YAML::Dump \%args; |
36
|
1
|
|
|
|
|
171
|
my $tt = $args{TT}; |
37
|
1
|
|
50
|
|
|
6
|
my $out = $args{OUT} || \*STDOUT; |
38
|
1
|
|
|
|
|
1
|
my @data; |
39
|
1
|
50
|
|
|
|
5
|
@data = ref $args{DATA} ? @{$args{DATA}} : ($args{DATA}); |
|
1
|
|
|
|
|
3
|
|
40
|
1
|
|
|
|
|
2
|
my %data; |
41
|
1
|
|
|
|
|
8
|
%data = (%data, %$_) for @data; |
42
|
1
|
|
|
|
|
6
|
return $self->tt->process($tt, \%data, $out); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _io { # this works only for $] >= 5.8 |
46
|
1
|
50
|
|
1
|
|
47
|
open my $io, '>', shift |
|
1
|
|
|
1
|
|
18
|
|
|
1
|
|
|
|
|
35
|
|
|
1
|
|
|
|
|
8
|
|
47
|
|
|
|
|
|
|
or croak "can't open in-core file: $!"; |
48
|
1
|
|
|
|
|
1809
|
return $io; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub process { |
52
|
1
|
|
|
1
|
1
|
53484
|
my $self = shift; |
53
|
1
|
|
|
|
|
7
|
my %args = @_; |
54
|
|
|
|
|
|
|
# warn YAML::Dump \%args; |
55
|
1
|
|
|
|
|
3
|
my $tt = $args{TT}; |
56
|
1
|
|
|
|
|
17
|
my $reader = Data::IO->new; |
57
|
|
|
|
|
|
|
|
58
|
1
|
|
|
|
|
12
|
my @data; |
59
|
1
|
|
|
|
|
4
|
my @args = defined $args{DATA} ? |
60
|
1
|
50
|
|
|
|
9
|
(ref $args{DATA} ? @{$args{DATA}} : ($args{DATA})) : |
|
|
50
|
|
|
|
|
|
61
|
|
|
|
|
|
|
(); |
62
|
1
|
|
|
|
|
4
|
for (@args) { |
63
|
1
|
50
|
0
|
|
|
4
|
if (ref $_) { # perl data already |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
64
|
1
|
|
|
|
|
4
|
push @data, $_; |
65
|
|
|
|
|
|
|
} elsif (-f && /\.ya?ml$/) { |
66
|
0
|
|
|
|
|
0
|
push @data, $reader->_read_yaml($_); |
67
|
|
|
|
|
|
|
} elsif (-f && /\.PL$/i) { |
68
|
0
|
|
|
|
|
0
|
push @data, $reader->_read_perl($_); |
69
|
|
|
|
|
|
|
} else { |
70
|
0
|
|
|
|
|
0
|
carp "'$_' ignored: unkown format\n"; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
3
|
my $out = $args{OUT}; |
75
|
1
|
50
|
|
|
|
12
|
$out = _io($out) if (ref $out eq 'SCALAR'); |
76
|
1
|
50
|
|
|
|
9
|
$out = \*STDOUT unless $out; |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
6
|
return $self->_process(TT => $tt, DATA => \@data, OUT => $out); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
0
|
1
|
0
|
sub error { return shift->tt->error } |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |