| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Template::Filters::LazyLoader; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
39823
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
466
|
|
|
4
|
3
|
|
|
3
|
|
15
|
use base qw/Class::Accessor::Fast/; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
2844
|
|
|
5
|
3
|
|
|
3
|
|
11185
|
use File::Spec; |
|
|
3
|
|
|
|
|
12
|
|
|
|
3
|
|
|
|
|
87
|
|
|
6
|
3
|
|
|
3
|
|
15
|
use Carp; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
312
|
|
|
7
|
3
|
|
|
3
|
|
2667
|
use Module::Recursive::Require 0.04; |
|
|
3
|
|
|
|
|
10721
|
|
|
|
3
|
|
|
|
|
27
|
|
|
8
|
3
|
|
|
3
|
|
89
|
use UNIVERSAL::require; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
12
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
85
|
use vars qw/$VERSION/; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
757
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '0.05'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( |
|
14
|
|
|
|
|
|
|
qw/ |
|
15
|
|
|
|
|
|
|
static_filter_prefix filters base_pkg |
|
16
|
|
|
|
|
|
|
pkg pkgs dynamic_filter_prefix lib_path |
|
17
|
|
|
|
|
|
|
/ |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub load { |
|
21
|
4
|
|
|
4
|
1
|
3631
|
my $s = shift; |
|
22
|
|
|
|
|
|
|
|
|
23
|
4
|
50
|
66
|
|
|
12
|
croak 'You must set base_pkg or pkg or pkgs.' if( !$s->base_pkg() && !$s->pkg && !$s->pkgs ); |
|
|
|
|
66
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
3
|
|
|
|
|
30
|
my $recursive_args = {}; |
|
26
|
3
|
50
|
|
|
|
10
|
if ( $s->lib_path() ){ |
|
27
|
0
|
|
|
|
|
0
|
$recursive_args->{path} = $s->lib_path(); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
3
|
50
|
|
|
|
19
|
unless ( $s->static_filter_prefix() ) { |
|
31
|
3
|
|
|
|
|
21
|
$s->static_filter_prefix( 'fs_' ); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
3
|
50
|
|
|
|
19
|
unless ( $s->dynamic_filter_prefix() ) { |
|
35
|
3
|
|
|
|
|
21
|
$s->dynamic_filter_prefix( 'fd_' ); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
20
|
my $r = Module::Recursive::Require->new( $recursive_args ); |
|
39
|
3
|
|
|
|
|
89
|
my @packages = () ; |
|
40
|
|
|
|
|
|
|
|
|
41
|
3
|
100
|
|
|
|
8
|
if ( $s->base_pkg() ) { |
|
|
|
50
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
9
|
@packages = $r->require_of( $s->base_pkg() ); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
elsif( $s->pkgs() ) { |
|
45
|
0
|
|
|
|
|
0
|
for my $pkg ( @{ $s->pkgs() } ) { |
|
|
0
|
|
|
|
|
0
|
|
|
46
|
0
|
0
|
|
|
|
0
|
$pkg->require() or croak $@; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
0
|
|
|
|
|
0
|
@packages = @{ $s->pkgs() } ; |
|
|
0
|
|
|
|
|
0
|
|
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
else { |
|
51
|
2
|
100
|
|
|
|
29
|
$s->pkg()->require() or croak $@; |
|
52
|
1
|
|
|
|
|
84
|
$packages[0] = $s->pkg(); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
3
|
|
|
3
|
|
17
|
no strict; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
810
|
|
|
56
|
|
|
|
|
|
|
READ_PKG_LOOP: |
|
57
|
2
|
|
|
|
|
2243
|
for my $filter_pkg ( @packages ) { |
|
58
|
|
|
|
|
|
|
|
|
59
|
4
|
|
|
|
|
7
|
my $pkg_href = $filter_pkg . '::' ; |
|
60
|
4
|
|
|
|
|
13
|
READ_SUB_LOOP: |
|
61
|
4
|
|
|
|
|
6
|
foreach my $symbol ( keys %{ $pkg_href } ) { |
|
62
|
|
|
|
|
|
|
|
|
63
|
18
|
|
|
|
|
37
|
local *glob = $pkg_href->{$symbol} ; |
|
64
|
18
|
100
|
|
|
|
166
|
next READ_SUB_LOOP unless $symbol |
|
65
|
|
|
|
|
|
|
=~ /^$s->{static_filter_prefix}|^$s->{dynamic_filter_prefix}/; |
|
66
|
9
|
50
|
|
|
|
16
|
if ( defined &glob ) { |
|
67
|
9
|
100
|
|
|
|
96
|
if ( $symbol =~ /^$s->{static_filter_prefix}/ ) { |
|
68
|
5
|
|
|
|
|
29
|
$symbol =~ s/^$s->{static_filter_prefix}//; |
|
69
|
5
|
|
50
|
|
|
30
|
$s->{filters}{ $symbol } = \&glob || undef ; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
else { |
|
72
|
4
|
|
|
|
|
21
|
$symbol =~ s/^$s->{dynamic_filter_prefix}//; |
|
73
|
4
|
|
50
|
|
|
24
|
$s->{filters}{ $symbol } = [ \&glob , 1 ]|| undef ; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
2
|
|
|
|
|
44
|
return $s->{filters}; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 NAME |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Template::Filters::LazyLoader - Loading template filter modules by lazy way. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Are you lazy? If so you come to right place :-) . This module load all your |
|
90
|
|
|
|
|
|
|
nice and sexy custom template filter modules with very simple and lazy way. |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
What you need to do is set parent package and then, LazyLoader read all |
|
93
|
|
|
|
|
|
|
packages recursively under the parent package and read all filter modules |
|
94
|
|
|
|
|
|
|
automatically from those packages. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SYNOPSYS |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $lazy = Template::Filters::LazyLoader->new(); |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# You must use base_pkg or pkg , do not use both. |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Case using base_pkg |
|
103
|
|
|
|
|
|
|
# read all packages which using My::Custom::Filters as base module . |
|
104
|
|
|
|
|
|
|
# e.g. ( My::Custom::Filters::One , My::Custom::Filters::Two , # My::Custom::Filters::A::Three ... ) |
|
105
|
|
|
|
|
|
|
$lazy->base_pkg('My::Custom::Filters'); |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# case using pkg |
|
108
|
|
|
|
|
|
|
# read My::Custom::Filter package only. |
|
109
|
|
|
|
|
|
|
$lazy->pkg( 'My::Custom::Filter'); |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# case using pkgs |
|
112
|
|
|
|
|
|
|
$lazy->pkgs( [qw/My::Filter1 My::Filter2/] ); |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# below methods are optional. I never use it. |
|
115
|
|
|
|
|
|
|
#$lazy->static_filter_prefix( 'fs_' ); # default is fs_ |
|
116
|
|
|
|
|
|
|
#$laxy->dynamic_filter_prefix( fd_' ); # default is fd_ |
|
117
|
|
|
|
|
|
|
#$lazy->lib_path( '/path/to/your/lib') # default is $INC[0] |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my $tt = Template->new( { FILTERS => $lazy->load() ); |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# $lazy->filters(); |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Your one filter package. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
package Your::Filter::OK; |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub fs_foo { |
|
129
|
|
|
|
|
|
|
return 'foo'; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub fd_boo { |
|
133
|
|
|
|
|
|
|
sub { |
|
134
|
|
|
|
|
|
|
return 'boo'; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Your template |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
[% 'I never show up | foo %] |
|
141
|
|
|
|
|
|
|
[% FILTER boo( 1,32,4,3) %] |
|
142
|
|
|
|
|
|
|
orz |
|
143
|
|
|
|
|
|
|
[% END %] |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 SET BASE PACKAGE |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
This is the example where you put your filter package. |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Suppose you set base_pkg as 'CustomFilters' and you have below lib tree. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|-- lib |
|
154
|
|
|
|
|
|
|
| |-- CustomFilters |
|
155
|
|
|
|
|
|
|
| | |-- Osaka.pm |
|
156
|
|
|
|
|
|
|
| | |-- Seattle.pm |
|
157
|
|
|
|
|
|
|
| | `-- USA |
|
158
|
|
|
|
|
|
|
| | `-- Okurahoma.pm |
|
159
|
|
|
|
|
|
|
| |-- CustomFilters.pm |
|
160
|
|
|
|
|
|
|
| `-- NeverCalled.pm |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
LazyLoader only read under CustomFilters dir recursively means it does not read CustomFilters.pm and NeverCalled.pm |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SET PREFIX |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
You must read 'Configuration - Plugins and Filters' SECTION for Template Tool |
|
168
|
|
|
|
|
|
|
Document first. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
OK now you know there are 2 types of filter which are static and dynamic. To |
|
171
|
|
|
|
|
|
|
distinct between this , LazyLoader ask you to set prefix for your all filter |
|
172
|
|
|
|
|
|
|
methods. for static you should start your method with 'fs_' and for dynamic |
|
173
|
|
|
|
|
|
|
'fd_'. You can also change this prefix with static_filter_prefix , |
|
174
|
|
|
|
|
|
|
dynamic_filter_prefix methods if you want. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub fs_foo{ |
|
177
|
|
|
|
|
|
|
return 'foo'; |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub fd_bar{ |
|
181
|
|
|
|
|
|
|
return sub { |
|
182
|
|
|
|
|
|
|
return 'bar'; |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub never_loaded { |
|
187
|
|
|
|
|
|
|
return "This module never read by LazyLoader"; |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 NAMING RULE |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
There is very important rule to use LazyLoader. Method name must be unique |
|
193
|
|
|
|
|
|
|
even different package. |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub {prefix}must_unique_name { |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 METHOD |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 base_pkg |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
set your parent package!!! |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 pkg |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
set your package which contain filter modules. |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head2 pkgs |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
set your pakcages as array ref. |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head2 load |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Load your filter modules and return filters hash ref. |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head2 filters |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
return filters hash ref. You must use this after calling load() method. |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head2 static_filter_prefix |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
You can set static filter prefix if you want. default is 'fs_' |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head2 dynamic_filter_prefix |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
You can set dynamic filter prefix if you want. default is 'fd_' |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head2 lib_path |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
You can set lib path if you want. default if $INC[0] SEE |
|
232
|
|
|
|
|
|
|
C |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Template , Class::Accessor::Fast , Module::Recursive::Require |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 AUTHOR |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Tomohiro Teranishi |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
This program is distributed under the Artistic License |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=cut |