ZofCMS/Config.pm

filter: Statementstmt 66.6% 44 / 66 Branchbran 31.2% 10 / 32 Conditioncond 18.7% 3 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 81.8% 9 / 11 Podpod 60.0% 3 / 5 totaltotal 49.2% 69 / 140 CC 25 SCAR 34.8
CC
25
Cov
50%
_is_valid_page
90.0
load
30.0
_prepare_query
16.4
CRAP 32.6
« ZofCMS/Plugin/DirTreeBrowse.pm ↑ Summary ZofCMS/Plugin/UserLogin/ForgotPassword.pm »
1 package App::ZofCMS::Config;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = '1.001010'; # VERSION
7  
8 3 ▶use CGI qw/:standard Vars/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 require File::Spec;
12  
13 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
14 1 my $class = shift;
15 1 my $self = bless {}, $class;
16  
17 1 $self->cgi( CGI->new );
18 1 $self->query( $self->_prepare_query );
19  
20 1 return $self;
21 }
22  
23 0 ▶sub load {
Subroutine load: not called CC=5 SCAR=34.0
Pod undocumented
24 0 my ( $self, $conf_file, $no_page_check ) = @_;
25  
26  
27 0 ▶ my $conf = do $conf_file
Branch: 1 branch
BranchTrueFalseTotal
my $conf = do $conf_file or croak("Failed to load config file ($!) ($@)") 0 0 0
28 or croak "Failed to load config file ($!) ($@)";
29  
30 defined $conf->{zcms_template_extension}
31 0 ▶ or $conf->{zcms_template_extension} = '.tmpl';
Branch: 1 branch
BranchTrueFalseTotal
defined $conf->{"zcms_template_extension"} or $conf->{"zcms_template_extension"} = ".tmpl" 0 0 0
32  
33 0 ▶ unless ( $no_page_check ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($no_page_check) 0 0 0
34 0 my $query = $self->query;
35 0 my $is_valid_page = $self->_is_valid_page(
36 $query,
37 $conf,
38 );
39  
40 0 ▶ unless ( $is_valid_page ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_valid_page) 0 0 0
41 0 @$query{ qw/page dir/ } = qw|404 /|;
42 }
43 }
44  
45 0 return $self->conf( $conf );
46 }
47  
48 0 ▶sub _is_valid_page {
Subroutine _is_valid_page: not called CC=9 SCAR=45.0
49 0 my ( $self, $query, $conf ) = @_;
50  
51 my ( $ext, $templates_dir, $valid_pages )
52 0 = @$conf{ qw/zcms_template_extension templates valid_pages/ };
53  
54 0 ▶ unless ( ref $valid_pages eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $valid_pages eq "HASH") 0 0 0
55 0 croak "Config file error: valid_pages must be a hashref";
56 }
57  
58 0 ▶ for ( @{ $valid_pages->{pages} || [] } ) {
Condition0%0/2
$valid_pages->{'pages'} || []
l!l
00
MC/DC0%0/1
$valid_pages->{'pages'} || []
$valid_pages->{'pages'}
Truth table0%0/2
A
A= $valid_pages->{'pages'}
Aresult
11
00
59 return 1
60 0 ▶ if $_ eq $query->{dir} . $query->{page};
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $query->{"dir"} . $query->{"page"} 0 0 0
61 }
62  
63 0 ▶ for ( @{ $valid_pages->{dirs} || [] } ) {
Condition0%0/2
$valid_pages->{'dirs'} || []
l!l
00
MC/DC0%0/1
$valid_pages->{'dirs'} || []
$valid_pages->{'dirs'}
Truth table0%0/2
A
A= $valid_pages->{'dirs'}
Aresult
11
00
64 return 1
65 if $_ eq $query->{dir}
66 0 ▶ and -e File::Spec->catfile( $templates_dir, $query->{dir}, $query->{page} . $ext);
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $query->{"dir"} and -e "File::Spec"->catfile($templates_dir, $query->{"dir"}, $query->{"page"} . $ext) 0 0 0
Condition0%0/3
$_ eq $query->{"dir"} and -e "File::Spec"->catfile($templates_dir, $query->{"dir"}, $query->{"page"} . $ext)
!ll&&!rl&&r
000
MC/DC0%0/2
$_ eq $query->{"dir"} and -e "File::Spec"->catfile($templates_dir, $query->{"dir"}, $query->{"page"} . $ext)
$_ eq $query->{"dir"} -e "File::Spec"->catfile($templates_dir, $query->{"dir"}, $query->{"page"} . $ext)
Truth table0%0/3
A and B
A= $_ eq $query->{"dir"}B= -e "File::Spec"->catfile($templates_dir, $query->{"dir"}, $query->{"page"} . $ext)
ABresult
0X0
100
111
67 }
68  
69 0 return 0;
70 }
71  
72 1 ▶sub _prepare_query {
Subroutine _prepare_query: called CC=10 SCAR=28.0
73 1 my $self = shift;
74  
75 1 my %query = Vars();
76  
77 1 ▶ unless ( defined $query{page} and length $query{page} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $query{"page"} and length $query{"page"}) 1 0 1
Condition33%1/3
defined $query{"page"} and length $query{"page"}
!ll&&!rl&&r
100
MC/DC0%0/2
defined $query{"page"} and length $query{"page"}
defined $query{"page"} length $query{"page"}
Truth table33%1/3
A and B
A= defined $query{"page"}B= length $query{"page"}
ABresult
0X0
100
111
78 1 $query{page} = 'index';
79 }
80  
81 1 ▶ if ( $query{page} =~ m|/| ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($query{"page"} =~ m[/]) 0 1 1
82 0 ( $query{dir}, $query{page} ) = $query{page} =~ m|(.*/)([^/]*)$|;
83 }
84  
85 1 ▶ unless ( defined $query{page} and length $query{page} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $query{"page"} and length $query{"page"}) 0 1 1
Condition33%1/3
defined $query{"page"} and length $query{"page"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $query{"page"} and length $query{"page"}
defined $query{"page"} length $query{"page"}
Truth table33%1/3
A and B
A= defined $query{"page"}B= length $query{"page"}
ABresult
0X0
100
111
86 0 $query{page} = 'index';
87 }
88  
89 1 ▶ unless ( defined $query{dir} and length $query{dir} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $query{"dir"} and length $query{"dir"}) 1 0 1
Condition33%1/3
defined $query{"dir"} and length $query{"dir"}
!ll&&!rl&&r
100
MC/DC0%0/2
defined $query{"dir"} and length $query{"dir"}
defined $query{"dir"} length $query{"dir"}
Truth table33%1/3
A and B
A= defined $query{"dir"}B= length $query{"dir"}
ABresult
0X0
100
111
90 1 $query{dir} = '/';
91 }
92  
93 1 $query{dir} =~ s/\Q..//g;
94  
95 $query{dir} = "/$query{dir}"
96 1 ▶ unless substr($query{dir}, 0, 1) eq '/';
Branch: 1 branch
BranchTrueFalseTotal
unless substr($query{"dir"}, 0, 1) eq "/" 0 1 1
97  
98 $query{dir} .= '/'
99 1 ▶ unless substr($query{dir}, -1) eq '/';
Branch: 1 branch
BranchTrueFalseTotal
unless substr($query{"dir"}, -1) eq "/" 0 1 1
100  
101 1 return \%query;
102 }
103  
104 1 ▶sub cgi {
Subroutine cgi: called CC=2 SCAR=7.0
Pod documented
105 1 my $self = shift;
106 1 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 0 1
107 1 $self->{ cgi } = shift;
108 }
109 1 return $self->{ cgi };
110 }
111  
112  
113 1 ▶sub query {
Subroutine query: called CC=2 SCAR=7.0
Pod documented
114 1 my $self = shift;
115 1 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 0 1
116 1 $self->{ query } = shift;
117 }
118 1 return $self->{ query };
119 }
120  
121  
122 2 ▶sub conf {
Subroutine conf: called CC=2 SCAR=6.9
Pod documented
123 2 my $self = shift;
124 2 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
125 1 $self->{ conf } = shift;
126 }
127 2 return $self->{ conf };
128 }
129  
130  
131  
132 3 1;
133 __END__
« ZofCMS/Plugin/DirTreeBrowse.pm ↑ Summary ZofCMS/Plugin/UserLogin/ForgotPassword.pm »