| 1 | package App::ZofCMS::Plugin::NavMaker; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.001010'; # VERSION | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | ▶ | use HTML::Template; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 0 | ▶ | sub new { bless {}, shift } | ||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 0 | ▶ | sub process { | ||||||||||||||||||
|
Subroutine
process: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||
| 13 | 0 | my ( $self, $template, $query, $config ) = @_; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 0 | ▶ | my $nav = delete($template->{nav_maker}) || delete $config->conf->{nav_maker}; | ||||||||||||||||||
|
Condition0%0/3
delete $template->{'nav_maker'} || delete $config->conf->{'nav_maker'}
MC/DC0%0/2
delete $template->{'nav_maker'} || delete $config->conf->{'nav_maker'}
delete $template->{'nav_maker'}
delete $config->conf->{'nav_maker'}
Truth table0%0/3
A || B
A= delete $template->{'nav_maker'}B= delete $config->conf->{'nav_maker'}
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | return | ||||||||||||||||||||
| 18 | 0 | ▶ | unless $nav; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | if ( ref $nav eq 'CODE' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | 0 | $nav = $nav->( $template, $query, $config ); | |||||||||||||||||||
| 22 | } | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 0 | my $html_template | |||||||||||||||||||
| 25 | = HTML::Template->new_scalar_ref( \ $self->_get_html_template ); | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 0 | for ( @$nav ) { | |||||||||||||||||||
| 28 | 0 | ▶ | next if ref; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 0 | $_ = [ $_ ]; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | $html_template->param( | ||||||||||||||||||||
| 33 | 0 | ▶ | nav => [ | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 34 | map +{ | ||||||||||||||||||||
| 35 | text => $_->[0], | ||||||||||||||||||||
| 36 | title => (defined $_->[2] ? $_->[2] : "Visit $_->[0]"), | ||||||||||||||||||||
| 37 | href => ( | ||||||||||||||||||||
| 38 | defined $_->[1] ? $_->[1] : $self->_make_href( $_->[0] ) | ||||||||||||||||||||
| 39 | ), | ||||||||||||||||||||
| 40 | id => ( | ||||||||||||||||||||
| 41 | defined $_->[3] | ||||||||||||||||||||
| 42 | ? $_->[3] | ||||||||||||||||||||
| 43 | : $self->_make_id( $_->[0] ) | ||||||||||||||||||||
| 44 | ), | ||||||||||||||||||||
| 45 | }, @$nav | ||||||||||||||||||||
| 46 | ], | ||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | $template->{t}{nav_maker} = $html_template->output; | |||||||||||||||||||
| 50 | 0 | return 1; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | ▶ | sub _make_href { | ||||||||||||||||||
|
Subroutine
_make_href: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 54 | 0 | my ( $self, $text ) = @_; | |||||||||||||||||||
| 55 | 0 | $text =~ s/[\W_]/-/g; | |||||||||||||||||||
| 56 | 0 | return lc "/$text"; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | ▶ | sub _make_id { | ||||||||||||||||||
|
Subroutine
_make_id: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 60 | 0 | my ( $self, $text ) = @_; | |||||||||||||||||||
| 61 | 0 | $text =~ s/\W/_/g; | |||||||||||||||||||
| 62 | 0 | return lc "nav_$text"; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 0 | ▶ | sub _get_html_template { | ||||||||||||||||||
|
Subroutine
_get_html_template: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 66 | 0 | return <<'END'; | |||||||||||||||||||
| 67 | <ul id="nav"><tmpl_loop name="nav"> | ||||||||||||||||||||
| 68 | <li id="<tmpl_var escape="html" name="id">"><a href="<tmpl_var escape="html" name="href">" title="<tmpl_var escape="html" name="title">"><tmpl_var escape="html" name="text"></a></li></tmpl_loop> | ||||||||||||||||||||
| 69 | </ul> | ||||||||||||||||||||
| 70 | END | ||||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 1 | 1; | |||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||