blib/lib/HTML/Widgets/NavMenu/Iterator/NavMenu.pm

filter: Statementstmt 100% 79 / 79 Branchbran 100% 16 / 16 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 24 / 24 Podpod 100% 5 / 5 totaltotal 100% 134 / 134 SCAR 24.0
CC
11
Cov
100%
_start_handle_non_role
3.0
_start_regular
3.0
_end_regular
3.0
CRAP 11.0
« blib/lib/HTML/Widgets/NavMenu/Predicate.pm ↑ Summary blib/lib/HTML/Widgets/NavMenu/Tree/Node.pm »
1 package HTML::Widgets::NavMenu::Iterator::NavMenu;
2 17 $HTML::Widgets::NavMenu::Iterator::NavMenu::VERSION = '1.0902';
3 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 17 ▶use parent qw(HTML::Widgets::NavMenu::Iterator::Html);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 17 ▶use HTML::Widgets::NavMenu::EscapeHtml qw/ escape_html /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 17 __PACKAGE__->mk_acc_ref(
11 [
12 qw(
13 _ul_classes
14 )
15 ]
16 );
17  
18  
19 sub _init
20 {
21 295 ▶ my $self = shift;
Subroutine _init: called CC=1 SCAR=0.0
22 295 my $args = shift;
23  
24 295 $self->SUPER::_init($args);
25  
26 # Make a fresh copy just to be on the safe side.
27 295 $self->_ul_classes( [ @{ $args->{'ul_classes'} } ] );
28  
29 295 return 0;
30 }
31  
32 sub _calc_li_id_attr
33 {
34 212 ▶ my $self = shift;
Subroutine _calc_li_id_attr: called CC=2 SCAR=6.9
35  
36 212 my $li_id = $self->top()->_li_id;
37  
38 return (
39 212 ▶ defined($li_id)
Branch: 1 branch
BranchTrueFalseTotal
defined $li_id ? : 6 206 212
40 ? qq/ id="/ . escape_html($li_id) . qq/"/
41 : q//
42 );
43 }
44  
45  
46 # Depth is 1 for the uppermost depth.
47 sub gen_ul_tag
48 {
49 94 ▶ my ( $self, $args ) = @_;
Subroutine gen_ul_tag: called CC=2 SCAR=6.9
Pod documented
50  
51 94 my $depth = $args->{'depth'};
52  
53 94 my $class = $self->_get_ul_class( { 'depth' => $depth } );
54  
55 94 ▶ return "<ul"
Branch: 1 branch
BranchTrueFalseTotal
defined $class ? : 65 29 94
56 . (
57 defined($class)
58 ? ( " class=\"" . escape_html($class) . "\"" )
59 : ""
60 ) . ">";
61 }
62  
63 sub _get_ul_class
64 {
65 94 ▶ my ( $self, $args ) = @_;
Subroutine _get_ul_class: called CC=1 SCAR=0.0
66  
67 94 my $depth = $args->{'depth'};
68  
69 94 return $self->_ul_classes->[ $depth - 1 ];
70 }
71  
72  
73 sub get_currently_active_text
74 {
75 24 ▶ my $self = shift;
Subroutine get_currently_active_text: called CC=1 SCAR=0.0
Pod documented
76 24 my $node = shift;
77 24 return "<b>" . $node->text() . "</b>";
78 }
79  
80  
81 sub get_link_tag
82 {
83 216 ▶ my $self = shift;
Subroutine get_link_tag: called CC=2 SCAR=6.9
Pod documented
84 216 my $node = $self->top->_node();
85 216 ▶ if ( $node->CurrentlyActive() )
Branch: 1 branch
BranchTrueFalseTotal
if ($node->CurrentlyActive) { } 25 191 216
86 {
87 25 return $self->get_currently_active_text($node);
88 }
89 else
90 {
91 191 return $self->get_a_tag();
92 }
93 }
94  
95 sub _start_root
96 {
97 44 ▶ my $self = shift;
Subroutine _start_root: called CC=1 SCAR=0.0
98  
99 44 $self->_add_tags(
100 $self->gen_ul_tag(
101 {
102 'depth' => $self->stack->len()
103 }
104 )
105 );
106 }
107  
108 sub _start_sep
109 {
110 2 ▶ my $self = shift;
Subroutine _start_sep: called CC=1 SCAR=0.0
111  
112 2 $self->_add_tags("</ul>");
113 }
114  
115 sub _start_handle_role
116 {
117 3 ▶ my $self = shift;
Subroutine _start_handle_role: called CC=1 SCAR=0.0
118 3 return $self->_start_handle_non_role();
119 }
120  
121  
122 sub get_open_sub_menu_tags
123 {
124 42 ▶ my $self = shift;
Subroutine get_open_sub_menu_tags: called CC=1 SCAR=0.0
Pod documented
125 42 return ( "<br />",
126 $self->gen_ul_tag( { 'depth' => $self->stack->len() } ) );
127 }
128  
129 sub _start_handle_non_role
130 {
131 195 ▶ my $self = shift;
Subroutine _start_handle_non_role: called CC=3 SCAR=11.0
132 195 my $top_item = $self->top;
133 195 my @tags_to_add =
134 ( ( "<li" . $self->_calc_li_id_attr() . ">" ), $self->get_link_tag() );
135 195 ▶ if ( $top_item->_num_subs_to_go() && $self->_is_expanded() )
Branch: 1 branch
BranchTrueFalseTotal
if ($top_item->_num_subs_to_go and $self->_is_expanded) 41 154 195
Condition100%3/3
$top_item->_num_subs_to_go and $self->_is_expanded
!ll&&!rl&&r
1391541
MC/DC100%2/2
$top_item->_num_subs_to_go and $self->_is_expanded
$top_item->_num_subs_to_go $self->_is_expanded
Truth table100%3/3
A and B
A= $top_item->_num_subs_to_goB= $self->_is_expanded
ABresult
0X0
100
111
136 {
137 41 push @tags_to_add, ( $self->get_open_sub_menu_tags() );
138 }
139 195 $self->_add_tags(@tags_to_add);
140 }
141  
142 sub _start_regular
143 {
144 220 ▶ my $self = shift;
Subroutine _start_regular: called CC=3 SCAR=11.0
145  
146 220 my $top_item = $self->top;
147 220 my $node = $self->top->_node();
148  
149 220 ▶ if ( $self->_is_hidden() )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_hidden) { } 4 216 220
150 {
151 # Do nothing
152 }
153 else
154 {
155 216 ▶ if ( $self->_is_role_specified() )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_role_specified) { } 7 209 216
156 {
157 7 $self->_start_handle_role();
158 }
159 else
160 {
161 209 $self->_start_handle_non_role();
162 }
163 }
164 }
165  
166 sub _end_sep
167 {
168 2 ▶ my $self = shift;
Subroutine _end_sep: called CC=1 SCAR=0.0
169  
170 2 $self->_add_tags(
171 $self->gen_ul_tag(
172 {
173 'depth' => $self->stack->len() - 1
174 }
175 )
176 );
177 }
178  
179 sub _end_handle_role
180 {
181 3 ▶ my $self = shift;
Subroutine _end_handle_role: called CC=1 SCAR=0.0
182 3 return $self->_end_handle_non_role();
183 }
184  
185 sub _end_handle_non_role
186 {
187 212 ▶ my $self = shift;
Subroutine _end_handle_non_role: called CC=1 SCAR=0.0
188 212 return $self->SUPER::_end_regular();
189 }
190  
191 sub _end_regular
192 {
193 220 ▶ my $self = shift;
Subroutine _end_regular: called CC=3 SCAR=11.0
194 220 ▶ if ( $self->_is_hidden() )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_hidden) { } 4 216 220
elsif ($self->_is_role_specified) { } 7 209 216
195 {
196 # Do nothing
197 }
198 elsif ( $self->_is_role_specified() )
199 {
200 7 $self->_end_handle_role();
201 }
202 else
203 {
204 209 $self->_end_handle_non_role();
205 }
206 }
207  
208 sub _is_hidden
209 {
210 440 ▶ my $self = shift;
Subroutine _is_hidden: called CC=1 SCAR=0.0
211 440 return $self->top->_node()->hide();
212 }
213  
214 sub _is_expanded
215 {
216 559 ▶ my $self = shift;
Subroutine _is_expanded: called CC=2 SCAR=6.9
217 559 my $node = $self->top->_node();
218 559 ▶ return ( $node->expanded() || $self->top->_accum_state->{'show_always'} );
Condition100%3/3
$node->expanded || $self->top->_accum_state->{'show_always'}
l!l&&r!l&&!r
31598146
MC/DC100%2/2
$node->expanded || $self->top->_accum_state->{'show_always'}
$node->expanded $self->top->_accum_state->{'show_always'}
Truth table100%3/3
A || B
A= $node->expandedB= $self->top->_accum_state->{'show_always'}
ABresult
1X1
011
000
219 }
220  
221  
222 sub get_role
223 {
224 446 ▶ my $self = shift;
Subroutine get_role: called CC=1 SCAR=0.0
Pod documented
225 446 return $self->top->_node->role();
226 }
227  
228 sub _is_role_specified
229 {
230 432 ▶ my $self = shift;
Subroutine _is_role_specified: called CC=1 SCAR=0.0
231 432 return defined( $self->get_role() );
232 }
233  
234 17 1;
235  
236 __END__
« blib/lib/HTML/Widgets/NavMenu/Predicate.pm ↑ Summary blib/lib/HTML/Widgets/NavMenu/Tree/Node.pm »