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