Jifty/Web/Menu.pm

filter: Statementstmt 8.1% 17 / 210 Branchbran 0.0% 0 / 98 Conditioncond 0.0% 0 / 58 MC/DCmcdc 0.0% 0 / 32 Subroutinesub 20.8% 5 / 24 Podpod 100% 17 / 17 totaltotal 8.8% 39 / 439 CC 79 SCAR 54.7
CC
79
Cov
5%
_render_as_yui_menu_item
756.0
child
182.0
render_submenu
56.0
CRAP 237.7
« Jifty/Action/Record/Search.pm ↑ Summary Jifty/Request.pm »
1 package Jifty::Web::Menu;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 1 ▶use base qw/Class::Accessor::Fast/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 __PACKAGE__->mk_accessors(qw(
12 label sort_order link target escape_label class render_children_inline
13 raw_html
14 ));
15  
16 =head1 NAME
17  
18 Jifty::Web::Menu - Handle the API for menu navigation
19  
20 =head1 METHODS
21  
22 =head2 new PARAMHASH
23  
24 Creates a new L<Jifty::Web::Menu> object. Possible keys in the
25 I<PARAMHASH> are L</label>, L</parent>, L</sort_order>, L</url>, and
26 L</active>. See the subroutines with the respective name below for
27 each option's use.
28  
29 =cut
30  
31 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
32 0 my $package = shift;
33 0 ▶ my $args = ref($_[0]) eq 'HASH' ? shift @_ : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
34  
35 0 my $parent = delete $args->{'parent'};
36 0 ▶ $args->{sort_order} ||= 0;
Condition0%0/2
$args->{"sort_order"} ||= 0
l!l
00
MC/DC0%0/1
$args->{"sort_order"} ||= 0
$args->{"sort_order"}
Truth table0%0/2
A
A= $args->{"sort_order"}
Aresult
11
00
37  
38 # Class::Accessor only wants a hashref;
39 0 my $self = $package->SUPER::new( $args );
40  
41 # make sure our reference is weak
42 0 ▶ $self->parent($parent) if defined $parent;
Branch: 1 branch
BranchTrueFalseTotal
if defined $parent 0 0 0
43  
44 0 return $self;
45 }
46  
47  
48 =head2 label [STRING]
49  
50 Sets or returns the string that the menu item will be displayed as.
51  
52 =cut
53  
54 =head2 parent [MENU]
55  
56 Gets or sets the parent L<Jifty::Web::Menu> of this item; this defaults
57 to null. This ensures that the reference is weakened.
58  
59 =head2 raw_html [STRING]
60  
61 Sets the content of this menu item to a raw blob of HTML. When
62 asked or output, rather than constructing a link, Jifty will return
63 this raw content. No escaping is done.
64  
65 =cut
66  
67 0 ▶sub parent {
Subroutine parent: not called CC=2 SCAR=17.9
Pod documented
68 0 my $self = shift;
69 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
70 0 $self->{parent} = shift;
71 0 weaken $self->{parent};
72 }
73  
74 0 return $self->{parent};
75 }
76  
77  
78 =head2 sort_order [NUMBER]
79  
80 Gets or sets the sort order of the item, as it will be displayed under
81 the parent. This defaults to adding onto the end.
82  
83 =head2 link
84  
85 Gets or set a L<Jifty::Web::Form::Link> object that represents this
86 menu item. If you're looking to do complex ajaxy things with menus,
87 this is likely the option you want.
88  
89 =head2 target [STRING]
90  
91 Get or set the frame or pseudo-target for this link. something like L<_blank>
92  
93 =cut
94  
95 =head2 class [STRING]
96  
97 Gets or sets the CSS class the link should have in addition to the default
98 classes. This is only used if L</link> isn't specified.
99  
100 =head2 render_children_inline [BOOLEAN]
101  
102 Gets or sets whether children are rendered inline as a menu "group" instead
103 of a true submenu. Only used when rendering with YUI for now.
104 Defaults to false.
105  
106 Note that YUI doesn't support rendering nested menu groups, so having direct
107 parent/children render_children_inline is likely not going to do what you
108 want or expect.
109  
110 =head2 url
111  
112 Gets or sets the URL that the menu's link goes to. If the link
113 provided is not absolute (does not start with a "/"), then is is
114 treated as relative to it's parent's url, and made absolute.
115  
116 =cut
117  
118 0 ▶sub url {
Subroutine url: not called CC=6 SCAR=37.4
Pod documented
119 0 my $self = shift;
120 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
121 0 $self->{url} = shift;
122 $self->{url} = URI->new_abs($self->{url}, $self->parent->url . "/")->as_string
123 0 ▶ if defined $self->{url} and $self->parent and $self->parent->url;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"url"} and $self->parent and $self->parent->url 0 0 0
Condition0%0/6
defined $self->{"url"} and $self->parent and $self->parent->url
!ll&&!rl&&r
000
defined $self->{"url"} and $self->parent
!ll&&!rl&&r
000
MC/DC0%0/3
defined $self->{"url"} and $self->parent and $self->parent->url
defined $self->{"url"} $self->parent $self->parent->url
Truth table0%0/4
A and B and C
A= defined $self->{"url"}B= $self->parentC= $self->parent->url
ABCresult
0XX0
10X0
1100
1111
124 0 ▶ $self->{url} =~ s!///!/! if $self->{url};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"url"} 0 0 0
125 }
126 0 return $self->{url};
127 }
128  
129 =head2 active [BOOLEAN]
130  
131 Gets or sets if the menu item is marked as active. Setting this
132 cascades to all of the parents of the menu item.
133  
134 =cut
135  
136 0 ▶sub active {
Subroutine active: not called CC=3 SCAR=24.8
Pod documented
137 0 my $self = shift;
138 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
139 0 $self->{active} = shift;
140 0 ▶ $self->parent->active($self->{active}) if defined $self->parent;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->parent 0 0 0
141 }
142 0 return $self->{active};
143 }
144  
145 =head2 child KEY [, PARAMHASH]
146  
147 If only a I<KEY> is provided, returns the child with that I<KEY>.
148  
149 Otherwise, creates or overwrites the child with that key, passing the
150 I<PARAMHASH> to L<Jifty::Web::Menu/new>. Additionally, the paramhash's
151 L</label> defaults to the I<KEY>, and the L</sort_order> defaults to the
152 pre-existing child's sort order (if a C<KEY> is being over-written) or
153 the end of the list, if it is a new C<KEY>.
154  
155 If the paramhash contains a key called C<menu>, that will be used instead
156 of creating a new Jifty::Web::Menu.
157  
158  
159 =cut
160  
161 0 ▶sub child {
Subroutine child: not called CC=13 SCAR=52.0
Pod documented
162 0 my $self = shift;
163 0 my $key = shift;
164 0 ▶ my $proto = ref $self || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
165  
166 0 ▶ if ( my %args = @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(%args) = ) 0 0 0
167  
168 # Clear children ordering cache
169 0 delete $self->{children_list};
170  
171 0 my $child;
172 0 ▶ if ( $child = $args{menu} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($child = $args{'menu'}) { } 0 0 0
173 0 $child->parent($self);
174 } else {
175 0 $child = $proto->new(
176 { parent => $self,
177 label => $key,
178 escape_label => 1,
179 %args
180 }
181 );
182 }
183 0 $self->{children}{$key} = $child;
184  
185 0 ▶ $child->sort_order( $args{sort_order} || (scalar values %{ $self->{children} }) )
Branch: 1 branch
BranchTrueFalseTotal
unless $child->sort_order 0 0 0
Condition0%0/2
$args{'sort_order'} || scalar values %{$$self{'children'};}
l!l
00
MC/DC0%0/1
$args{'sort_order'} || scalar values %{$$self{'children'};}
$args{'sort_order'}
Truth table0%0/2
A
A= $args{'sort_order'}
Aresult
11
00
186 unless ($child->sort_order());
187  
188 # URL is relative to parents, and cached, so set it up now
189 0 $child->url( $child->{url} );
190  
191 # Figure out the URL
192 0 ▶ my $url
Branch: 1 branch
BranchTrueFalseTotal
defined $child->link && ref $child->link && $child->link->can('url') ? : 0 0 0
Condition0%0/6
defined $child->link and ref $child->link and $child->link->can("url")
!ll&&!rl&&r
000
defined $child->link and ref $child->link
!ll&&!rl&&r
000
MC/DC0%0/3
defined $child->link and ref $child->link and $child->link->can("url")
defined $child->link ref $child->link $child->link->can("url")
Truth table0%0/4
A and B and C
A= defined $child->linkB= ref $child->linkC= $child->link->can("url")
ABCresult
0XX0
10X0
1100
1111
193 = ( defined $child->link
194 and ref $child->link
195 and $child->link->can('url') )
196 ? $child->link->url
197 : $child->url;
198  
199 # Activate it
200 0 ▶ if ( defined $url and length $url and Jifty->web->request ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $url and length $url and "Jifty"->web->request) 0 0 0
Condition0%0/6
defined $url and length $url and "Jifty"->web->request
!ll&&!rl&&r
000
defined $url and length $url
!ll&&!rl&&r
000
MC/DC0%0/3
defined $url and length $url and "Jifty"->web->request
defined $url length $url "Jifty"->web->request
Truth table0%0/4
A and B and C
A= defined $urlB= length $urlC= "Jifty"->web->request
ABCresult
0XX0
10X0
1100
1111
201  
202 # XXX TODO cleanup for mod_perl
203 0 my $base_path = Jifty->web->request->path;
204 0 chomp($base_path);
205  
206 0 $base_path =~ s/index\.html$//;
207 0 $base_path =~ s/\/+$//;
208 0 $url =~ s/\/+$//;
209  
210 0 ▶ if ( $url eq $base_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url eq $base_path) 0 0 0
211 0 $self->{children}{$key}->active(1);
212 }
213 }
214 }
215  
216 0 return $self->{children}{$key};
217 }
218  
219 =head2 active_child
220  
221 Returns the first active child node, or C<undef> is there is none.
222  
223 =cut
224  
225 0 ▶sub active_child {
Subroutine active_child: not called CC=3 SCAR=24.8
Pod documented
226 0 my $self = shift;
227 0 foreach my $kid ($self->children) {
228 0 ▶ return $kid if $kid->active;
Branch: 1 branch
BranchTrueFalseTotal
if $kid->active 0 0 0
229 }
230 0 return undef;
231 }
232  
233  
234 =head2 delete KEY
235  
236 Removes the child with the provided I<KEY>.
237  
238 =cut
239  
240 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
241 0 my $self = shift;
242 0 my $key = shift;
243 0 delete $self->{children_list};
244 0 delete $self->{children}{$key};
245 }
246  
247 =head2 empty
248  
249 Removes all children of this menu.
250  
251 =cut
252  
253 0 ▶sub empty {
Subroutine empty: not called CC=1 SCAR=6.9
Pod documented
254 0 my $self = shift;
255 0 delete $self->{children_list};
256 0 delete $self->{children};
257 }
258  
259 =head2 children
260  
261 Returns the children of this menu item in sorted order; as an array in
262 array context, or as an array reference in scalar context.
263  
264 =cut
265  
266 0 ▶sub children {
Subroutine children: not called CC=4 SCAR=30.0
Pod documented
267 0 my $self = shift;
268 0 my @kids;
269 0 ▶ if ($self->{children_list}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'children_list'}) { } 0 0 0
270 0 @kids = @{$self->{children_list}};
271 } else {
272 0 ▶ @kids = values %{$self->{children} || {}};
Condition0%0/2
$self->{'children'} || {}
l!l
00
MC/DC0%0/1
$self->{'children'} || {}
$self->{'children'}
Truth table0%0/2
A
A= $self->{'children'}
Aresult
11
00
273 0 @kids = sort {$a->{sort_order} <=> $b->{sort_order}} @kids;
274 0 $self->{children_list} = \@kids;
275 }
276 0 ▶ return wantarray ? @kids : \@kids;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
277 }
278  
279 =head2 render_as_menu
280  
281 Render this menu with HTML markup as multiple dropdowns, suitable for
282 an application's menu
283  
284 Any arguments are passed to L<render_as_hierarchical_menu_item>.
285  
286 =cut
287  
288 0 ▶sub render_as_menu {
Subroutine render_as_menu: not called CC=2 SCAR=17.9
Pod documented
289 0 my $self = shift;
290 0 my @kids = $self->children;
291 0 Jifty->web->out(qq{<ul class="menu">});
292  
293 0 for (@kids) {
294 0 $_->render_as_hierarchical_menu_item(@_);
295 }
296 0 Jifty->web->out(qq{</ul>});
297 0 '';
298 }
299  
300 =head2 render_as_context_menu
301  
302 Render this menu with html markup as an inline dropdown menu.
303  
304 =cut
305  
306 0 ▶sub render_as_context_menu {
Subroutine render_as_context_menu: not called CC=1 SCAR=6.9
Pod documented
307 0 my $self = shift;
308 0 Jifty->web->out( qq{<ul class="context_menu">});
309 0 $self->render_as_hierarchical_menu_item();
310 0 Jifty->web->out(qq{</ul>});
311 0 '';
312 }
313  
314 =head2 render_as_hierarchical_menu_item
315  
316 Render an <li> for this item. suitable for use in a regular or contextual
317 menu. Currently renders one level of submenu, if it exists, using
318 L</render_submenu>.
319  
320 If you pass C<expand => 0>, the javascript expansion C<span> won't be output.
321  
322 Any arguments are passed to L<render_submenu>.
323  
324 =cut
325  
326 0 ▶sub render_as_hierarchical_menu_item {
Subroutine render_as_hierarchical_menu_item: not called CC=5 SCAR=34.0
Pod documented
327 0 my $self = shift;
328 0 my %args = (
329 expand => 1,
330 @_
331 );
332 0 my @kids = $self->children;
333 0 my $web = Jifty->web;
334 0 ▶ $web->out( qq{<li class="toplevel }
Branch: 1 branch
BranchTrueFalseTotal
$self->active ? : 0 0 0
Condition0%0/2
$self->class || ''
l!l
00
MC/DC0%0/1
$self->class || ''
$self->class
Truth table0%0/2
A
A= $self->class
Aresult
11
00
335 . ( $self->active ? 'active' : 'closed' ) .' '.($self->class||"").' '. qq{">}
336 . qq{<span class="title">} );
337 0 $web->out( $self->as_link );
338 0 $web->out(qq{</span>});
339 0 ▶ if (@kids) {
Branch: 1 branch
BranchTrueFalseTotal
if (@kids) 0 0 0
340 0 my $id = $web->serial;
341 $web->out(
342 qq{<span class="expand"><a href="#" onclick="Jifty.ContextMenu.hideshow('}
343 . $id
344 . qq{'); return false;">&nbsp;</a></span>} )
345 0 ▶ if delete $args{'expand'};
Branch: 1 branch
BranchTrueFalseTotal
if delete $args{"expand"} 0 0 0
346 0 $self->render_submenu( %args, id => $id );
347 }
348 0 $web->out(qq{</li>});
349 0 '';
350  
351 }
352  
353 =head2 render_submenu
354  
355 Renders a <ul> for the children (but not descendants) of this menu object,
356 suitable for use as part of a regular or contextual menu. Called by
357 L</render_as_hierarchical_menu_item>. You probably don't need to use this
358 on it's own.
359  
360 If passed C<deep_active => 1>, then it renders active descendants recursively
361 all the way down.
362  
363 =cut
364  
365 0 ▶sub render_submenu {
Subroutine render_submenu: not called CC=7 SCAR=40.3
Pod documented
366 0 my $self = shift;
367 0 my %args = (
368 id => '',
369 deep_active => 0,
370 @_
371 );
372  
373 0 my $web = Jifty->web;
374 0 $web->out(qq(<ul id="$args{id}" class="submenu">));
375 0 for ($self->children) {
376 0 ▶ $web->out(qq{<li class="submenu }.($_->active ? 'active' : '' ).' '. ($_->class || "").qq{">});
Branch: 1 branch
BranchTrueFalseTotal
$_->active ? : 0 0 0
Condition0%0/2
$_->class || ''
l!l
00
MC/DC0%0/1
$_->class || ''
$_->class
Truth table0%0/2
A
A= $_->class
Aresult
11
00
377  
378 # We should be able to get this as a string.
379 # Either stringify the link object or output the label
380 # This is really icky. XXX TODO
381 0 $web->out( $_->as_link );
382
383 0 my @kids = $_->children;
384 0 ▶ if ($args{'deep_active'} and $_->active and @kids) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"deep_active"} and $_->active and @kids) 0 0 0
Condition0%0/6
$args{"deep_active"} and $_->active and @kids
!ll&&!rl&&r
000
$args{"deep_active"} and $_->active
!ll&&!rl&&r
000
MC/DC0%0/3
$args{"deep_active"} and $_->active and @kids
$args{"deep_active"} $_->active @kids
Truth table0%0/4
A and B and C
A= $args{"deep_active"}B= $_->activeC= @kids
ABCresult
0XX0
10X0
1100
1111
385 0 $_->render_submenu( %args, id => $web->serial );
386 }
387  
388 0 $web->out("</li>");
389 }
390 0 $web->out(qq{</ul>});
391 }
392  
393 =head2 render_as_classical_menu
394  
395 Render this menu with html markup as old classical mason menu.
396 Currently renders one level of submenu, if it exists.
397  
398 =cut
399  
400 0 ▶sub render_as_classical_menu {
Subroutine render_as_classical_menu: not called CC=2 SCAR=17.9
Pod documented
401 0 my $self = shift;
402 0 my @kids = $self->children;
403  
404 0 Jifty->web->out( qq{<ul class="menu">});
405  
406 0 for (@kids) {
407 0 $_->_render_as_classical_menu_item();
408 }
409  
410 0 Jifty->web->out(qq{</ul>});
411 0 '';
412 }
413  
414 0 ▶sub _render_as_classical_menu_item {
Subroutine _render_as_classical_menu_item: not called CC=5 SCAR=34.0
415 0 my $self = shift;
416 0 my %args = (
417 class => '',
418 @_
419 );
420 0 my @kids = $self->children;
421 0 ▶ Jifty->web->out( qq{<li} . ($self->active ? qq{ class="active"} : '' ) . qq{>} );
Branch: 1 branch
BranchTrueFalseTotal
$self->active ? : 0 0 0
422 0 Jifty->web->out( $self->as_link );
423 0 ▶ if (@kids) {
Branch: 1 branch
BranchTrueFalseTotal
if (@kids) 0 0 0
424 0 Jifty->web->out( qq{<ul class="submenu">} );
425 0 for (@kids) {
426 0 ▶ Jifty->web->out( qq{<li} . ($_->active ? qq{ class="active"} : '' ) . qq{>} );
Branch: 1 branch
BranchTrueFalseTotal
$_->active ? : 0 0 0
427 0 Jifty->web->out( $_->as_link );
428 0 Jifty->web->out("</li>");
429 }
430 0 Jifty->web->out(qq{</ul>});
431 }
432 0 Jifty->web->out(qq{</li>});
433 0 '';
434  
435 }
436  
437 =head2 render_as_yui_menu [PARAMHASH]
438  
439 Render menu with YUI menu. It can support arbitrary levels of submenus.
440  
441 Valid options for the paramhash are as follows:
442  
443 =over
444  
445 =item id
446  
447 The HTML element ID to use for the menu
448  
449 =item show
450  
451 A boolean indicating whether to show the menu after rendering the HTML.
452 Defaults to true. If you don't set this to true, you should use the
453 button option (see below) or show the menu with Javascript like:
454  
455 YAHOO.widget.MenuManager.getMenu("menu-html-id").show();
456  
457 =item button
458  
459 The ID of an HTML element. The element's onclick Javascript event is bound
460 to a function which shows the menu.
461  
462 =item options
463  
464 A hashref of options passed directly to the Javascript constructor for
465 the menu. See L<http://developer.yahoo.com/yui/menu/#configreference> for
466 a list of the options available.
467  
468 =item beforeshow
469  
470 A string of Javascript to run immediately before the menu is shown. The
471 variable C<menu> is available and represents the current YUI Menu object.
472  
473 =back
474  
475 =cut
476  
477 0 ▶sub render_as_yui_menu {
Subroutine render_as_yui_menu: not called CC=4 SCAR=30.0
Pod documented
478 0 my $self = shift;
479 0 my %args = (
480 id => Jifty->web->serial,
481 show => 1,
482 options => {},
483 beforeshow => '',
484 @_
485 );
486  
487 0 ▶ my $showjs = $args{'show'} ? "menu.show();" : "";
Branch: 1 branch
BranchTrueFalseTotal
$args{'show'} ? : 0 0 0
488 0 my $json = Jifty::JSON::encode_json( $args{'options'} );
489  
490 # Bind to a button to show the menu
491 0 ▶ my $binding = (defined $args{'button'} and length $args{'button'}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'button'} && length $args{'button'} ? : 0 0 0
Condition0%0/3
defined $args{"button"} and length $args{"button"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{"button"} and length $args{"button"}
defined $args{"button"} length $args{"button"}
Truth table0%0/3
A and B
A= defined $args{"button"}B= length $args{"button"}
ABresult
0X0
100
111
492  
493 0 $self->_render_as_yui_menu_item( class => "yuimenu", id => $args{'id'} );
494  
495 0 Jifty->web->out(<<" END");
496 <script type="text/javascript">
497 YAHOO.util.Event.onContentReady("$args{id}", function() {
498 // set container?
499 var menu = new YAHOO.widget.Menu("$args{id}", $json);
500 menu.render();
501 menu.subscribe("show", function() {
502 if ( !this.cfg.getProperty("constraintoviewport") )
503 Jifty.Utils.scrollToShow(this.id);
504 });
505 if ( $binding ) {
506 YAHOO.util.Event.addListener("$args{button}", "click",
507 function() {
508 this.show();
509 },
510 null, menu
511 );
512 menu.subscribe("show", function() { if (!this.parent) jQuery("#$args{button}").addClass("open") });
513 menu.subscribe("hide", function() { if (!this.parent) jQuery("#$args{button}").removeClass("open") });
514 }
515 $args{beforeshow}
516 $showjs
517 });
518 </script>
519 END
520 0 '';
521 }
522  
523 =head2 render_as_yui_menubar
524  
525 Render menubar with YUI menu, suitable for an application's menu.
526 It can support arbitrary levels of submenu.
527  
528 =cut
529  
530 0 ▶sub render_as_yui_menubar {
Subroutine render_as_yui_menubar: not called CC=2 SCAR=17.9
Pod documented
531 0 my $self = shift;
532 0 ▶ my $id = shift || Jifty->web->serial;
Condition0%0/3
shift() || 'Jifty'->web->serial
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || 'Jifty'->web->serial
shift() 'Jifty'->web->serial
Truth table0%0/3
A || B
A= shift()B= 'Jifty'->web->serial
ABresult
1X1
011
000
533 0 $self->_render_as_yui_menu_item( class => "yuimenubar", id => $id );
534 0 Jifty->web->out(qq|<script type="text/javascript">\n|
535 . qq|YAHOO.util.Event.onContentReady("|.$id.qq|", function() {\n|
536 . qq|var menu = new YAHOO.widget.MenuBar("|.$id.qq|", { autosubmenudisplay:true, hidedelay:750, lazyload:true, showdelay:0 });\n|
537 . qq|menu.render();\n|
538 . qq|});</script>|
539 );
540 0 '';
541 }
542  
543 0 ▶sub _render_as_yui_menu_item {
Subroutine _render_as_yui_menu_item: not called CC=27 SCAR=66.3
544 0 my $self = shift;
545 0 my %args = ( class => 'yuimenu', first => 0, id => undef, @_ );
546 0 ▶ my @kids = $self->children or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@kids) = $self->children or return 0 0 0
547
548 # Add the appropriate YUI class to each kid
549 0 for my $kid ( @kids ) {
550 # Skip it if it's a group heading
551 0 ▶ next if $kid->render_children_inline and $kid->children;
Branch: 1 branch
BranchTrueFalseTotal
if $kid->render_children_inline and $kid->children 0 0 0
Condition0%0/3
$kid->render_children_inline and $kid->children
!ll&&!rl&&r
000
MC/DC0%0/2
$kid->render_children_inline and $kid->children
$kid->render_children_inline $kid->children
Truth table0%0/3
A and B
A= $kid->render_children_inlineB= $kid->children
ABresult
0X0
100
111
552  
553 # Figure out the correct object to be setting the class on
554 0 ▶ my $object = ( defined $kid->link
Branch: 1 branch
BranchTrueFalseTotal
defined $kid->link && ref $kid->link && $kid->link->can('class') ? : 0 0 0
Condition0%0/6
defined $kid->link and ref $kid->link and $kid->link->can("class")
!ll&&!rl&&r
000
defined $kid->link and ref $kid->link
!ll&&!rl&&r
000
MC/DC0%0/3
defined $kid->link and ref $kid->link and $kid->link->can("class")
defined $kid->link ref $kid->link $kid->link->can("class")
Truth table0%0/4
A and B and C
A= defined $kid->linkB= ref $kid->linkC= $kid->link->can("class")
ABCresult
0XX0
10X0
1100
1111
555 and ref $kid->link
556 and $kid->link->can('class') )
557 ? $kid->link : $kid;
558  
559 0 ▶ my $class = defined $object->class ? $object->class . ' ' : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $object->class ? : 0 0 0
560 0 $class .= "$args{class}itemlabel";
561 0 $object->class( $class );
562 }
563  
564 # We're rendering this inline, so just render a UL (and any submenus as normal)
565 0 ▶ if ( $self->render_children_inline ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->render_children_inline) { } 0 0 0
566 0 ▶ Jifty->web->out( $args{'first'} ? '<ul class="first-of-type">' : '<ul>' );
Branch: 1 branch
BranchTrueFalseTotal
$args{'first'} ? : 0 0 0
567 0 for my $kid ( @kids ) {
568 0 ▶ Jifty->web->out( qq(<li class="$args{class}item ) . ($kid->active? 'active' : '') . qq{">});
Branch: 1 branch
BranchTrueFalseTotal
$kid->active ? : 0 0 0
569 0 Jifty->web->out( $kid->as_link );
570 0 $kid->_render_as_yui_menu_item( class => 'yuimenu' );
571 0 Jifty->web->out( qq{</li>});
572 }
573 0 Jifty->web->out('</ul>');
574 }
575 # Render as normal submenus
576 else {
577 Jifty->web->out(
578 qq{<div}
579 0 ▶ . ($args{'id'} ? qq( id="$args{'id'}") : "")
Branch: 1 branch
BranchTrueFalseTotal
$args{'id'} ? : 0 0 0
580 0 ▶ . qq( class="$args{class}"><div class="bd" @{[($args{id} ? "id=\"$args{id}-bd\"" : "")]}>)
Branch: 1 branch
BranchTrueFalseTotal
$args{'id'} ? : 0 0 0
581 );
582  
583 0 my $count = 1;
584 0 my $count_h6 = 1;
585 0 my $openlist = 0;
586  
587 0 for my $kid ( @kids ) {
588 # We want to render the children of this child inline, so close
589 # any open <ul>s, render it as an <h6>, and then render it's
590 # children.
591 0 ▶ if ( $kid->render_children_inline and $kid->children ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kid->render_children_inline and $kid->children) { } 0 0 0
Condition0%0/3
$kid->render_children_inline and $kid->children
!ll&&!rl&&r
000
MC/DC0%0/2
$kid->render_children_inline and $kid->children
$kid->render_children_inline $kid->children
Truth table0%0/3
A and B
A= $kid->render_children_inlineB= $kid->children
ABresult
0X0
100
111
592 0 ▶ Jifty->web->out('</ul>') if $openlist;
Branch: 1 branch
BranchTrueFalseTotal
if $openlist 0 0 0
593
594 0 my @classes = ();
595 0 ▶ push @classes, 'active' if $kid->active;
Branch: 1 branch
BranchTrueFalseTotal
if $kid->active 0 0 0
596 0 ▶ push @classes, 'first-of-type'
Branch: 1 branch
BranchTrueFalseTotal
if $count_h6 == 1 and $count == 1 0 0 0
Condition0%0/3
$count_h6 == 1 and $count == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$count_h6 == 1 and $count == 1
$count_h6 == 1 $count == 1
Truth table0%0/3
A and B
A= $count_h6 == 1B= $count == 1
ABresult
0X0
100
111
597 if $count_h6 == 1 and $count == 1;
598  
599 0 Jifty->web->out(qq(<h6 class="@{[ join ' ', @classes ]}">));
600 0 Jifty->web->out( $kid->as_link );
601 0 Jifty->web->out('</h6>');
602 0 ▶ $kid->_render_as_yui_menu_item(
Branch: 1 branch
BranchTrueFalseTotal
$count == 1 ? : 0 0 0
603 class => 'yuimenu',
604 first => ($count == 1 ? 1 : 0)
605 );
606 0 $openlist = 0;
607 0 $count_h6++;
608 }
609 # It's a normal child
610 else {
611 0 ▶ if ( not $openlist ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($openlist) 0 0 0
612 0 ▶ Jifty->web->out( $count == 1 ? '<ul class="first-of-type">' : '<ul>' );
Branch: 1 branch
BranchTrueFalseTotal
$count == 1 ? : 0 0 0
613 0 $openlist = 1;
614 }
615 0 ▶ Jifty->web->out( qq(<li class="$args{class}item ) . ($kid->active? 'active' : '') . qq{">});
Branch: 1 branch
BranchTrueFalseTotal
$kid->active ? : 0 0 0
616 0 Jifty->web->out( $kid->as_link );
617 0 $kid->_render_as_yui_menu_item( class => 'yuimenu' );
618 0 Jifty->web->out( qq{</li>});
619 }
620 0 $count++;
621 }
622 0 ▶ Jifty->web->out('</ul>') if $openlist;
Branch: 1 branch
BranchTrueFalseTotal
if $openlist 0 0 0
623 0 Jifty->web->out(qq{</div></div>});
624 }
625 }
626  
627 =head2 as_link
628  
629 Return this menu item as a L<Jifty::Web::Form::Link>, either the one
630 we were initialized with or a new one made from the L</label> and L</url>
631  
632 If there's no L</url> and no L</link>, renders just the label.
633  
634 =cut
635  
636 0 ▶sub as_link {
Subroutine as_link: not called CC=5 SCAR=34.0
Pod documented
637 0 my $self = shift;
638 # Stringifying $self->link may return '' and output something, so
639 # we need to be careful to not stringify it more than once, and to
640 # check it for defined-ness, not truth.
641 0 ▶ if ( my $raw = $self->raw_html) {
Branch: 3 branches
BranchTrueFalseTotal
if (my $raw = $self->raw_html) { } 0 0 0
elsif (defined(my $str = $self->link)) { } 0 0 0
elsif ($self->url) { } 0 0 0
642 0 return $raw;
643 }
644 elsif ( defined (my $str = $self->link) ) {
645 0 return $str;
646 } elsif ( $self->url ) {
647 0 return Jifty->web->link( label => _( $self->label ),
648 url => $self->url,
649 escape_label => $self->escape_label,
650 target => $self->target,
651 class => $self->class );
652 } else {
653 0 ▶ if ( $self->class ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->class) { } 0 0 0
654 0 return "<span class=\"@{[$self->class]}\">"._( $self->label )."</span>";
655 } else {
656 0 return _( $self->label );
657 }
658 }
659 }
660  
661 1 1;
« Jifty/Action/Record/Search.pm ↑ Summary Jifty/Request.pm »