line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Templ; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
14438
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
453
|
use Scope::Upper qw(localize UP); |
|
1
|
|
|
|
|
723
|
|
|
1
|
|
|
|
|
56
|
|
7
|
1
|
|
|
1
|
|
4
|
use File::Find; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
68
|
|
8
|
1
|
|
|
1
|
|
423
|
use File::Spec::Functions qw(catdir abs2rel curdir splitdir); |
|
1
|
|
|
|
|
657
|
|
|
1
|
|
|
|
|
55
|
|
9
|
1
|
|
|
1
|
|
4
|
use Carp qw(croak); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
230
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = "0.01_01"; |
12
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $spec_class; |
15
|
|
|
|
|
|
|
BEGIN { |
16
|
1
|
|
|
1
|
|
2
|
$Templ::spec_class = 'Templ::Spec::Basic'; |
17
|
|
|
|
|
|
|
# Somewhat inspired by Module::Find... |
18
|
|
|
|
|
|
|
# Perform a "require MODULE;" for all Templ::* modules |
19
|
1
|
|
|
|
|
2
|
foreach my $dir ( grep { -d } map { catdir($_,'Templ') } @INC ) { |
|
11
|
|
|
|
|
89
|
|
|
11
|
|
|
|
|
20
|
|
20
|
|
|
|
|
|
|
my $wanted = sub { |
21
|
7
|
50
|
|
|
|
328
|
return unless -r; |
22
|
7
|
100
|
|
|
|
17
|
return if abs2rel($_,$dir) !~ m/^(.*)\.pm$/; |
23
|
5
|
|
|
|
|
314
|
my $module = join( '::', 'Templ', splitdir($1) ); |
24
|
5
|
50
|
|
|
|
36
|
return unless $module =~ m/^(\w+::)*\w+$/; |
25
|
5
|
50
|
|
|
|
13
|
return if $Templ::loaded{$module}++; |
26
|
5
|
|
|
|
|
204
|
eval "require $module;"; |
27
|
5
|
100
|
|
|
|
399
|
$@ && croak $@; |
28
|
1
|
|
|
|
|
4
|
}; |
29
|
|
|
|
|
|
|
# Find the perl modules under thes dirs and "require" them |
30
|
1
|
|
|
|
|
118
|
find( { wanted => $wanted, no_chdir => 1, follow => 1 }, $dir ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub templ ($;$) { $spec_class->templ( @_ ) } |
35
|
|
|
|
|
|
|
sub templ_method ($$;$) { $spec_class->templ_method( @_ ) } |
36
|
|
|
|
|
|
|
sub templ_sub ($$;$) { $spec_class->templ_sub( @_ ) } |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub templ_spec (;$$) { |
39
|
|
|
|
|
|
|
return $spec_class unless scalar @_; |
40
|
|
|
|
|
|
|
my $new_spec_class = shift; |
41
|
|
|
|
|
|
|
my $context = shift || UP; |
42
|
|
|
|
|
|
|
if ( not Templ::Spec::_subclass_loaded($new_spec_class) ) { |
43
|
|
|
|
|
|
|
if ( $Templ::loaded{'Templ::Spec::'.$new_spec_class} ) { |
44
|
|
|
|
|
|
|
$new_spec_class = 'Templ::Spec::'.$new_spec_class; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
Templ::Spec::_load_subclass($new_spec_class); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
localize '$Templ::spec_class', $new_spec_class, $context; |
49
|
|
|
|
|
|
|
return $new_spec_class; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub import { |
53
|
|
|
|
|
|
|
my $class = shift; |
54
|
|
|
|
|
|
|
my %valid_exports = map { $_ => 1 } qw(templ templ_method templ_sub templ_spec); |
55
|
|
|
|
|
|
|
my @export = (); |
56
|
|
|
|
|
|
|
while (scalar @_) { |
57
|
|
|
|
|
|
|
my $item = shift @_; |
58
|
|
|
|
|
|
|
if ($item eq '-spec') { |
59
|
|
|
|
|
|
|
templ_spec( shift(@_), UP ); |
60
|
|
|
|
|
|
|
next; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
if (not exists $valid_exports{$item}) { |
63
|
|
|
|
|
|
|
croak "Unknown function: $item"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
push @export, $item; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
unless (scalar @export) { |
68
|
|
|
|
|
|
|
@export = keys %valid_exports; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
foreach ( qw(templ templ_method templ_sub templ_spec) ) { |
71
|
|
|
|
|
|
|
no strict 'refs'; |
72
|
|
|
|
|
|
|
*{caller().'::'.$_} = \*{$_}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |