line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Xslate::Bridge; |
2
|
2
|
|
|
2
|
|
3171
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
49
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
53
|
|
4
|
2
|
|
|
2
|
|
9
|
use Carp (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
35
|
|
5
|
2
|
|
|
2
|
|
9
|
use Text::Xslate::Util qw(p); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1319
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my %storage; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub bridge { |
10
|
3
|
|
|
3
|
1
|
206
|
my $class = shift; |
11
|
3
|
|
|
|
|
23
|
while(my($type, $table) = splice @_, 0, 2) { |
12
|
9
|
|
|
|
|
37
|
$storage{$class}{$type} = $table; |
13
|
|
|
|
|
|
|
} |
14
|
3
|
|
|
|
|
9
|
return; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub export_into_xslate { |
18
|
6
|
|
|
6
|
0
|
15
|
my($class, $funcs_ref, @args) = @_; |
19
|
6
|
|
|
|
|
10
|
push @{$funcs_ref}, $class->methods(@args); |
|
6
|
|
|
|
|
28
|
|
20
|
6
|
|
|
|
|
84
|
return; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub methods { |
24
|
6
|
|
|
6
|
0
|
20
|
my($class, %args) = @_; |
25
|
|
|
|
|
|
|
|
26
|
6
|
50
|
|
|
|
22
|
if(!exists $storage{$class}) { |
27
|
0
|
|
|
|
|
0
|
Carp::croak("$class has no methods (possibly not a bridge class)"); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
6
|
100
|
|
|
|
27
|
if(exists $args{-exclude}) { |
31
|
1
|
|
|
|
|
4
|
my $exclude = $args{-exclude}; |
32
|
1
|
|
|
|
|
4
|
my $methods = $class->_functions; |
33
|
1
|
|
|
|
|
3
|
my @export; |
34
|
|
|
|
|
|
|
|
35
|
1
|
50
|
|
|
|
5
|
if(ref($exclude) eq 'ARRAY') { |
36
|
1
|
|
|
|
|
2
|
$exclude = { map { $_ => 1 } @{$exclude} }; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
3
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
1
|
50
|
|
|
|
6
|
if(ref($exclude) eq 'HASH') { |
|
|
0
|
|
|
|
|
|
40
|
1
|
|
|
|
|
2
|
@export = grep { !$exclude->{$_} } keys %{$methods}; |
|
5
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
3
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
elsif(ref($exclude) eq 'Regexp'){ |
43
|
0
|
|
|
|
|
0
|
@export = grep { $_ !~ $exclude } keys %{$methods}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
else { |
46
|
0
|
|
|
|
|
0
|
@export = grep { $_ ne $exclude } keys %{$methods}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
47
|
|
|
|
|
|
|
} |
48
|
1
|
|
|
|
|
4
|
return map { $_ => $methods->{$_} } @export; |
|
4
|
|
|
|
|
13
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else { |
51
|
5
|
|
|
|
|
7
|
return %{ $class->_functions }; |
|
5
|
|
|
|
|
21
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _functions { |
56
|
6
|
|
|
6
|
|
14
|
my($class) = @_; |
57
|
|
|
|
|
|
|
|
58
|
6
|
|
50
|
|
|
21
|
my $st = $storage{$class} ||= {}; |
59
|
6
|
|
100
|
|
|
32
|
my $funcs = $st->{_funcs} ||= {}; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# for methods |
62
|
6
|
|
|
|
|
15
|
foreach my $type (qw(scalar hash array)) { |
63
|
18
|
|
100
|
|
|
56
|
my $table = $st->{$type} || next; |
64
|
|
|
|
|
|
|
|
65
|
16
|
|
|
|
|
17
|
foreach my $name(keys %{$table}) { |
|
16
|
|
|
|
|
38
|
|
66
|
26
|
|
|
|
|
142
|
$funcs->{$type . '::' . $name} = $table->{$name}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# for functions |
71
|
6
|
|
|
|
|
14
|
my $table = $st->{function}; |
72
|
6
|
|
|
|
|
11
|
foreach my $name(keys %{$table}) { |
|
6
|
|
|
|
|
15
|
|
73
|
11
|
|
|
|
|
22
|
$funcs->{$name} = $table->{$name}; |
74
|
|
|
|
|
|
|
} |
75
|
6
|
|
|
|
|
41
|
return $funcs; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub dump { |
79
|
0
|
|
|
0
|
0
|
|
p(\%storage); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
__END__ |