line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: perl; coding: utf-8 -*- |
2
|
|
|
|
|
|
|
package YATT::Widget; |
3
|
4
|
|
|
4
|
|
20
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
118
|
|
4
|
4
|
|
|
4
|
|
25
|
use warnings qw(FATAL all NONFATAL misc); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
210
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
20
|
BEGIN {require Exporter; *import = \&Exporter::import} |
|
4
|
|
|
|
|
86
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
22
|
use base qw(YATT::Class::Configurable); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
374
|
|
9
|
4
|
|
|
|
|
24
|
use YATT::Fields qw(^=arg_dict |
10
|
|
|
|
|
|
|
^=arg_order |
11
|
|
|
|
|
|
|
^=virtual_var_dict |
12
|
|
|
|
|
|
|
^=argmacro_dict |
13
|
|
|
|
|
|
|
^=argmacro_order |
14
|
|
|
|
|
|
|
^cf_root |
15
|
|
|
|
|
|
|
^cf_name |
16
|
|
|
|
|
|
|
^cf_filename |
17
|
|
|
|
|
|
|
^cf_declared |
18
|
|
|
|
|
|
|
^cf_public |
19
|
|
|
|
|
|
|
cf_decl_start |
20
|
|
|
|
|
|
|
cf_body_start |
21
|
|
|
|
|
|
|
^cf_template_nsid |
22
|
|
|
|
|
|
|
^cf_no_last_newline |
23
|
4
|
|
|
4
|
|
27
|
); |
|
4
|
|
|
|
|
19
|
|
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
|
|
42
|
use YATT::Types qw(:export_alias) |
26
|
|
|
|
|
|
|
, -alias => [Cursor => 'YATT::LRXML::NodeCursor' |
27
|
4
|
|
|
4
|
|
23
|
, Widget => __PACKAGE__]; |
|
4
|
|
|
|
|
7
|
|
28
|
4
|
|
|
4
|
|
28
|
use YATT::LRXML::Node qw(create_node); |
|
4
|
|
|
|
|
169
|
|
|
4
|
|
|
|
|
212
|
|
29
|
4
|
|
|
4
|
|
22
|
use YATT::Util qw(add_arg_order_in call_type); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
212
|
|
30
|
|
|
|
|
|
|
|
31
|
4
|
|
|
4
|
|
24
|
use Carp; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
3986
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub after_configure { |
34
|
280
|
|
|
280
|
0
|
436
|
my MY $widget = shift; |
35
|
280
|
|
66
|
|
|
1670
|
$widget->{cf_root} ||= $widget->create_node('root'); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub cursor { |
39
|
414
|
|
|
414
|
0
|
667
|
my Widget $widget = shift; |
40
|
414
|
|
|
|
|
1795
|
$widget->call_type(Cursor => new_opened => $widget->{cf_root}, @_); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub add_arg { |
44
|
416
|
|
|
416
|
0
|
1044
|
(my Widget $widget, my ($name, $arg)) = @_; |
45
|
416
|
|
|
|
|
1771
|
add_arg_order_in($widget->{arg_dict}, $widget->{arg_order}, $name, $arg); |
46
|
416
|
|
|
|
|
1684
|
$widget; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub has_arg { |
50
|
422
|
|
|
422
|
0
|
730
|
(my Widget $widget, my ($name)) = @_; |
51
|
422
|
|
|
|
|
1750
|
defined $widget->{arg_dict}{$name}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub has_virtual_var { |
55
|
6
|
|
|
6
|
0
|
15
|
(my Widget $widget, my ($name)) = @_; |
56
|
6
|
|
|
|
|
33
|
$widget->{virtual_var_dict}{$name} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub add_virtual_var { |
60
|
6
|
|
|
6
|
0
|
19
|
(my Widget $widget, my ($name, $var)) = @_; |
61
|
6
|
|
|
|
|
54
|
$widget->{virtual_var_dict}{$name} = $var; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub widget_scope { |
65
|
220
|
|
|
220
|
0
|
384
|
(my Widget $widget, my ($outer)) = @_; |
66
|
220
|
|
100
|
|
|
931
|
my $args = $widget->{arg_dict} ||= {}; |
67
|
220
|
100
|
66
|
|
|
880
|
if ($widget->{virtual_var_dict} and keys %{$widget->{virtual_var_dict}}) { |
|
6
|
|
|
|
|
33
|
|
68
|
6
|
|
|
|
|
45
|
[$args, [$widget->{virtual_var_dict}, $outer]]; |
69
|
|
|
|
|
|
|
} else { |
70
|
214
|
|
|
|
|
1362
|
[$args, $outer]; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub copy_specs_from { |
75
|
6
|
|
|
6
|
0
|
12
|
(my Widget $this, my Widget $from) = @_; |
76
|
6
|
|
|
|
|
12
|
my @names; |
77
|
|
|
|
|
|
|
{ |
78
|
6
|
|
|
|
|
26
|
my ($dict, $order) = $from->arg_specs; |
79
|
6
|
|
|
|
|
21
|
foreach my $name (@$order) { |
80
|
22
|
100
|
|
|
|
47
|
unless ($this->has_arg($name)) { |
81
|
19
|
|
|
|
|
90
|
$this->add_arg($name, $dict->{$name}->clone); |
82
|
|
|
|
|
|
|
} |
83
|
22
|
|
|
|
|
79
|
push @names, $name; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
{ |
87
|
|
|
|
|
|
|
# XXX: 深く考え切れてない。 |
88
|
|
|
|
|
|
|
# order には Spec object が入っている。 |
89
|
|
|
|
|
|
|
# dict には Slot object が入っている |
90
|
6
|
|
|
|
|
10
|
my ($dst_dict, $dst_order) = $this->macro_specs; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
26
|
|
91
|
6
|
|
|
|
|
20
|
my ($src_dict, $src_order) = $from->macro_specs; |
92
|
6
|
|
|
|
|
12
|
push @$dst_order, @$src_order; |
93
|
6
|
|
|
|
|
21
|
foreach my $trigger (keys %$src_dict) { |
94
|
0
|
|
0
|
|
|
0
|
$dst_dict->{$trigger} ||= $src_dict->{$trigger}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
6
|
|
|
|
|
53
|
@names; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub arg_specs { |
101
|
98
|
|
|
98
|
0
|
177
|
(my Widget $widget) = @_; |
102
|
|
|
|
|
|
|
my @list = ($widget->{arg_dict} ||= {} |
103
|
98
|
|
50
|
|
|
588
|
, $widget->{arg_order} ||= []); |
|
|
|
100
|
|
|
|
|
104
|
98
|
50
|
|
|
|
594
|
wantarray ? @list : \@list; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub get_arg_spec { |
108
|
0
|
|
|
0
|
0
|
0
|
(my Widget $widget, my ($name, $default)) = @_; |
109
|
|
|
|
|
|
|
my $dict = $widget->{arg_dict} |
110
|
0
|
0
|
|
|
|
0
|
or return $default; |
111
|
0
|
0
|
|
|
|
0
|
defined (my $spec = $dict->{$name}) |
112
|
|
|
|
|
|
|
or return $default; |
113
|
0
|
0
|
|
|
|
0
|
return $default unless exists $spec->{arg_dict}; |
114
|
0
|
|
|
|
|
0
|
$spec->{arg_dict}; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub macro_specs { |
118
|
28
|
|
|
28
|
0
|
61
|
(my Widget $widget) = @_; |
119
|
|
|
|
|
|
|
my @list = ($widget->{argmacro_dict} ||= {} |
120
|
28
|
|
100
|
|
|
312
|
, $widget->{argmacro_order} ||= []); |
|
|
|
100
|
|
|
|
|
121
|
28
|
50
|
|
|
|
117
|
wantarray ? @list : \@list; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub reorder_params { |
125
|
0
|
|
|
0
|
0
|
|
(my Widget $widget, my ($params)) = @_; |
126
|
0
|
|
|
|
|
|
my @params; |
127
|
0
|
0
|
|
|
|
|
foreach my $name (map($_ ? @$_ : (), $widget->{arg_order})) { |
128
|
0
|
|
|
|
|
|
push @params, delete $params->{$name}; |
129
|
|
|
|
|
|
|
} |
130
|
0
|
0
|
|
|
|
|
if (keys %$params) { |
131
|
0
|
|
|
|
|
|
die "Unknown args for $widget->{cf_name}: " . join(", ", keys %$params); |
132
|
|
|
|
|
|
|
} |
133
|
0
|
0
|
|
|
|
|
wantarray ? @params : \@params; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub reorder_cgi_params { |
137
|
0
|
|
|
0
|
0
|
|
(my Widget $widget, my ($cgi, $list)) = @_; |
138
|
0
|
|
0
|
|
|
|
$list ||= []; |
139
|
0
|
|
|
|
|
|
foreach my $name ($cgi->param) { |
140
|
0
|
0
|
|
|
|
|
my $argdecl = $widget->{arg_dict}{$name} |
141
|
|
|
|
|
|
|
or die "Unknown args for widget '$widget->{cf_name}': $name"; |
142
|
0
|
|
|
|
|
|
my @value = $cgi->multi_param($name); |
143
|
0
|
0
|
|
|
|
|
$list->[$argdecl->argno] = $argdecl->type_name eq 'list' |
144
|
|
|
|
|
|
|
? \@value : $value[0]; |
145
|
|
|
|
|
|
|
} |
146
|
0
|
|
|
|
|
|
$list; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |