line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Widgets::NavMenu::Tree::Iterator; |
2
|
|
|
|
|
|
|
$HTML::Widgets::NavMenu::Tree::Iterator::VERSION = '1.1000'; |
3
|
12
|
|
|
12
|
|
5216
|
use strict; |
|
12
|
|
|
|
|
27
|
|
|
12
|
|
|
|
|
265
|
|
4
|
12
|
|
|
12
|
|
48
|
use warnings; |
|
12
|
|
|
|
|
17
|
|
|
12
|
|
|
|
|
257
|
|
5
|
|
|
|
|
|
|
|
6
|
12
|
|
|
12
|
|
73
|
use parent qw(HTML::Widgets::NavMenu::Object); |
|
12
|
|
|
|
|
25
|
|
|
12
|
|
|
|
|
86
|
|
7
|
|
|
|
|
|
|
|
8
|
12
|
|
|
12
|
|
4948
|
use HTML::Widgets::NavMenu::Tree::Iterator::Stack (); |
|
12
|
|
|
|
|
27
|
|
|
12
|
|
|
|
|
223
|
|
9
|
12
|
|
|
12
|
|
3940
|
use HTML::Widgets::NavMenu::Tree::Iterator::Item (); |
|
12
|
|
|
|
|
27
|
|
|
12
|
|
|
|
|
7219
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
__PACKAGE__->mk_acc_ref( |
12
|
|
|
|
|
|
|
[ |
13
|
|
|
|
|
|
|
qw( |
14
|
|
|
|
|
|
|
coords |
15
|
|
|
|
|
|
|
stack |
16
|
|
|
|
|
|
|
_top |
17
|
|
|
|
|
|
|
) |
18
|
|
|
|
|
|
|
] |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _init |
23
|
|
|
|
|
|
|
{ |
24
|
358
|
|
|
358
|
|
489
|
my $self = shift; |
25
|
|
|
|
|
|
|
|
26
|
358
|
|
|
|
|
784
|
$self->stack( HTML::Widgets::NavMenu::Tree::Iterator::Stack->new() ); |
27
|
358
|
|
|
|
|
670
|
$self->{_top} = undef(); |
28
|
|
|
|
|
|
|
|
29
|
358
|
|
|
|
|
592
|
return 0; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub top |
34
|
|
|
|
|
|
|
{ |
35
|
4443
|
|
|
4443
|
1
|
9482
|
return shift(@_)->{_top}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _construct_new_item |
39
|
|
|
|
|
|
|
{ |
40
|
286
|
|
|
286
|
|
608
|
my ( $self, $args ) = @_; |
41
|
|
|
|
|
|
|
|
42
|
286
|
|
|
|
|
541
|
return HTML::Widgets::NavMenu::Tree::Iterator::Item->new($args); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get_new_item |
47
|
|
|
|
|
|
|
{ |
48
|
1265
|
|
|
1265
|
1
|
2172
|
my ( $self, $args ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
1265
|
|
|
|
|
1686
|
my $node = $args->{'node'}; |
51
|
1265
|
|
|
|
|
1670
|
my $parent_item = $args->{'parent_item'}; |
52
|
|
|
|
|
|
|
|
53
|
1265
|
|
|
|
|
2843
|
return $self->_construct_new_item( |
54
|
|
|
|
|
|
|
{ |
55
|
|
|
|
|
|
|
'node' => $node, |
56
|
|
|
|
|
|
|
'subs' => $self->get_node_subs( { 'node' => $node } ), |
57
|
|
|
|
|
|
|
'accum_state' => $self->get_new_accum_state( |
58
|
|
|
|
|
|
|
{ |
59
|
|
|
|
|
|
|
'item' => $parent_item, |
60
|
|
|
|
|
|
|
'node' => $node, |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
), |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub traverse |
69
|
|
|
|
|
|
|
{ |
70
|
106
|
|
|
106
|
1
|
169
|
my $self = shift; |
71
|
106
|
|
|
|
|
207
|
my $_items = $self->stack->_items; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $push = sub { |
74
|
583
|
|
|
|
|
1411
|
push @{$_items}, |
75
|
|
|
|
|
|
|
( |
76
|
|
|
|
|
|
|
$self->{_top} = $self->get_new_item( |
77
|
|
|
|
|
|
|
{ |
78
|
|
|
|
|
|
|
'node' => shift(@_), |
79
|
|
|
|
|
|
|
'parent_item' => $self->{_top}, |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
) |
82
|
583
|
|
|
583
|
|
857
|
); |
83
|
106
|
|
|
|
|
366
|
}; |
84
|
106
|
|
|
|
|
284
|
$push->( $self->get_initial_node() ); |
85
|
106
|
|
|
|
|
328
|
$self->{_is_root} = ( scalar(@$_items) == 1 ); |
86
|
|
|
|
|
|
|
|
87
|
106
|
|
|
|
|
283
|
my $co = $self->coords( [] ); |
88
|
|
|
|
|
|
|
|
89
|
106
|
|
|
|
|
253
|
MAIN_LOOP: while ( my $top_item = $self->{_top} ) |
90
|
|
|
|
|
|
|
{ |
91
|
1060
|
|
|
|
|
1920
|
my $visited = $top_item->_is_visited(); |
92
|
|
|
|
|
|
|
|
93
|
1060
|
100
|
|
|
|
1833
|
if ( !$visited ) |
94
|
|
|
|
|
|
|
{ |
95
|
583
|
|
|
|
|
1088
|
$self->node_start(); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
1060
|
100
|
|
|
|
2119
|
my $sub_item = ( |
99
|
|
|
|
|
|
|
$self->node_should_recurse() |
100
|
|
|
|
|
|
|
? $top_item->_visit() |
101
|
|
|
|
|
|
|
: undef |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
|
104
|
1060
|
100
|
|
|
|
1791
|
if ( defined($sub_item) ) |
105
|
|
|
|
|
|
|
{ |
106
|
477
|
|
|
|
|
881
|
push @$co, $top_item->_visited_index(); |
107
|
477
|
|
|
|
|
1205
|
$push->( |
108
|
|
|
|
|
|
|
$self->get_node_from_sub( |
109
|
|
|
|
|
|
|
{ |
110
|
|
|
|
|
|
|
'item' => $top_item, |
111
|
|
|
|
|
|
|
'sub' => $sub_item, |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
), |
114
|
|
|
|
|
|
|
); |
115
|
477
|
|
|
|
|
1273
|
$self->{_is_root} = ( scalar(@$_items) == 1 ); |
116
|
477
|
|
|
|
|
1146
|
next MAIN_LOOP; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
else |
119
|
|
|
|
|
|
|
{ |
120
|
583
|
|
|
|
|
1406
|
$self->node_end(); |
121
|
583
|
|
|
|
|
895
|
pop @$_items; |
122
|
583
|
|
|
|
|
900
|
$self->{_top} = $_items->[-1]; |
123
|
583
|
|
|
|
|
834
|
$self->{_is_root} = ( scalar(@$_items) == 1 ); |
124
|
583
|
|
|
|
|
1321
|
pop @$co; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
106
|
|
|
|
|
423
|
return 0; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub get_node_from_sub |
133
|
|
|
|
|
|
|
{ |
134
|
822
|
|
|
822
|
1
|
1789
|
return $_[1]->{'sub'}; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub find_node_by_coords |
139
|
|
|
|
|
|
|
{ |
140
|
335
|
|
|
335
|
1
|
431
|
my $self = shift; |
141
|
335
|
|
|
|
|
390
|
my $coords = shift; |
142
|
335
|
|
50
|
682
|
|
1362
|
my $callback = shift || ( sub { } ); |
143
|
|
|
|
|
|
|
|
144
|
335
|
|
|
|
|
476
|
my $idx = 0; |
145
|
335
|
|
|
|
|
695
|
my $item = $self->get_new_item( |
146
|
|
|
|
|
|
|
{ |
147
|
|
|
|
|
|
|
'node' => $self->get_initial_node(), |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
my $internal_callback = sub { |
152
|
682
|
|
|
682
|
|
1051
|
$callback->( |
153
|
|
|
|
|
|
|
'idx' => $idx, |
154
|
|
|
|
|
|
|
'item' => $item, |
155
|
|
|
|
|
|
|
'self' => $self, |
156
|
|
|
|
|
|
|
); |
157
|
335
|
|
|
|
|
1225
|
}; |
158
|
|
|
|
|
|
|
|
159
|
335
|
|
|
|
|
776
|
$internal_callback->(); |
160
|
335
|
|
|
|
|
554
|
foreach my $c (@$coords) |
161
|
|
|
|
|
|
|
{ |
162
|
347
|
|
|
|
|
732
|
$item = $self->get_new_item( |
163
|
|
|
|
|
|
|
{ |
164
|
|
|
|
|
|
|
'node' => $self->get_node_from_sub( |
165
|
|
|
|
|
|
|
{ |
166
|
|
|
|
|
|
|
'item' => $item, |
167
|
|
|
|
|
|
|
'sub' => $item->_get_sub($c), |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
), |
170
|
|
|
|
|
|
|
'parent_item' => $item, |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
); |
173
|
347
|
|
|
|
|
1043
|
++$idx; |
174
|
347
|
|
|
|
|
522
|
$internal_callback->(); |
175
|
|
|
|
|
|
|
} |
176
|
335
|
|
|
|
|
1193
|
return +{ 'item' => $item, }; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub get_coords |
181
|
|
|
|
|
|
|
{ |
182
|
50
|
|
|
50
|
1
|
85
|
my $self = shift; |
183
|
|
|
|
|
|
|
|
184
|
50
|
|
|
|
|
138
|
return $self->coords(); |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub _is_root |
188
|
|
|
|
|
|
|
{ |
189
|
0
|
|
|
0
|
|
|
my $self = shift; |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
return $self->{_is_root}; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
__END__ |