| 1 | package HTML::Widgets::NavMenu::Tree::Iterator; | ||||||||||||||||||||
| 2 | 23 | $HTML::Widgets::NavMenu::Tree::Iterator::VERSION = '1.1000'; | |||||||||||||||||||
| 3 | 23 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 23 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 23 | ▶ | use parent qw(HTML::Widgets::NavMenu::Object); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 23 | ▶ | use HTML::Widgets::NavMenu::Tree::Iterator::Stack (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 23 | ▶ | use HTML::Widgets::NavMenu::Tree::Iterator::Item (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 23 | __PACKAGE__->mk_acc_ref( | |||||||||||||||||||
| 12 | [ | ||||||||||||||||||||
| 13 | qw( | ||||||||||||||||||||
| 14 | coords | ||||||||||||||||||||
| 15 | stack | ||||||||||||||||||||
| 16 | _top | ||||||||||||||||||||
| 17 | ) | ||||||||||||||||||||
| 18 | ] | ||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | sub _init | ||||||||||||||||||||
| 23 | 358 | ▶ | { | ||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | 358 | my $self = shift; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 358 | $self->stack( HTML::Widgets::NavMenu::Tree::Iterator::Stack->new() ); | |||||||||||||||||||
| 27 | 358 | $self->{_top} = undef(); | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 358 | return 0; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | sub top | ||||||||||||||||||||
| 34 | 4443 | ▶ | { | ||||||||||||||||||
|
Subroutine
top: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 35 | 4443 | return shift(@_)->{_top}; | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | sub _construct_new_item | ||||||||||||||||||||
| 39 | 286 | ▶ | { | ||||||||||||||||||
|
Subroutine
_construct_new_item: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 40 | 286 | my ( $self, $args ) = @_; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 286 | return HTML::Widgets::NavMenu::Tree::Iterator::Item->new($args); | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | sub get_new_item | ||||||||||||||||||||
| 47 | 1265 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_new_item: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 48 | 1265 | my ( $self, $args ) = @_; | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 1265 | my $node = $args->{'node'}; | |||||||||||||||||||
| 51 | 1265 | my $parent_item = $args->{'parent_item'}; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 1265 | 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 | 106 | ▶ | { | ||||||||||||||||||
|
Subroutine
traverse: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||
| 70 | 106 | my $self = shift; | |||||||||||||||||||
| 71 | 106 | my $_items = $self->stack->_items; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 583 | ▶ | my $push = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 74 | 583 | push @{$_items}, | |||||||||||||||||||
| 75 | ( | ||||||||||||||||||||
| 76 | $self->{_top} = $self->get_new_item( | ||||||||||||||||||||
| 77 | { | ||||||||||||||||||||
| 78 | 'node' => shift(@_), | ||||||||||||||||||||
| 79 | 'parent_item' => $self->{_top}, | ||||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | ) | ||||||||||||||||||||
| 82 | 583 | ); | |||||||||||||||||||
| 83 | 106 | }; | |||||||||||||||||||
| 84 | 106 | $push->( $self->get_initial_node() ); | |||||||||||||||||||
| 85 | 106 | $self->{_is_root} = ( scalar(@$_items) == 1 ); | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 106 | my $co = $self->coords( [] ); | |||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 106 | ▶ | MAIN_LOOP: while ( my $top_item = $self->{_top} ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | { | ||||||||||||||||||||
| 91 | 1060 | my $visited = $top_item->_is_visited(); | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 1060 | ▶ | if ( !$visited ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | { | ||||||||||||||||||||
| 95 | 583 | $self->node_start(); | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 1060 | ▶ | my $sub_item = ( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | $self->node_should_recurse() | ||||||||||||||||||||
| 100 | ? $top_item->_visit() | ||||||||||||||||||||
| 101 | : undef | ||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 1060 | ▶ | if ( defined($sub_item) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 105 | { | ||||||||||||||||||||
| 106 | 477 | push @$co, $top_item->_visited_index(); | |||||||||||||||||||
| 107 | 477 | $push->( | |||||||||||||||||||
| 108 | $self->get_node_from_sub( | ||||||||||||||||||||
| 109 | { | ||||||||||||||||||||
| 110 | 'item' => $top_item, | ||||||||||||||||||||
| 111 | 'sub' => $sub_item, | ||||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | ), | ||||||||||||||||||||
| 114 | ); | ||||||||||||||||||||
| 115 | 477 | $self->{_is_root} = ( scalar(@$_items) == 1 ); | |||||||||||||||||||
| 116 | 477 | next MAIN_LOOP; | |||||||||||||||||||
| 117 | } | ||||||||||||||||||||
| 118 | else | ||||||||||||||||||||
| 119 | { | ||||||||||||||||||||
| 120 | 583 | $self->node_end(); | |||||||||||||||||||
| 121 | 583 | pop @$_items; | |||||||||||||||||||
| 122 | 583 | $self->{_top} = $_items->[-1]; | |||||||||||||||||||
| 123 | 583 | $self->{_is_root} = ( scalar(@$_items) == 1 ); | |||||||||||||||||||
| 124 | 583 | pop @$co; | |||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | } | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 106 | return 0; | |||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | sub get_node_from_sub | ||||||||||||||||||||
| 133 | 822 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_node_from_sub: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 134 | 822 | return $_[1]->{'sub'}; | |||||||||||||||||||
| 135 | } | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | sub find_node_by_coords | ||||||||||||||||||||
| 139 | 335 | ▶ | { | ||||||||||||||||||
|
Subroutine
find_node_by_coords: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 140 | 335 | my $self = shift; | |||||||||||||||||||
| 141 | 335 | my $coords = shift; | |||||||||||||||||||
| 142 | 335 | ▶ | my $callback = shift || ( sub { } ); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
Condition33%1/3
shift() || sub {
}
MC/DC0%0/2
shift() || sub {
}
shift()
sub {
}
Truth table33%1/3
A || B
A= shift()B= sub {
}
| |||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 335 | my $idx = 0; | |||||||||||||||||||
| 145 | 335 | my $item = $self->get_new_item( | |||||||||||||||||||
| 146 | { | ||||||||||||||||||||
| 147 | 'node' => $self->get_initial_node(), | ||||||||||||||||||||
| 148 | } | ||||||||||||||||||||
| 149 | ); | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | 682 | ▶ | my $internal_callback = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 152 | 682 | $callback->( | |||||||||||||||||||
| 153 | 'idx' => $idx, | ||||||||||||||||||||
| 154 | 'item' => $item, | ||||||||||||||||||||
| 155 | 'self' => $self, | ||||||||||||||||||||
| 156 | ); | ||||||||||||||||||||
| 157 | 335 | }; | |||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | 335 | $internal_callback->(); | |||||||||||||||||||
| 160 | 335 | foreach my $c (@$coords) | |||||||||||||||||||
| 161 | { | ||||||||||||||||||||
| 162 | 347 | $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 | ++$idx; | |||||||||||||||||||
| 174 | 347 | $internal_callback->(); | |||||||||||||||||||
| 175 | } | ||||||||||||||||||||
| 176 | 335 | return +{ 'item' => $item, }; | |||||||||||||||||||
| 177 | } | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | sub get_coords | ||||||||||||||||||||
| 181 | 50 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_coords: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 182 | 50 | my $self = shift; | |||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | 50 | return $self->coords(); | |||||||||||||||||||
| 185 | } | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | sub _is_root | ||||||||||||||||||||
| 188 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_is_root: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 189 | 0 | my $self = shift; | |||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | 0 | return $self->{_is_root}; | |||||||||||||||||||
| 192 | } | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | 23 | 1; | |||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | __END__ | ||||||||||||||||||||