line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: perl; coding: utf-8 -*- |
2
|
|
|
|
|
|
|
package YATT::Widget; |
3
|
4
|
|
|
4
|
|
13
|
use strict; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
115
|
|
4
|
4
|
|
|
4
|
|
13
|
use warnings FATAL => qw(all); |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
140
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
14
|
BEGIN {require Exporter; *import = \&Exporter::import} |
|
4
|
|
|
|
|
75
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
12
|
use base qw(YATT::Class::Configurable); |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
265
|
|
9
|
4
|
|
|
|
|
19
|
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
|
|
15
|
); |
|
4
|
|
|
|
|
5
|
|
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
|
|
28
|
use YATT::Types qw(:export_alias) |
26
|
|
|
|
|
|
|
, -alias => [Cursor => 'YATT::LRXML::NodeCursor' |
27
|
4
|
|
|
4
|
|
18
|
, Widget => __PACKAGE__]; |
|
4
|
|
|
|
|
4
|
|
28
|
4
|
|
|
4
|
|
17
|
use YATT::LRXML::Node qw(create_node); |
|
4
|
|
|
|
|
120
|
|
|
4
|
|
|
|
|
165
|
|
29
|
4
|
|
|
4
|
|
15
|
use YATT::Util qw(add_arg_order_in call_type); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
138
|
|
30
|
|
|
|
|
|
|
|
31
|
4
|
|
|
4
|
|
19
|
use Carp; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
2295
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub after_configure { |
34
|
280
|
|
|
280
|
0
|
389
|
my MY $widget = shift; |
35
|
280
|
|
66
|
|
|
1406
|
$widget->{cf_root} ||= $widget->create_node('root'); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub cursor { |
39
|
414
|
|
|
414
|
0
|
445
|
my Widget $widget = shift; |
40
|
414
|
|
|
|
|
1473
|
$widget->call_type(Cursor => new_opened => $widget->{cf_root}, @_); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub add_arg { |
44
|
416
|
|
|
416
|
0
|
720
|
(my Widget $widget, my ($name, $arg)) = @_; |
45
|
416
|
|
|
|
|
1469
|
add_arg_order_in($widget->{arg_dict}, $widget->{arg_order}, $name, $arg); |
46
|
416
|
|
|
|
|
1191
|
$widget; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub has_arg { |
50
|
422
|
|
|
422
|
0
|
448
|
(my Widget $widget, my ($name)) = @_; |
51
|
422
|
|
|
|
|
1327
|
defined $widget->{arg_dict}{$name}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub has_virtual_var { |
55
|
6
|
|
|
6
|
0
|
12
|
(my Widget $widget, my ($name)) = @_; |
56
|
6
|
|
|
|
|
25
|
$widget->{virtual_var_dict}{$name} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub add_virtual_var { |
60
|
6
|
|
|
6
|
0
|
18
|
(my Widget $widget, my ($name, $var)) = @_; |
61
|
6
|
|
|
|
|
46
|
$widget->{virtual_var_dict}{$name} = $var; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub widget_scope { |
65
|
220
|
|
|
220
|
0
|
276
|
(my Widget $widget, my ($outer)) = @_; |
66
|
220
|
|
100
|
|
|
700
|
my $args = $widget->{arg_dict} ||= {}; |
67
|
220
|
100
|
66
|
|
|
728
|
if ($widget->{virtual_var_dict} and keys %{$widget->{virtual_var_dict}}) { |
|
6
|
|
|
|
|
30
|
|
68
|
6
|
|
|
|
|
28
|
[$args, [$widget->{virtual_var_dict}, $outer]]; |
69
|
|
|
|
|
|
|
} else { |
70
|
214
|
|
|
|
|
1101
|
[$args, $outer]; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub copy_specs_from { |
75
|
6
|
|
|
6
|
0
|
11
|
(my Widget $this, my Widget $from) = @_; |
76
|
6
|
|
|
|
|
10
|
my @names; |
77
|
|
|
|
|
|
|
{ |
78
|
6
|
|
|
|
|
8
|
my ($dict, $order) = $from->arg_specs; |
|
6
|
|
|
|
|
25
|
|
79
|
6
|
|
|
|
|
16
|
foreach my $name (@$order) { |
80
|
22
|
100
|
|
|
|
33
|
unless ($this->has_arg($name)) { |
81
|
19
|
|
|
|
|
59
|
$this->add_arg($name, $dict->{$name}->clone); |
82
|
|
|
|
|
|
|
} |
83
|
22
|
|
|
|
|
47
|
push @names, $name; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
{ |
87
|
|
|
|
|
|
|
# XXX: 深く考え切れてない。 |
88
|
|
|
|
|
|
|
# order には Spec object が入っている。 |
89
|
|
|
|
|
|
|
# dict には Slot object が入っている |
90
|
6
|
|
|
|
|
12
|
my ($dst_dict, $dst_order) = $this->macro_specs; |
|
6
|
|
|
|
|
22
|
|
91
|
6
|
|
|
|
|
19
|
my ($src_dict, $src_order) = $from->macro_specs; |
92
|
6
|
|
|
|
|
11
|
push @$dst_order, @$src_order; |
93
|
6
|
|
|
|
|
23
|
foreach my $trigger (keys %$src_dict) { |
94
|
0
|
|
0
|
|
|
0
|
$dst_dict->{$trigger} ||= $src_dict->{$trigger}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
6
|
|
|
|
|
35
|
@names; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub arg_specs { |
101
|
98
|
|
|
98
|
0
|
134
|
(my Widget $widget) = @_; |
102
|
98
|
|
50
|
|
|
569
|
my @list = ($widget->{arg_dict} ||= {} |
|
|
|
100
|
|
|
|
|
103
|
|
|
|
|
|
|
, $widget->{arg_order} ||= []); |
104
|
98
|
50
|
|
|
|
509
|
wantarray ? @list : \@list; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub get_arg_spec { |
108
|
0
|
|
|
0
|
0
|
0
|
(my Widget $widget, my ($name, $default)) = @_; |
109
|
0
|
0
|
|
|
|
0
|
my $dict = $widget->{arg_dict} |
110
|
|
|
|
|
|
|
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
|
35
|
(my Widget $widget) = @_; |
119
|
28
|
|
100
|
|
|
290
|
my @list = ($widget->{argmacro_dict} ||= {} |
|
|
|
100
|
|
|
|
|
120
|
|
|
|
|
|
|
, $widget->{argmacro_order} ||= []); |
121
|
28
|
50
|
|
|
|
95
|
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; |