line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Sandbox::Library; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
2949
|
use strict; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
220
|
|
4
|
6
|
|
|
6
|
|
31
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
147
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
35
|
use Carp; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
429
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
37
|
use Template::Sandbox; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
390
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my %function_library = (); |
11
|
|
|
|
|
|
|
my %function_tags = (); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
BEGIN |
14
|
|
|
|
|
|
|
{ |
15
|
6
|
|
|
6
|
|
4219
|
$Template::Sandbox::Library::VERSION = '1.04'; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import |
19
|
|
|
|
|
|
|
{ |
20
|
13
|
|
|
13
|
|
187
|
my $pkg = shift; |
21
|
|
|
|
|
|
|
|
22
|
13
|
100
|
|
|
|
1960
|
export_template_functions( $pkg, 'Template::Sandbox', @_ ) if @_; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub export_template_functions |
26
|
|
|
|
|
|
|
{ |
27
|
26
|
|
|
26
|
1
|
345
|
my ( $this, $template, @imports ) = @_; |
28
|
26
|
|
|
|
|
37
|
my ( $pkg, $library, $tags, %export, @functions, $existing ); |
29
|
|
|
|
|
|
|
|
30
|
26
|
|
33
|
|
|
107
|
$pkg = ref( $this ) || $this; |
31
|
|
|
|
|
|
|
|
32
|
26
|
100
|
|
|
|
114
|
croak "\"$pkg\" does not appear to be a template function library." |
33
|
|
|
|
|
|
|
unless $function_library{ $pkg }; |
34
|
|
|
|
|
|
|
|
35
|
25
|
|
|
|
|
44
|
$library = $function_library{ $pkg }; |
36
|
25
|
|
|
|
|
48
|
$tags = $function_tags{ $pkg }; |
37
|
|
|
|
|
|
|
|
38
|
25
|
|
|
|
|
46
|
%export = (); |
39
|
25
|
|
|
|
|
49
|
foreach my $import ( @imports ) |
40
|
|
|
|
|
|
|
{ |
41
|
34
|
|
|
|
|
102
|
foreach my $word ( split( /\s+/, $import ) ) |
42
|
|
|
|
|
|
|
{ |
43
|
34
|
|
|
|
|
42
|
my ( $delete ); |
44
|
|
|
|
|
|
|
|
45
|
34
|
100
|
|
|
|
114
|
$delete = 1 if $word =~ s/^!//; |
46
|
|
|
|
|
|
|
|
47
|
34
|
100
|
|
|
|
129
|
if( $word =~ s/^:// ) |
48
|
|
|
|
|
|
|
{ |
49
|
17
|
|
|
|
|
27
|
my ( @names ); |
50
|
|
|
|
|
|
|
|
51
|
17
|
100
|
|
|
|
62
|
if( exists $tags->{ $word } ) |
|
|
100
|
|
|
|
|
|
52
|
|
|
|
|
|
|
{ |
53
|
7
|
|
|
|
|
10
|
@names = @{$tags->{ $word }}; |
|
7
|
|
|
|
|
24
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
elsif( $word eq 'all' ) |
56
|
|
|
|
|
|
|
{ |
57
|
9
|
|
|
|
|
15
|
@names = keys( %{$library} ); |
|
9
|
|
|
|
|
37
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else |
60
|
|
|
|
|
|
|
{ |
61
|
1
|
|
|
|
|
21
|
croak "\"$word\" is not a template library tag in $pkg"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
16
|
100
|
|
|
|
43
|
if( $delete ) |
65
|
|
|
|
|
|
|
{ |
66
|
3
|
|
|
|
|
23
|
delete $export{ $_ } foreach ( @names ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else |
69
|
|
|
|
|
|
|
{ |
70
|
13
|
|
|
|
|
120
|
$export{ $_ } = 1 foreach ( @names ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else |
74
|
|
|
|
|
|
|
{ |
75
|
17
|
100
|
|
|
|
36
|
if( $delete ) |
76
|
|
|
|
|
|
|
{ |
77
|
3
|
|
|
|
|
14
|
delete $export{ $word }; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
else |
80
|
|
|
|
|
|
|
{ |
81
|
14
|
|
|
|
|
317
|
$export{ $word } = 1; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
24
|
|
|
|
|
97
|
$existing = $template->_find_local_functions(); |
88
|
|
|
|
|
|
|
|
89
|
24
|
|
|
|
|
46
|
@functions = (); |
90
|
24
|
|
|
|
|
111
|
foreach my $name ( keys( %export ) ) |
91
|
|
|
|
|
|
|
{ |
92
|
55
|
100
|
|
|
|
304
|
croak "\"$name\" is not a template library function in $pkg" |
93
|
|
|
|
|
|
|
unless $library->{ $name }; |
94
|
|
|
|
|
|
|
|
95
|
54
|
100
|
|
|
|
199
|
push @functions, $name => $library->{ $name } |
96
|
|
|
|
|
|
|
unless exists $existing->{ $name }; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
23
|
100
|
|
|
|
204
|
$template->register_template_function( @functions ) if @functions; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub set_library_functions |
103
|
|
|
|
|
|
|
{ |
104
|
8
|
|
|
8
|
1
|
75
|
my ( $this, %functions ) = @_; |
105
|
8
|
|
|
|
|
15
|
my ( $pkg ); |
106
|
|
|
|
|
|
|
|
107
|
8
|
|
33
|
|
|
57
|
$pkg = ref( $this ) || $this; |
108
|
|
|
|
|
|
|
|
109
|
8
|
|
|
|
|
22
|
$function_library{ $pkg } = \%functions; |
110
|
8
|
|
50
|
|
|
75
|
$function_tags{ $pkg } ||= {}; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub set_library_tags |
114
|
|
|
|
|
|
|
{ |
115
|
4
|
|
|
4
|
1
|
17
|
my ( $this, %tags ) = @_; |
116
|
4
|
|
|
|
|
10
|
my ( $pkg ); |
117
|
|
|
|
|
|
|
|
118
|
4
|
|
33
|
|
|
28
|
$pkg = ref( $this ) || $this; |
119
|
|
|
|
|
|
|
|
120
|
4
|
|
|
|
|
16
|
$function_tags{ $pkg } = \%tags; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |