line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package YATT::Lite::Entities; |
2
|
20
|
|
|
20
|
|
140
|
use strict; |
|
20
|
|
|
|
|
49
|
|
|
20
|
|
|
|
|
649
|
|
3
|
20
|
|
|
20
|
|
104
|
use warnings qw(FATAL all NONFATAL misc); |
|
20
|
|
|
|
|
52
|
|
|
20
|
|
|
|
|
777
|
|
4
|
20
|
|
|
20
|
|
101
|
use Carp; |
|
20
|
|
|
|
|
50
|
|
|
20
|
|
|
|
|
1133
|
|
5
|
|
|
|
|
|
|
|
6
|
20
|
|
|
20
|
|
126
|
use mro 'c3'; |
|
20
|
|
|
|
|
47
|
|
|
20
|
|
|
|
|
152
|
|
7
|
|
|
|
|
|
|
# XXX: 残念ながら、要整理。 |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require YATT::Lite::MFields; |
10
|
|
|
|
|
|
|
|
11
|
20
|
|
|
20
|
|
787
|
use YATT::Lite::Util qw/globref terse_dump url_encode/; |
|
20
|
|
|
|
|
49
|
|
|
20
|
|
|
|
|
28639
|
|
12
|
|
|
|
|
|
|
|
13
|
21
|
|
|
21
|
0
|
78
|
sub default_export { qw(*YATT) } |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#======================================== |
16
|
|
|
|
|
|
|
# Facade を template に見せるための, グローバル変数. |
17
|
|
|
|
|
|
|
our $YATT; |
18
|
53
|
|
|
53
|
0
|
626
|
sub symbol_YATT { return *YATT } |
19
|
4
|
|
|
4
|
0
|
102
|
sub YATT { $YATT } |
20
|
0
|
|
|
0
|
0
|
0
|
sub DIR { $YATT } |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Factory/Dispatcher/Logger/... を template に見せる |
23
|
|
|
|
|
|
|
our $SYS; |
24
|
62
|
|
|
62
|
0
|
658
|
sub symbol_SYS { return *SYS } |
25
|
0
|
|
|
0
|
0
|
0
|
sub SYS { $SYS } |
26
|
0
|
|
|
0
|
0
|
0
|
sub SITE { $SYS } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Connection |
29
|
|
|
|
|
|
|
our $CON; |
30
|
62
|
|
|
62
|
0
|
536
|
sub symbol_CON { return *CON } |
31
|
11
|
|
|
11
|
0
|
50
|
sub CON { return $CON } |
32
|
|
|
|
|
|
|
#======================================== |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub import { |
35
|
79
|
|
|
79
|
|
378
|
my ($pack, @opts) = @_; |
36
|
79
|
100
|
|
|
|
349
|
@opts = $pack->default_export unless @opts; |
37
|
79
|
|
|
|
|
233
|
my $callpack = caller; |
38
|
79
|
|
|
|
|
190
|
my (%opts, @task); |
39
|
79
|
|
|
|
|
252
|
foreach my $exp (@opts) { |
40
|
237
|
100
|
|
|
|
3139
|
if (my $sub = $pack->can("define_$exp")) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
41
|
42
|
|
|
|
|
135
|
push @task, $sub; |
42
|
|
|
|
|
|
|
} elsif ($exp =~ /^-(\w+)$/) { |
43
|
33
|
50
|
|
|
|
336
|
$sub = $pack->can("declare_$1") |
44
|
|
|
|
|
|
|
or croak "Unknown declarator: $1"; |
45
|
33
|
|
|
|
|
141
|
$sub->($pack, \%opts, $callpack); |
46
|
|
|
|
|
|
|
} elsif ($exp =~ /^\*(\w+)$/) { |
47
|
162
|
50
|
|
|
|
1197
|
$sub = $pack->can("symbol_$1") |
48
|
|
|
|
|
|
|
or croak "Can't export symbol $1"; |
49
|
162
|
|
|
|
|
533
|
my $val = $sub->(); |
50
|
162
|
50
|
|
|
|
681
|
unless (defined $val) { |
51
|
0
|
|
|
|
|
0
|
croak "Undefined symbol in export spec: $exp"; |
52
|
|
|
|
|
|
|
} |
53
|
162
|
|
|
|
|
294
|
*{globref($callpack, $1)} = $val; |
|
162
|
|
|
|
|
481
|
|
54
|
|
|
|
|
|
|
} elsif ($sub = $pack->can($exp)) { |
55
|
0
|
|
|
|
|
0
|
*{globref($callpack, $exp)} = $sub; |
|
0
|
|
|
|
|
0
|
|
56
|
|
|
|
|
|
|
} else { |
57
|
0
|
|
|
|
|
0
|
croak "Unknown export spec: $exp"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
79
|
|
|
|
|
2977
|
foreach my $sub (@task) { |
61
|
42
|
|
|
|
|
180
|
$sub->($pack, \%opts, $callpack); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# use 時に関数を生成したい場合、 define_ZZZ を定義すること。 |
66
|
|
|
|
|
|
|
# サブクラスで新たな symbol を export したい場合、 symbol_ZZZ を定義すること |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
*declare_as_parent = *declare_as_base; *declare_as_parent = *declare_as_base; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub declare_as_base { |
71
|
33
|
|
|
33
|
0
|
100
|
my ($myPack, $opts, $callpack) = @_; |
72
|
|
|
|
|
|
|
# ckrequire($myPack); # Not needed because $myPack is just used! |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Fill $callpack's %FIELDS, by current ISA. |
75
|
33
|
|
|
|
|
189
|
YATT::Lite::MFields->add_isa_to($callpack, $myPack) |
76
|
|
|
|
|
|
|
->define_fields($callpack); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
######################################### |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub define_import { |
82
|
0
|
|
|
0
|
0
|
0
|
my ($myPack, $opts, $callpack) = @_; |
83
|
0
|
|
|
|
|
0
|
*{globref($callpack, 'import')} = \&import; |
|
0
|
|
|
|
|
0
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub define_MY { |
87
|
0
|
|
|
0
|
0
|
0
|
my ($myPack, $opts, $callpack) = @_; |
88
|
0
|
|
|
|
|
0
|
my $my = globref($callpack, 'MY'); |
89
|
0
|
0
|
|
|
|
0
|
unless (*{$my}{CODE}) { |
|
0
|
|
|
|
|
0
|
|
90
|
0
|
|
|
|
|
0
|
YATT::Lite::Util::define_const($my, $callpack); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
#======================================== |
95
|
|
|
|
|
|
|
# 組み込み Entity |
96
|
|
|
|
|
|
|
# Entity 呼び出し時の第一引数は, packageName (つまり文字列) になる。 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub entity_breakpoint { |
99
|
1
|
|
|
1
|
0
|
84
|
require YATT::Lite::Breakpoint; |
100
|
1
|
|
|
|
|
7
|
&YATT::Lite::Breakpoint::breakpoint(); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub entity_param { |
104
|
0
|
|
|
0
|
0
|
0
|
shift; |
105
|
0
|
|
|
|
|
0
|
$CON->param(@_); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub entity_concat { |
109
|
1
|
|
|
1
|
0
|
128
|
my $this = shift; |
110
|
1
|
|
|
|
|
7
|
join '', @_; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub entity_coalesce { |
114
|
3
|
|
|
3
|
0
|
207
|
my $this = shift; |
115
|
3
|
|
|
|
|
9
|
foreach my $str (@_) { |
116
|
5
|
100
|
|
|
|
22
|
return $str if defined $str; |
117
|
|
|
|
|
|
|
} |
118
|
0
|
|
|
|
|
0
|
''; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub entity_default { |
122
|
3
|
|
|
3
|
0
|
217
|
my $this = shift; |
123
|
3
|
|
|
|
|
8
|
foreach my $str (@_) { |
124
|
6
|
100
|
100
|
|
|
36
|
return $str if defined $str and $str ne ''; |
125
|
|
|
|
|
|
|
} |
126
|
0
|
|
|
|
|
0
|
''; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
*entity_lsize = *entity_llength; *entity_lsize = *entity_llength; |
130
|
|
|
|
|
|
|
sub entity_llength { |
131
|
0
|
|
|
0
|
0
|
0
|
my ($this, $list) = @_; |
132
|
0
|
0
|
0
|
|
|
0
|
return undef unless defined $list and ref $list eq 'ARRAY'; |
133
|
0
|
|
|
|
|
0
|
scalar @$list; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub entity_join { |
137
|
3
|
|
|
3
|
0
|
362
|
my ($this, $sep) = splice @_, 0, 2; |
138
|
3
|
50
|
|
|
|
9
|
join $sep, grep {defined $_ && $_ ne ''} @_; |
|
11
|
|
|
|
|
67
|
|
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub entity_format { |
142
|
1
|
|
|
1
|
0
|
112
|
my ($this, $format) = (shift, shift); |
143
|
1
|
|
|
|
|
22
|
sprintf $format, @_; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub entity_HTML { |
147
|
5
|
|
|
5
|
0
|
531
|
my $this = shift; |
148
|
5
|
|
|
|
|
16
|
\ join "", grep {defined $_} @_; |
|
10
|
|
|
|
|
45
|
|
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub entity_url_encode { |
152
|
1
|
|
|
1
|
0
|
93
|
my $this = shift; |
153
|
1
|
|
|
|
|
4
|
join "", map {url_encode($this, $_)} @_; |
|
1
|
|
|
|
|
7
|
|
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub entity_alternative { |
157
|
3
|
|
|
3
|
0
|
99
|
my ($this, $value, $list) = @_; |
158
|
3
|
|
|
|
|
5
|
my @alt = do { |
159
|
3
|
50
|
|
|
|
9
|
if (defined $value) { |
160
|
3
|
|
|
|
|
6
|
grep {$value ne $_} @$list; |
|
6
|
|
|
|
|
16
|
|
161
|
|
|
|
|
|
|
} else { |
162
|
0
|
|
|
|
|
0
|
grep {defined $_} @$list; |
|
0
|
|
|
|
|
0
|
|
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
}; |
165
|
3
|
|
|
|
|
12
|
$alt[0] |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# XXX: auto url_encode |
169
|
|
|
|
|
|
|
sub entity_append_params { |
170
|
3
|
|
|
3
|
0
|
227
|
my ($this, $url) = splice @_, 0, 2; |
171
|
3
|
50
|
|
|
|
11
|
return $url unless @_; |
172
|
3
|
|
|
|
|
101
|
require URI; |
173
|
3
|
|
|
|
|
2786
|
require Hash::MultiValue; |
174
|
3
|
|
|
|
|
2139
|
my $uri = URI->new($url); |
175
|
3
|
|
|
|
|
5988
|
my $hmv = Hash::MultiValue->new($uri->query_form); |
176
|
3
|
|
|
|
|
267
|
my %multi; |
177
|
3
|
|
|
|
|
7
|
foreach my $item (@_) { |
178
|
5
|
|
|
|
|
68
|
my ($key, @strs) = @$item; |
179
|
5
|
100
|
|
|
|
25
|
$hmv->remove($key) unless $multi{$key}++; |
180
|
5
|
|
|
|
|
112
|
$hmv->add($key, join("", @strs)); |
181
|
|
|
|
|
|
|
} |
182
|
3
|
|
|
|
|
89
|
$uri->query_form($hmv->flatten); |
183
|
3
|
|
|
|
|
334
|
$uri->as_string; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub entity_dump { |
187
|
2
|
|
|
2
|
0
|
220
|
shift; |
188
|
2
|
|
|
|
|
12
|
terse_dump(@_); |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub entity_can_render { |
192
|
0
|
|
|
0
|
0
|
|
my ($this, $widget) = @_; |
193
|
0
|
|
|
|
|
|
$this->can("render_$widget"); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
0
|
0
|
|
sub entity_uc { shift; uc($_[0]) } |
|
0
|
|
|
|
|
|
|
197
|
0
|
|
|
0
|
0
|
|
sub entity_ucfirst { shift; ucfirst($_[0]) } |
|
0
|
|
|
|
|
|
|
198
|
0
|
|
|
0
|
0
|
|
sub entity_lc { shift; lc($_[0]) } |
|
0
|
|
|
|
|
|
|
199
|
0
|
|
|
0
|
0
|
|
sub entity_lcfirst { shift; lcfirst($_[0]) } |
|
0
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub entity_strftime { |
202
|
0
|
|
|
0
|
0
|
|
my ($this, $fmt, $sec, $is_uts) = @_; |
203
|
0
|
|
0
|
|
|
|
$sec //= time; |
204
|
0
|
|
|
|
|
|
require POSIX; |
205
|
0
|
0
|
|
|
|
|
POSIX::strftime($fmt, $is_uts ? gmtime($sec) : localtime($sec)); |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub entity_mkhash { |
209
|
0
|
|
|
0
|
0
|
|
my ($this, @list) = @_; |
210
|
0
|
|
|
|
|
|
my %hash; |
211
|
0
|
|
|
|
|
|
$hash{$_} = 1 for @list; |
212
|
0
|
|
|
|
|
|
\%hash; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub entity_datetime { |
216
|
0
|
|
|
0
|
0
|
|
my ($this, $method, @args) = @_; |
217
|
0
|
|
0
|
|
|
|
$method //= 'now'; |
218
|
0
|
|
|
|
|
|
require DateTime; |
219
|
0
|
|
|
|
|
|
DateTime->$method(@args); |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub entity_redirect { |
223
|
0
|
|
|
0
|
0
|
|
my ($this) = shift; |
224
|
0
|
|
|
|
|
|
$CON->redirect(@_); |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
# &yatt:code_of_entity(redirect); |
228
|
|
|
|
|
|
|
# |
229
|
|
|
|
|
|
|
sub entity_code_of_entity { |
230
|
0
|
|
|
0
|
0
|
|
shift->entity_code_of(entity => @_); |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub entity_code_of { |
234
|
0
|
|
|
0
|
0
|
|
my ($this, $prefix, $name) = @_; |
235
|
0
|
|
|
|
|
|
$this->can(join("_", $prefix, $name)); |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub entity_inspector { |
239
|
0
|
|
|
0
|
0
|
|
require Sub::Inspector; |
240
|
0
|
|
|
|
|
|
my ($this, $code) = @_; |
241
|
0
|
0
|
|
|
|
|
croak "Not a code ref" unless ref $code; |
242
|
0
|
|
|
|
|
|
Sub::Inspector->new($code); |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
20
|
|
|
20
|
|
183
|
use YATT::Lite::Breakpoint (); |
|
20
|
|
|
|
|
48
|
|
|
20
|
|
|
|
|
843
|
|
246
|
|
|
|
|
|
|
YATT::Lite::Breakpoint::break_load_entns(); |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
1; |