line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Semantic; |
2
|
12
|
|
|
12
|
|
1224111
|
use strict; |
|
12
|
|
|
|
|
205
|
|
|
12
|
|
|
|
|
317
|
|
3
|
12
|
|
|
12
|
|
52
|
use warnings; |
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
243
|
|
4
|
12
|
|
|
12
|
|
287
|
use 5.008000; |
|
12
|
|
|
|
|
36
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
6
|
12
|
|
|
12
|
|
70
|
use Carp; |
|
12
|
|
|
|
|
20
|
|
|
12
|
|
|
|
|
757
|
|
7
|
12
|
|
|
12
|
|
90
|
use Scalar::Util qw/blessed/; |
|
12
|
|
|
|
|
204
|
|
|
12
|
|
|
|
|
662
|
|
8
|
12
|
|
|
12
|
|
7883
|
use XML::LibXML (); |
|
12
|
|
|
|
|
598024
|
|
|
12
|
|
|
|
|
349
|
|
9
|
12
|
|
|
12
|
|
4908
|
use Template::Semantic::Document; |
|
12
|
|
|
|
|
30
|
|
|
12
|
|
|
|
|
327
|
|
10
|
12
|
|
|
12
|
|
4408
|
use Template::Semantic::Filter; |
|
12
|
|
|
|
|
27
|
|
|
12
|
|
|
|
|
5011
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
25
|
|
|
25
|
1
|
63687
|
my ($class, %opt) = @_; |
14
|
25
|
|
|
|
|
65
|
my $self = bless { }, $class; |
15
|
|
|
|
|
|
|
|
16
|
25
|
|
|
|
|
110
|
$self->{parser} = delete $opt{parser}; |
17
|
25
|
|
66
|
|
|
105
|
$self->{parser} ||= do { |
18
|
24
|
|
|
|
|
113
|
my $parser = XML::LibXML->new; |
19
|
24
|
|
|
|
|
403
|
$parser->no_network(1); # faster |
20
|
24
|
|
|
|
|
342
|
$parser->recover(2); # = recover_silently(1) = no warnings |
21
|
24
|
|
|
|
|
346
|
$parser->$_($opt{$_}) for keys %opt; |
22
|
24
|
|
|
|
|
111
|
$parser; |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
25
|
|
|
|
|
54
|
for (@Template::Semantic::Filter::EXPORT_OK) { |
26
|
150
|
|
|
|
|
176
|
$self->define_filter($_ => \&{'Template::Semantic::Filter::' . $_}); |
|
150
|
|
|
|
|
435
|
|
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
25
|
|
|
|
|
60
|
$self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub define_filter { |
33
|
150
|
|
|
150
|
1
|
217
|
my ($self, $name, $code) = @_; |
34
|
150
|
|
33
|
|
|
484
|
$self->{filter}{$name} ||= $code; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub call_filter { |
38
|
13
|
|
|
13
|
1
|
1041
|
my ($self, $name) = @_; |
39
|
13
|
|
50
|
|
|
31
|
$name ||= ""; |
40
|
13
|
100
|
|
|
|
49
|
my $filter = ref($self) ? $self->{filter}{$name} |
41
|
|
|
|
|
|
|
: Template::Semantic::Filter->can($name); |
42
|
13
|
50
|
|
|
|
50
|
$filter or croak "Filter $name not defined."; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub process { |
46
|
168
|
100
|
|
168
|
1
|
289664
|
my $self = ref $_[0] ? shift : shift->new; |
47
|
168
|
|
|
|
|
332
|
my ($template, $vars) = @_; |
48
|
|
|
|
|
|
|
|
49
|
168
|
|
|
|
|
212
|
my $source; |
50
|
168
|
100
|
33
|
|
|
371
|
if (ref($template) eq 'SCALAR') { |
|
|
100
|
66
|
|
|
|
|
51
|
166
|
|
|
|
|
223
|
$source = $$template; |
52
|
|
|
|
|
|
|
} elsif (ref($template) eq 'GLOB' |
53
|
|
|
|
|
|
|
or blessed($template) && $template->isa('GLOB')) { |
54
|
1
|
|
|
|
|
2
|
$source = do { local $/; <$template> }; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
31
|
|
55
|
|
|
|
|
|
|
} else { |
56
|
1
|
50
|
|
|
|
40
|
open(my $fh, '<', $template) or croak $!; |
57
|
1
|
|
|
|
|
3
|
$source = do { local $/; <$fh> }; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
31
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
168
|
|
50
|
|
|
688
|
my $doc = Template::Semantic::Document->new( |
61
|
|
|
|
|
|
|
engine => $self, |
62
|
|
|
|
|
|
|
source => $source || "", |
63
|
|
|
|
|
|
|
); |
64
|
166
|
|
100
|
|
|
521
|
$doc->process($vars || {}); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
__END__ |