ZofCMS/Plugin/BreadCrumbs.pm

filter: Statementstmt 22.2% 14 / 63 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 44.4% 4 / 9 Podpod 0.0% 0 / 2 totaltotal 15.9% 18 / 113 CC 19 SCAR 44.0
CC
19
Cov
14%
process
110.0
_parse_crumb
110.0
new
2.0
CRAP 81.9
« ZofCMS/Plugin/FormFiller.pm ↑ Summary ZofCMS/Plugin/GooglePageRank.pm »
1 package App::ZofCMS::Plugin::BreadCrumbs;
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 1 ▶use File::Spec::Functions (qw/catfile splitdir/);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub new { bless {}, shift }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
12  
13 0 ▶sub process {
Subroutine process: not called CC=10 SCAR=47.0
Pod undocumented
14 0 my ( $self, $template, $query, $config ) = @_;
15  
16 0 my $bread_conf = delete $template->{breadcrumbs};
17 $bread_conf = delete $config->conf->{breadcrumbs}
18 0 ▶ unless defined $bread_conf;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bread_conf 0 0 0
19  
20 return
21 0 ▶ if ref $bread_conf eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
if ref $bread_conf eq "HASH" and not keys %$bread_conf 0 0 0
Condition0%0/3
ref $bread_conf eq "HASH" and not keys %$bread_conf
!ll&&!rl&&r
000
MC/DC0%0/2
ref $bread_conf eq "HASH" and not keys %$bread_conf
ref $bread_conf eq "HASH" not keys %$bread_conf
Truth table0%0/3
A and not(B)
A= ref $bread_conf eq "HASH"B= not keys %$bread_conf
ABresult
0X0
100
111
22 and not keys %$bread_conf;
23  
24 %$bread_conf = (
25 key => 'title',
26  
27 0 ▶ %{ $bread_conf || {} },
Condition0%0/2
$bread_conf || {}
l!l
00
MC/DC0%0/1
$bread_conf || {}
$bread_conf
Truth table0%0/2
A
A= $bread_conf
Aresult
11
00
28 );
29  
30 0 my @crumbs;
31 0 my $templates_dir = $config->conf->{templates};
32 0 my @dirs = splitdir $query->{dir};
33  
34 pop @dirs
35 0 ▶ if $dirs[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $dirs[-1] eq "" 0 0 0
36  
37 0 for ( 0 .. $#dirs ) {
38 0 push @crumbs, [
39 catfile( $templates_dir, @dirs[0..$_], 'index.tmpl' ),
40 catfile( @dirs[0..$_], 'index' ),
41 ];
42 }
43 0 ▶ unless ( $query->{page} eq 'index' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($query->{"page"} eq "index") 0 0 0
44 push @crumbs, [
45 catfile( $templates_dir, $query->{dir}, $query->{page} . '.tmpl' ),
46 0 catfile( @$query{ qw/dir page/ } ),
47 ];
48 }
49  
50 0 my %no_crumb_pages = map { $_ => 1 }
51 0 ▶ @{ $bread_conf->{no_pages} || [] };
Condition0%0/2
$bread_conf->{'no_pages'} || []
l!l
00
MC/DC0%0/1
$bread_conf->{'no_pages'} || []
$bread_conf->{'no_pages'}
Truth table0%0/2
A
A= $bread_conf->{'no_pages'}
Aresult
11
00
52  
53 @crumbs = map $self->_parse_crumb( $bread_conf, $_ ),
54 0 grep { not exists $no_crumb_pages{ $_->[1] } }
55 @crumbs;
56  
57 0 my $last_crumb = pop @crumbs;
58  
59 my $html_template = HTML::Template->new_scalar_ref(
60 $bread_conf->{span}
61 0 ▶ ? \ $self->_span_template
Branch: 1 branch
BranchTrueFalseTotal
$bread_conf->{'span'} ? : 0 0 0
62 : \ $self->_list_template
63 );
64  
65 $html_template->param(
66 crumbs => \@crumbs,
67 last_text => $last_crumb->{text},
68 0 );
69 0 $template->{t}{breadcrumbs} = $html_template->output;
70 0 return 1;
71 }
72  
73 0 ▶sub _parse_crumb {
Subroutine _parse_crumb: not called CC=10 SCAR=47.0
74 0 my ( $self, $bread_conf ) = splice @_, 0, 2;
75 0 my ( $file, $link ) = @{ $_[0] };
76  
77 0 ▶ my $template = do $file
Branch: 1 branch
BranchTrueFalseTotal
my $template = do $file or return () 0 0 0
78 or return ();
79  
80 0 my $link_text = $template->{ $bread_conf->{key} };
81  
82 0 ▶ $link_text = ''
Branch: 1 branch
BranchTrueFalseTotal
unless defined $link_text 0 0 0
83 unless defined $link_text;
84  
85 0 ▶ if ( $bread_conf->{text_re} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bread_conf->{"text_re"}) 0 0 0
86 0 ( $link_text ) = $link_text =~ /$bread_conf->{text_re}/;
87 }
88  
89 0 ▶ if ( $bread_conf->{change} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bread_conf->{"change"}) 0 0 0
90 0 keys %{ $bread_conf->{change} };
91 0 ▶ while ( my ( $re, $text ) = each %{ $bread_conf->{change} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$bread_conf{"change"};}) 0 0 0
92 0 ▶ if ( $link_text =~ /$re/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($link_text =~ /$re/) 0 0 0
93 0 $link_text = $text;
94 }
95 }
96 }
97  
98 0 ▶ if ( $bread_conf->{replace} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bread_conf->{"replace"}) 0 0 0
99 0 keys %{ $bread_conf->{replace} };
100 0 ▶ while ( my ( $re, $sub ) = each %{ $bread_conf->{replace} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$bread_conf{"replace"};}) 0 0 0
101 0 $link_text =~ s/$re/$sub/g;
102 }
103 }
104  
105 return {
106 0 ▶ link => $bread_conf->{direct} ? $link : "/index.pl?page=$link",
Branch: 1 branch
BranchTrueFalseTotal
$bread_conf->{'direct'} ? : 0 0 0
107 text => $link_text,
108 };
109 }
110  
111 0 ▶sub _span_template {
Subroutine _span_template: not called CC=1 SCAR=6.9
112 0 return <<'END_TEMPLATE';
113 <span class="breadcrumbs">[<tmpl_loop name="crumbs"><a href="<tmpl_var name="link">"><tmpl_var name="text"></a></tmpl_loop><span class="last_brumb"><tmpl_var name="last_text"></span>]</span>
114 END_TEMPLATE
115 }
116  
117 0 ▶sub _list_template {
Subroutine _list_template: not called CC=1 SCAR=6.9
118 0 return <<'END_TEMPLATE';
119 <ul class="breadcrumbs"><tmpl_loop name="crumbs">
120 <li><a href="<tmpl_var name="link">"><tmpl_var name="text"></a></li></tmpl_loop>
121 <li class="last_crumb"><tmpl_var name="last_text"></li>
122 </ul>
123 END_TEMPLATE
124 }
125  
126 1 1;
127 __END__
« ZofCMS/Plugin/FormFiller.pm ↑ Summary ZofCMS/Plugin/GooglePageRank.pm »