blib/lib/ClearPress/decorator.pm

filter: Statementstmt 85.9% 98 / 114 Branchbran 71.4% 20 / 28 Conditioncond 59.2% 16 / 27 MC/DCmcdc 31.2% 5 / 16 Subroutinesub 100% 18 / 18 Podpod 100% 12 / 12 totaltotal 78.6% 169 / 215 CC 25 SCAR 23.3
CC
25
Cov
79%
site_header
24.8
get
7.0
cookie
3.3
CRAP 10.3
« blib/lib/ClearPress/authdecor.pm ↑ Summary blib/lib/ClearPress/view/error.pm »
1 # -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*-
2 # vim:ts=8:sw=2:et:sta:sts=2
3 #########
4 # Author: rmp
5 # Created: 2007-06-07
6 #
7 package ClearPress::decorator;
8 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use CGI qw(param);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use base qw(Class::Accessor);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 7 our $VERSION = q[2026.07.25];
16  
17 7 our $DEFAULTS = {
18 meta_content_type => 'text/html',
19 meta_version => '0.2',
20 meta_description => q[],
21 meta_author => q[],
22 meta_keywords => q[],
23 username => q[],
24 charset => q[iso8859-1],
25 lang => [qw(en)],
26 };
27  
28 7 Readonly::Scalar our $PROCESS_COMMA_YES => 1;
29 7 Readonly::Scalar our $PROCESS_COMMA_NO => 2;
30 7 our $ARRAY_FIELDS = {
31 'jsfile' => $PROCESS_COMMA_YES,
32 'rss' => $PROCESS_COMMA_YES,
33 'atom' => $PROCESS_COMMA_YES,
34 'stylesheet' => $PROCESS_COMMA_YES,
35 'script' => $PROCESS_COMMA_NO,
36 'lang' => $PROCESS_COMMA_YES,
37 };
38 7 __PACKAGE__->mk_accessors(__PACKAGE__->fields());
39  
40 23 ▶sub fields {
Subroutine fields: called CC=1 SCAR=0.0
Pod documented
41 23 return qw(title stylesheet style jsfile script atom rss
42 meta_keywords meta_description meta_author meta_version
43 meta_refresh meta_cookie meta_content_type meta_expires
44 onload onunload onresize username charset headers
45 lang);
46 }
47  
48 611 ▶sub get {
Subroutine get: called CC=7 SCAR=19.5
Pod documented
49 611 my ($self, $field) = @_;
50  
51 611 ▶ if($ARRAY_FIELDS->{$field}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ClearPress::decorator::ARRAY_FIELDS->{$field}) { } 187 424 611
52 187 ▶ my $val = $self->{$field} || $DEFAULTS->{$field} || [];
Condition100%5/5
$self->{$field} || $ClearPress::decorator::DEFAULTS->{$field} || []
l!l
57130
$self->{$field} or $ClearPress::decorator::DEFAULTS->{$field}
l!l&&r!l&&!r
354130
MC/DC100%2/2
$self->{$field} || $ClearPress::decorator::DEFAULTS->{$field} || []
$self->{$field} $ClearPress::decorator::DEFAULTS->{$field}
Truth table100%3/3
A or B
A= $self->{$field}B= $ClearPress::decorator::DEFAULTS->{$field}
ABresult
1X1
011
000
53 187 ▶ if(!ref $val) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $val) 4 183 187
54 4 $val = [$val];
55 }
56  
57 187 ▶ if($ARRAY_FIELDS->{$field} == $PROCESS_COMMA_YES) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ClearPress::decorator::ARRAY_FIELDS->{$field} == $ClearPress::decorator::PROCESS_COMMA_YES) { } 160 27 187
58 160 return [map { split /,/smx } @{$val}];
59  
60 } else {
61 27 return $val;
62 }
63  
64  
65 } else {
66 424 ▶ return $self->{$field} || $DEFAULTS->{$field};
Condition100%3/3
$self->{$field} || $ClearPress::decorator::DEFAULTS->{$field}
l!l&&r!l&&!r
27262135
MC/DC100%2/2
$self->{$field} || $ClearPress::decorator::DEFAULTS->{$field}
$self->{$field} $ClearPress::decorator::DEFAULTS->{$field}
Truth table100%3/3
A || B
A= $self->{$field}B= $ClearPress::decorator::DEFAULTS->{$field}
ABresult
1X1
011
000
67 }
68 }
69  
70 31 ▶sub defaults {
Subroutine defaults: called CC=1 SCAR=0.0
Pod documented
71 31 my ($self, $key) = @_;
72 31 return $DEFAULTS->{$key};
73 }
74  
75 33 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
76 33 my ($class, $ref) = @_;
77 33 ▶ if(!$ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ref) 14 19 33
78 14 $ref = {};
79 }
80 33 bless $ref, $class;
81 33 return $ref;
82 }
83  
84 10 ▶sub header {
Subroutine header: called CC=1 SCAR=0.0
Pod documented
85 10 my ($self) = @_;
86  
87 10 return $self->site_header();
88 }
89  
90 16 ▶sub cookie {
Subroutine cookie: called CC=3 SCAR=12.0
Pod documented
91 16 my ($self, @cookies) = @_;
92  
93 16 ▶ if(scalar @cookies) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @cookies) 0 16 16
94 0 $self->{cookie} = \@cookies;
95 }
96  
97 16 ▶ return @{$self->{cookie}||[]};
Condition50%1/2
$self->{'cookie'} || []
l!l
016
MC/DC0%0/1
$self->{'cookie'} || []
$self->{'cookie'}
Truth table50%1/2
A
A= $self->{'cookie'}
Aresult
11
00
98 }
99  
100 10 ▶sub site_header {
Subroutine site_header: called CC=14 SCAR=32.1
Pod documented
101 10 my ($self) = @_;
102 10 my $cgi = $self->cgi();
103  
104 10 my $ss = <<"EOT";
105 @{[map {
106 0 qq( <link rel="stylesheet" type="text/css" href="$_" />);
107 0 } grep { $_ } @{$self->stylesheet()}]}
108 EOT
109  
110 10 ▶ if($self->style()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->style) 0 10 10
111 0 $ss .= q(<style type="text/css">). $self->style() .q(</style>);
112 }
113  
114 10 my $rss = <<"EOT";
115 @{[map {
116 0 qq( <link rel="alternate" type="application/rss+xml" title="RSS" href="$_" />\n);
117 0 } grep { $_ } @{$self->rss()}]}
118 EOT
119  
120 10 my $atom = <<"EOT";
121 @{[map {
122 0 qq( <link rel="alternate" type="application/atom+xml" title="ATOM" href="$_" />\n);
123 0 } grep { $_ } @{$self->atom()}]}
124 EOT
125  
126 10 my $js = <<"EOT";
127 @{[map {
128 1 qq( <script type="text/javascript" src="@{[$cgi->escapeHTML($_)]}"></script>\n);
129 10 } grep { $_ } @{$self->jsfile()}]}
130 EOT
131  
132 10 my $script = <<"EOT";
133 @{[map {
134 0 qq( <script type="text/javascript">$_</script>\n);
135 0 } grep { $_ } @{$self->script()}]}
136 EOT
137  
138 0 ▶ my $onload = (scalar $self->onload()) ? qq( onload="@{[ join q(;), $self->onload()]}") : q[];
Branch: 1 branch
BranchTrueFalseTotal
scalar $self->onload ? : 0 10 10
139 0 ▶ my $onunload = (scalar $self->onunload()) ? qq( onunload="@{[join q(;), $self->onunload()]}") : q[];
Branch: 1 branch
BranchTrueFalseTotal
scalar $self->onunload ? : 0 10 10
140 0 ▶ my $onresize = (scalar $self->onresize()) ? qq( onresize="@{[join q(;), $self->onresize()]}") : q[];
Branch: 1 branch
BranchTrueFalseTotal
scalar $self->onresize ? : 0 10 10
141 10 return <<"EOT";
142 <?xml version="1.0" encoding="utf-8"?>
143 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
144 10 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="@{[join q[,], @{$self->lang}]}" lang="@{[join q[,], @{$self->lang}]}">
145 <head>
146 10 ▶ <meta http-equiv="Content-Type" content="@{[$self->meta_content_type() || $self->defaults('meta_content_type')]}" />
Condition33%1/3
$self->meta_content_type || $self->defaults('meta_content_type')
l!l&&r!l&&!r
1000
MC/DC0%0/2
$self->meta_content_type || $self->defaults('meta_content_type')
$self->meta_content_type $self->defaults('meta_content_type')
Truth table33%1/3
A || B
A= $self->meta_content_typeB= $self->defaults('meta_content_type')
ABresult
1X1
011
000
147 0 ▶@{[(scalar $self->meta_cookie())?(map { qq( <meta http-equiv="Set-Cookie" content="$_" />\n) } $self->meta_cookie()):q[]]}@{[$self->meta_refresh()?qq(<meta http-equiv="Refresh" content="@{[$self->meta_refresh()]}" />):q[]]}@{[$self->meta_expires()?qq(<meta http-equiv="Expires" content="@{[$self->meta_expires()]}" />):q[]]} <meta name="author" content="@{[$self->meta_author() || $self->defaults('meta_author')]}" />
Branch: 3 branches
BranchTrueFalseTotal
scalar $self->meta_cookie ? : 0 10 10
$self->meta_refresh ? : 0 10 10
$self->meta_expires ? : 0 10 10
Condition33%1/3
$self->meta_author || $self->defaults('meta_author')
l!l&&r!l&&!r
0010
MC/DC0%0/2
$self->meta_author || $self->defaults('meta_author')
$self->meta_author $self->defaults('meta_author')
Truth table33%1/3
A || B
A= $self->meta_authorB= $self->defaults('meta_author')
ABresult
1X1
011
000
148 10 ▶ <meta name="version" content="@{[$self->meta_version() || $self->defaults('meta_version')]}" />
Condition33%1/3
$self->meta_version || $self->defaults('meta_version')
l!l&&r!l&&!r
1000
MC/DC0%0/2
$self->meta_version || $self->defaults('meta_version')
$self->meta_version $self->defaults('meta_version')
Truth table33%1/3
A || B
A= $self->meta_versionB= $self->defaults('meta_version')
ABresult
1X1
011
000
149 10 ▶ <meta name="description" content="@{[$self->meta_description() || $self->defaults('meta_description')]}" />
Condition33%1/3
$self->meta_description || $self->defaults('meta_description')
l!l&&r!l&&!r
0010
MC/DC0%0/2
$self->meta_description || $self->defaults('meta_description')
$self->meta_description $self->defaults('meta_description')
Truth table33%1/3
A || B
A= $self->meta_descriptionB= $self->defaults('meta_description')
ABresult
1X1
011
000
150 10 ▶ <meta name="keywords" content="@{[$self->meta_keywords() || $self->defaults('meta_keywords')]}" />
Condition33%1/3
$self->meta_keywords || $self->defaults('meta_keywords')
l!l&&r!l&&!r
0010
MC/DC0%0/2
$self->meta_keywords || $self->defaults('meta_keywords')
$self->meta_keywords $self->defaults('meta_keywords')
Truth table33%1/3
A || B
A= $self->meta_keywordsB= $self->defaults('meta_keywords')
ABresult
1X1
011
000
151 10 ▶ <title>@{[$self->title || 'ClearPress Application']}</title>
Condition100%2/2
$self->title || 'ClearPress Application'
l!l
91
MC/DC100%1/1
$self->title || 'ClearPress Application'
$self->title
Truth table100%2/2
A
A= $self->title
Aresult
11
00
152 $ss$rss$atom$js$script </head>
153 <body$onload$onunload$onresize>
154 EOT
155 }
156  
157 8 ▶sub footer {
Subroutine footer: called CC=1 SCAR=0.0
Pod documented
158 8 my ($self, @args) = @_;
159 8 return $self->site_footer(@args);
160 }
161  
162 8 ▶sub site_footer {
Subroutine site_footer: called CC=1 SCAR=0.0
Pod documented
163 8 return <<'EOT';
164 </body>
165 </html>
166 EOT
167 }
168  
169 14 ▶sub cgi {
Subroutine cgi: called CC=3 SCAR=11.0
Pod documented
170 14 my ($self, $cgi) = @_;
171  
172 14 ▶ if($cgi) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cgi) { } 1 13 14
elsif (not $self->{'cgi'}) { } 10 3 13
173 1 $self->{cgi} = $cgi;
174  
175 } elsif(!$self->{cgi}) {
176 10 $self->{cgi} = CGI->new();
177 }
178  
179 14 return $self->{cgi};
180 }
181  
182 16 ▶sub session {
Subroutine session: called CC=1 SCAR=0.0
Pod documented
183 16 return {};
184 }
185  
186 17 ▶sub save_session {
Subroutine save_session: called CC=1 SCAR=0.0
Pod documented
187 17 return;
188 }
189  
190 7 1;
191 __END__
« blib/lib/ClearPress/authdecor.pm ↑ Summary blib/lib/ClearPress/view/error.pm »