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