line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package YATT::Lite::Entities; |
2
|
14
|
|
|
14
|
|
90
|
use strict; |
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
459
|
|
3
|
14
|
|
|
14
|
|
70
|
use warnings qw(FATAL all NONFATAL misc); |
|
14
|
|
|
|
|
29
|
|
|
14
|
|
|
|
|
538
|
|
4
|
14
|
|
|
14
|
|
67
|
use Carp; |
|
14
|
|
|
|
|
23
|
|
|
14
|
|
|
|
|
1060
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#use mro 'c3'; |
7
|
|
|
|
|
|
|
# XXX: 残念ながら、要整理。 |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require YATT::Lite::MFields; |
10
|
|
|
|
|
|
|
|
11
|
14
|
|
|
14
|
|
69
|
use YATT::Lite::Util qw/globref terse_dump url_encode/; |
|
14
|
|
|
|
|
30
|
|
|
14
|
|
|
|
|
26162
|
|
12
|
|
|
|
|
|
|
|
13
|
14
|
|
|
14
|
0
|
45
|
sub default_export { qw(*YATT) } |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#======================================== |
16
|
|
|
|
|
|
|
# Facade を template に見せるための, グローバル変数. |
17
|
|
|
|
|
|
|
our $YATT; |
18
|
34
|
|
|
34
|
0
|
591
|
sub symbol_YATT { return *YATT } |
19
|
0
|
|
|
0
|
0
|
0
|
sub YATT { $YATT } |
20
|
0
|
|
|
0
|
0
|
0
|
sub DIR { $YATT } |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Factory/Dispatcher/Logger/... を template に見せる |
23
|
|
|
|
|
|
|
our $SYS; |
24
|
39
|
|
|
39
|
0
|
699
|
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
|
39
|
|
|
39
|
0
|
553
|
sub symbol_CON { return *CON } |
31
|
0
|
|
|
0
|
0
|
0
|
sub CON { return $CON } |
32
|
|
|
|
|
|
|
#======================================== |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub import { |
35
|
50
|
|
|
50
|
|
188
|
my ($pack, @opts) = @_; |
36
|
50
|
100
|
|
|
|
246
|
@opts = $pack->default_export unless @opts; |
37
|
50
|
|
|
|
|
127
|
my $callpack = caller; |
38
|
50
|
|
|
|
|
73
|
my (%opts, @task); |
39
|
50
|
|
|
|
|
176
|
foreach my $exp (@opts) { |
40
|
149
|
100
|
|
|
|
2149
|
if (my $sub = $pack->can("define_$exp")) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
41
|
25
|
|
|
|
|
81
|
push @task, $sub; |
42
|
|
|
|
|
|
|
} elsif ($exp =~ /^-(\w+)$/) { |
43
|
22
|
50
|
|
|
|
216
|
$sub = $pack->can("declare_$1") |
44
|
|
|
|
|
|
|
or croak "Unknown declarator: $1"; |
45
|
22
|
|
|
|
|
90
|
$sub->($pack, \%opts, $callpack); |
46
|
|
|
|
|
|
|
} elsif ($exp =~ /^\*(\w+)$/) { |
47
|
102
|
50
|
|
|
|
801
|
$sub = $pack->can("symbol_$1") |
48
|
|
|
|
|
|
|
or croak "Can't export symbol $1"; |
49
|
102
|
|
|
|
|
270
|
my $val = $sub->(); |
50
|
102
|
50
|
|
|
|
723
|
unless (defined $val) { |
51
|
0
|
|
|
|
|
0
|
croak "Undefined symbol in export spec: $exp"; |
52
|
|
|
|
|
|
|
} |
53
|
102
|
|
|
|
|
135
|
*{globref($callpack, $1)} = $val; |
|
102
|
|
|
|
|
306
|
|
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
|
50
|
|
|
|
|
2927
|
foreach my $sub (@task) { |
61
|
25
|
|
|
|
|
104
|
$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
|
22
|
|
|
22
|
0
|
52
|
my ($myPack, $opts, $callpack) = @_; |
72
|
|
|
|
|
|
|
# ckrequire($myPack); # Not needed because $myPack is just used! |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Fill $callpack's %FIELDS, by current ISA. |
75
|
22
|
|
|
|
|
117
|
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
|
75
|
require YATT::Lite::Breakpoint; |
100
|
1
|
|
|
|
|
6
|
&YATT::Lite::Breakpoint::breakpoint(); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub entity_concat { |
104
|
1
|
|
|
1
|
0
|
84
|
my $this = shift; |
105
|
1
|
|
|
|
|
7
|
join '', @_; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# coalesce |
109
|
|
|
|
|
|
|
*entity_coalesce = *entity_default; *entity_coalesce = *entity_default; |
110
|
|
|
|
|
|
|
sub entity_default { |
111
|
0
|
|
|
0
|
0
|
0
|
my $this = shift; |
112
|
0
|
|
|
|
|
0
|
foreach my $str (@_) { |
113
|
0
|
0
|
0
|
|
|
0
|
return $str if defined $str and $str ne ''; |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
0
|
''; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
*entity_lsize = *entity_llength; *entity_lsize = *entity_llength; |
119
|
|
|
|
|
|
|
sub entity_llength { |
120
|
0
|
|
|
0
|
0
|
0
|
my ($this, $list) = @_; |
121
|
0
|
0
|
0
|
|
|
0
|
return undef unless defined $list and ref $list eq 'ARRAY'; |
122
|
0
|
|
|
|
|
0
|
scalar @$list; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub entity_join { |
126
|
3
|
|
|
3
|
0
|
229
|
my ($this, $sep) = splice @_, 0, 2; |
127
|
3
|
50
|
|
|
|
7
|
join $sep, grep {defined $_ && $_ ne ''} @_; |
|
11
|
|
|
|
|
67
|
|
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub entity_format { |
131
|
1
|
|
|
1
|
0
|
78
|
my ($this, $format) = (shift, shift); |
132
|
1
|
|
|
|
|
7
|
sprintf $format, @_; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub entity_HTML { |
136
|
5
|
|
|
5
|
0
|
473
|
my $this = shift; |
137
|
5
|
|
|
|
|
17
|
\ join "", grep {defined $_} @_; |
|
10
|
|
|
|
|
50
|
|
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub entity_url_encode { |
141
|
1
|
|
|
1
|
0
|
78
|
my $this = shift; |
142
|
1
|
|
|
|
|
3
|
join "", map {url_encode($this, $_)} @_; |
|
1
|
|
|
|
|
6
|
|
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub entity_alternative { |
146
|
3
|
|
|
3
|
0
|
86
|
my ($this, $value, $list) = @_; |
147
|
3
|
|
|
|
|
4
|
my @alt = do { |
148
|
3
|
50
|
|
|
|
9
|
if (defined $value) { |
149
|
3
|
|
|
|
|
5
|
grep {$value ne $_} @$list; |
|
6
|
|
|
|
|
16
|
|
150
|
|
|
|
|
|
|
} else { |
151
|
0
|
|
|
|
|
0
|
grep {defined $_} @$list; |
|
0
|
|
|
|
|
0
|
|
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
}; |
154
|
3
|
|
|
|
|
16
|
$alt[0] |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# XXX: auto url_encode |
158
|
|
|
|
|
|
|
sub entity_append_params { |
159
|
3
|
|
|
3
|
0
|
216
|
my ($this, $url) = splice @_, 0, 2; |
160
|
3
|
50
|
|
|
|
12
|
return $url unless @_; |
161
|
3
|
|
|
|
|
101
|
require URI; |
162
|
3
|
|
|
|
|
3781
|
require Hash::MultiValue; |
163
|
3
|
|
|
|
|
3158
|
my $uri = URI->new($url); |
164
|
3
|
|
|
|
|
8072
|
my $hmv = Hash::MultiValue->new($uri->query_form); |
165
|
3
|
|
|
|
|
295
|
my %multi; |
166
|
3
|
|
|
|
|
8
|
foreach my $item (@_) { |
167
|
5
|
|
|
|
|
66
|
my ($key, @strs) = @$item; |
168
|
5
|
100
|
|
|
|
29
|
$hmv->remove($key) unless $multi{$key}++; |
169
|
5
|
|
|
|
|
107
|
$hmv->add($key, join("", @strs)); |
170
|
|
|
|
|
|
|
} |
171
|
3
|
|
|
|
|
91
|
$uri->query_form($hmv->flatten); |
172
|
3
|
|
|
|
|
315
|
$uri->as_string; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub entity_dump { |
176
|
2
|
|
|
2
|
0
|
197
|
shift; |
177
|
2
|
|
|
|
|
13
|
terse_dump(@_); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub entity_can_render { |
181
|
0
|
|
|
0
|
0
|
|
my ($this, $widget) = @_; |
182
|
0
|
|
|
|
|
|
$this->can("render_$widget"); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
0
|
0
|
|
sub entity_uc { shift; uc($_[0]) } |
|
0
|
|
|
|
|
|
|
186
|
0
|
|
|
0
|
0
|
|
sub entity_ucfirst { shift; ucfirst($_[0]) } |
|
0
|
|
|
|
|
|
|
187
|
0
|
|
|
0
|
0
|
|
sub entity_lc { shift; lc($_[0]) } |
|
0
|
|
|
|
|
|
|
188
|
0
|
|
|
0
|
0
|
|
sub entity_lcfirst { shift; lcfirst($_[0]) } |
|
0
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub entity_strftime { |
191
|
0
|
|
|
0
|
0
|
|
my ($this, $fmt, $sec, $is_uts) = @_; |
192
|
0
|
|
0
|
|
|
|
$sec //= time; |
193
|
0
|
|
|
|
|
|
require POSIX; |
194
|
0
|
0
|
|
|
|
|
POSIX::strftime($fmt, $is_uts ? gmtime($sec) : localtime($sec)); |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub entity_mkhash { |
198
|
0
|
|
|
0
|
0
|
|
my ($this, @list) = @_; |
199
|
0
|
|
|
|
|
|
my %hash; |
200
|
0
|
|
|
|
|
|
$hash{$_} = 1 for @list; |
201
|
0
|
|
|
|
|
|
\%hash; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub entity_datetime { |
205
|
0
|
|
|
0
|
0
|
|
my ($this, $method, @args) = @_; |
206
|
0
|
|
0
|
|
|
|
$method //= 'now'; |
207
|
0
|
|
|
|
|
|
require DateTime; |
208
|
0
|
|
|
|
|
|
DateTime->$method(@args); |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub entity_redirect { |
212
|
0
|
|
|
0
|
0
|
|
my ($this) = shift; |
213
|
0
|
|
|
|
|
|
$CON->redirect(@_); |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
# &yatt:code_of_entity(redirect); |
217
|
|
|
|
|
|
|
# |
218
|
|
|
|
|
|
|
sub entity_code_of_entity { |
219
|
0
|
|
|
0
|
0
|
|
shift->entity_code_of(entity => @_); |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub entity_code_of { |
223
|
0
|
|
|
0
|
0
|
|
my ($this, $prefix, $name) = @_; |
224
|
0
|
|
|
|
|
|
$this->can(join("_", $prefix, $name)); |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub entity_inspector { |
228
|
0
|
|
|
0
|
0
|
|
require Sub::Inspector; |
229
|
0
|
|
|
|
|
|
my ($this, $code) = @_; |
230
|
0
|
0
|
|
|
|
|
croak "Not a code ref" unless ref $code; |
231
|
0
|
|
|
|
|
|
Sub::Inspector->new($code); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
14
|
|
|
14
|
|
84
|
use YATT::Lite::Breakpoint (); |
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
548
|
|
235
|
|
|
|
|
|
|
YATT::Lite::Breakpoint::break_load_entns(); |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
1; |