| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Typist::Template::Context; |
|
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
38
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use base qw( Class::ErrorHandler ); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
137
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use constant FALSE => -99999; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
69
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Exporter; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
68
|
|
|
8
|
|
|
|
|
|
|
*import = \&Exporter::import; |
|
9
|
1
|
|
|
1
|
|
7
|
use vars qw( @EXPORT ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
68
|
|
|
10
|
|
|
|
|
|
|
@EXPORT = qw( FALSE pass_tokens pass_tokens_else ); |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use vars qw( %Handlers %Filters ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1415
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
|
15
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
|
16
|
0
|
|
|
|
|
0
|
my $ctx = bless {}, $class; |
|
17
|
0
|
|
|
|
|
0
|
$ctx->init(@_); |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub init { |
|
21
|
0
|
|
|
0
|
0
|
0
|
my $ctx = shift; |
|
22
|
0
|
|
|
|
|
0
|
my $class = ref($ctx); |
|
23
|
0
|
|
|
|
|
0
|
$ctx->{__handlers} = {}; |
|
24
|
0
|
|
|
|
|
0
|
$ctx->{__filters} = {}; |
|
25
|
0
|
0
|
|
|
|
0
|
if ($@) { # initialize stash. |
|
26
|
0
|
0
|
|
|
|
0
|
if (ref $_[0] eq 'HASH') { |
|
27
|
0
|
|
|
|
|
0
|
map { $ctx->stash($_, $_[0]->{$_}) } keys %{$_[0]}; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
28
|
|
|
|
|
|
|
} else { |
|
29
|
0
|
0
|
|
|
|
0
|
my @stash_pairs = ref $_[0] eq 'ARRAY' ? @{$_[0]} : @_; # ??? |
|
|
0
|
|
|
|
|
0
|
|
|
30
|
0
|
0
|
|
|
|
0
|
return $class->error( |
|
31
|
|
|
|
|
|
|
"Uneven number of arguments to initialize stash.") |
|
32
|
|
|
|
|
|
|
if (int(@stash_pairs) & 1); |
|
33
|
0
|
|
|
|
|
0
|
while (@stash_pairs) { |
|
34
|
0
|
|
|
|
|
0
|
my $key = shift @stash_pairs; |
|
35
|
0
|
|
|
|
|
0
|
my $val = shift @stash_pairs; |
|
36
|
0
|
|
|
|
|
0
|
$ctx->stash($key, $val); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
} |
|
40
|
0
|
|
|
|
|
0
|
$ctx; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub var { |
|
44
|
0
|
0
|
|
0
|
1
|
0
|
$_[0]->{__var}->{$_[1]} = $_[2] if defined $_[2]; |
|
45
|
0
|
|
|
|
|
0
|
$_[0]->{__var}->{$_[1]}; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub stash { |
|
49
|
0
|
|
|
0
|
1
|
0
|
my $ctx = shift; |
|
50
|
0
|
|
|
|
|
0
|
my $key = shift; |
|
51
|
0
|
|
0
|
|
|
0
|
$ctx->{__stash}->{$key} ||= []; |
|
52
|
0
|
0
|
|
|
|
0
|
if (@_) { |
|
53
|
0
|
|
|
|
|
0
|
push @{$ctx->{__stash}->{$key}}, shift; |
|
|
0
|
|
|
|
|
0
|
|
|
54
|
|
|
|
|
|
|
} |
|
55
|
0
|
0
|
|
|
|
0
|
wantarray ? @{$ctx->{__stash}->{$key}} : $ctx->{__stash}->{$key}->[-1]; |
|
|
0
|
|
|
|
|
0
|
|
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
0
|
1
|
0
|
sub unstash { pop @{$_[0]->{__stash}->{$_[1]}} } |
|
|
0
|
|
|
|
|
0
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#--- internal plugin methods |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub register_handler { # $class/$object, $tag, $handler |
|
63
|
11
|
50
|
|
11
|
0
|
58
|
ref $_[0] |
|
64
|
|
|
|
|
|
|
? $_[0]->{__handlers}->{$_[1]} = |
|
65
|
|
|
|
|
|
|
$_[2] |
|
66
|
|
|
|
|
|
|
: $Handlers{$_[1]} = $_[2]; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub register_filter { |
|
70
|
18
|
50
|
|
18
|
0
|
63
|
ref $_[0] |
|
71
|
|
|
|
|
|
|
? $_[0]->{__filters}->{$_[1]} = |
|
72
|
|
|
|
|
|
|
$_[2] |
|
73
|
|
|
|
|
|
|
: $Filters{$_[1]} = $_[2]; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub handler_for { |
|
77
|
0
|
|
0
|
0
|
0
|
0
|
my $v = $_[0]->{__handlers}->{$_[1]} || $Handlers{$_[1]}; |
|
78
|
0
|
0
|
|
|
|
0
|
ref($v) eq 'ARRAY' ? @$v : $v; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub post_process_handler { |
|
82
|
|
|
|
|
|
|
sub { |
|
83
|
0
|
|
|
0
|
|
0
|
my ($ctx, $args, $str) = @_; |
|
84
|
0
|
|
|
|
|
0
|
foreach my $name (keys %$args) { |
|
85
|
0
|
|
0
|
|
|
0
|
my $code = $ctx->{__filters}->{$name} || $Filters{$name} || next; |
|
86
|
0
|
|
|
|
|
0
|
$str = $code->($str, $args->{$name}, $ctx); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
0
|
|
|
|
|
0
|
$str; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
0
|
|
|
0
|
0
|
0
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#--- plugin API |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub add_tag { |
|
95
|
2
|
|
|
2
|
1
|
2
|
my ($this, $name, $code) = @_; |
|
96
|
2
|
|
|
|
|
5
|
my $h = [$code, 0]; |
|
97
|
2
|
|
|
|
|
6
|
$this->register_handler($name, $h); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub add_container_tag { |
|
101
|
4
|
|
|
4
|
1
|
8
|
my ($this, $name, $code) = @_; |
|
102
|
4
|
|
|
|
|
9
|
my $h = [$code, 1]; |
|
103
|
4
|
|
|
|
|
9
|
$this->register_handler($name, $h); |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub add_conditional_tag { |
|
107
|
5
|
|
|
5
|
1
|
7
|
my ($this, $name, $condition) = @_; |
|
108
|
|
|
|
|
|
|
my $h = [ |
|
109
|
|
|
|
|
|
|
sub { |
|
110
|
0
|
0
|
|
0
|
|
0
|
if ($condition->(@_)) { |
|
111
|
0
|
|
|
|
|
0
|
return pass_tokens(@_); |
|
112
|
|
|
|
|
|
|
} else { |
|
113
|
0
|
|
|
|
|
0
|
return pass_tokens_else(@_); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
}, |
|
116
|
5
|
|
|
|
|
23
|
1 |
|
117
|
|
|
|
|
|
|
]; |
|
118
|
5
|
|
|
|
|
11
|
$this->register_handler($name, $h); |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub add_global_filter { |
|
122
|
18
|
|
|
18
|
1
|
23
|
my ($this, $name, $code) = @_; |
|
123
|
18
|
|
|
|
|
31
|
$this->register_filter($name, $code); |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
#-- exportable methods |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub pass_tokens { |
|
129
|
0
|
|
|
0
|
0
|
|
$_[0]->stash('builder')->build($_[0], $_[0]->stash('tokens'), $_[2]); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub pass_tokens_else { |
|
133
|
0
|
|
|
0
|
0
|
|
$_[0]->stash('builder')->build($_[0], $_[0]->stash('tokens_else'), $_[2]); |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
__END__ |