line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: perl; coding: utf-8 -*- |
2
|
|
|
|
|
|
|
package YATT::Widget; |
3
|
4
|
|
|
4
|
|
21
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
125
|
|
4
|
4
|
|
|
4
|
|
21
|
use warnings qw(FATAL all NONFATAL misc); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
202
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
20
|
BEGIN {require Exporter; *import = \&Exporter::import} |
|
4
|
|
|
|
|
96
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
20
|
use base qw(YATT::Class::Configurable); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
360
|
|
9
|
4
|
|
|
|
|
26
|
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
|
|
24
|
); |
|
4
|
|
|
|
|
8
|
|
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
|
|
39
|
use YATT::Types qw(:export_alias) |
26
|
|
|
|
|
|
|
, -alias => [Cursor => 'YATT::LRXML::NodeCursor' |
27
|
4
|
|
|
4
|
|
24
|
, Widget => __PACKAGE__]; |
|
4
|
|
|
|
|
8
|
|
28
|
4
|
|
|
4
|
|
21
|
use YATT::LRXML::Node qw(create_node); |
|
4
|
|
|
|
|
157
|
|
|
4
|
|
|
|
|
188
|
|
29
|
4
|
|
|
4
|
|
20
|
use YATT::Util qw(add_arg_order_in call_type); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
182
|
|
30
|
|
|
|
|
|
|
|
31
|
4
|
|
|
4
|
|
19
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
3963
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub after_configure { |
34
|
280
|
|
|
280
|
0
|
567
|
my MY $widget = shift; |
35
|
280
|
|
66
|
|
|
1875
|
$widget->{cf_root} ||= $widget->create_node('root'); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub cursor { |
39
|
414
|
|
|
414
|
0
|
659
|
my Widget $widget = shift; |
40
|
414
|
|
|
|
|
2047
|
$widget->call_type(Cursor => new_opened => $widget->{cf_root}, @_); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub add_arg { |
44
|
416
|
|
|
416
|
0
|
1086
|
(my Widget $widget, my ($name, $arg)) = @_; |
45
|
416
|
|
|
|
|
1969
|
add_arg_order_in($widget->{arg_dict}, $widget->{arg_order}, $name, $arg); |
46
|
416
|
|
|
|
|
1622
|
$widget; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub has_arg { |
50
|
422
|
|
|
422
|
0
|
769
|
(my Widget $widget, my ($name)) = @_; |
51
|
422
|
|
|
|
|
1940
|
defined $widget->{arg_dict}{$name}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub has_virtual_var { |
55
|
6
|
|
|
6
|
0
|
15
|
(my Widget $widget, my ($name)) = @_; |
56
|
6
|
|
|
|
|
37
|
$widget->{virtual_var_dict}{$name} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub add_virtual_var { |
60
|
6
|
|
|
6
|
0
|
25
|
(my Widget $widget, my ($name, $var)) = @_; |
61
|
6
|
|
|
|
|
58
|
$widget->{virtual_var_dict}{$name} = $var; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub widget_scope { |
65
|
220
|
|
|
220
|
0
|
362
|
(my Widget $widget, my ($outer)) = @_; |
66
|
220
|
|
100
|
|
|
867
|
my $args = $widget->{arg_dict} ||= {}; |
67
|
220
|
100
|
66
|
|
|
923
|
if ($widget->{virtual_var_dict} and keys %{$widget->{virtual_var_dict}}) { |
|
6
|
|
|
|
|
32
|
|
68
|
6
|
|
|
|
|
43
|
[$args, [$widget->{virtual_var_dict}, $outer]]; |
69
|
|
|
|
|
|
|
} else { |
70
|
214
|
|
|
|
|
1523
|
[$args, $outer]; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub copy_specs_from { |
75
|
6
|
|
|
6
|
0
|
14
|
(my Widget $this, my Widget $from) = @_; |
76
|
6
|
|
|
|
|
14
|
my @names; |
77
|
|
|
|
|
|
|
{ |
78
|
6
|
|
|
|
|
25
|
my ($dict, $order) = $from->arg_specs; |
79
|
6
|
|
|
|
|
21
|
foreach my $name (@$order) { |
80
|
22
|
100
|
|
|
|
53
|
unless ($this->has_arg($name)) { |
81
|
19
|
|
|
|
|
85
|
$this->add_arg($name, $dict->{$name}->clone); |
82
|
|
|
|
|
|
|
} |
83
|
22
|
|
|
|
|
81
|
push @names, $name; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
{ |
87
|
|
|
|
|
|
|
# XXX: 深く考え切れてない。 |
88
|
|
|
|
|
|
|
# order には Spec object が入っている。 |
89
|
|
|
|
|
|
|
# dict には Slot object が入っている |
90
|
6
|
|
|
|
|
8
|
my ($dst_dict, $dst_order) = $this->macro_specs; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
26
|
|
91
|
6
|
|
|
|
|
22
|
my ($src_dict, $src_order) = $from->macro_specs; |
92
|
6
|
|
|
|
|
14
|
push @$dst_order, @$src_order; |
93
|
6
|
|
|
|
|
24
|
foreach my $trigger (keys %$src_dict) { |
94
|
0
|
|
0
|
|
|
0
|
$dst_dict->{$trigger} ||= $src_dict->{$trigger}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
6
|
|
|
|
|
54
|
@names; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub arg_specs { |
101
|
98
|
|
|
98
|
0
|
227
|
(my Widget $widget) = @_; |
102
|
|
|
|
|
|
|
my @list = ($widget->{arg_dict} ||= {} |
103
|
98
|
|
50
|
|
|
556
|
, $widget->{arg_order} ||= []); |
|
|
|
100
|
|
|
|
|
104
|
98
|
50
|
|
|
|
608
|
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
|
56
|
(my Widget $widget) = @_; |
119
|
|
|
|
|
|
|
my @list = ($widget->{argmacro_dict} ||= {} |
120
|
28
|
|
100
|
|
|
323
|
, $widget->{argmacro_order} ||= []); |
|
|
|
100
|
|
|
|
|
121
|
28
|
50
|
|
|
|
130
|
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; |