blib/lib/HTML/XHTML/Lite.pm

filter: Statementstmt 21.2% 21 / 99 Branchbran 0.0% 0 / 70 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 55.5% 5 / 9 Podpod 50.0% 2 / 4 totaltotal 13.9% 28 / 201 CC 41 SCAR 66.7
CC
41
Cov
12%
start_page
1094.5
getvars
20.0
end_page
12.0
CRAP 784.5
↑ Summary
1 package HTML::XHTML::Lite;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 require Exporter;
8  
9 1 our @ISA = qw(Exporter);
10  
11 # Items to export into callers namespace by default. Note: do not export
12 # names by default without a very good reason. Use EXPORT_OK instead.
13 # Do not simply export all your public functions/methods/constants.
14  
15 # This allows declaration use HTML::XHTML::Lite ':all';
16 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
17 # will save memory.
18 1 our %EXPORT_TAGS = ( 'all' => [ qw(
19  
20 ) ] );
21  
22 1 our @EXPORT_OK = qw( start_page end_page getvars );
23  
24 1 our @EXPORT = qw(
25 start_page end_page getvars
26 );
27  
28 1 our $VERSION = '0.06';
29  
30  
31 # Preloaded methods go here.
32  
33 sub start_page
34 0 ▶{
Subroutine start_page: not called CC=35 SCAR=70.0
Pod documented
35 1 ▶use HTTP::Date;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 0 ▶$_[0]={} unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
39  
40 0 my %p=%{$_[0]};
41 0 my $page;
42  
43 0 ▶$p{content_type}='text/html' unless defined $p{content_type};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p{"content_type"} 0 0 0
44 0 ▶my $charset=(defined $p{charset} ? uc($p{charset}) : 'UTF-8');
Branch: 1 branch
BranchTrueFalseTotal
defined $p{'charset'} ? : 0 0 0
45 0 ▶$p{title}='Untitled Document' unless defined $p{title};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p{"title"} 0 0 0
46 0 ▶$p{dctitle}=$p{title} unless defined $p{dctitle};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p{"dctitle"} 0 0 0
47 0 ▶$p{lang}=(defined $p{lang} ? $p{lang} : 'en');
Branch: 1 branch
BranchTrueFalseTotal
defined $p{'lang'} ? : 0 0 0
48 0 ▶$p{foaftitle}='FOAF' unless defined $p{foaftitle};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p{"foaftitle"} 0 0 0
49  
50 0 ▶if ($p{feed})
Branch: 1 branch
BranchTrueFalseTotal
if ($p{"feed"}) 0 0 0
51 {
52 0 ▶ $p{feedtype}="application/rss+xml" unless defined $p{feedtype};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p{"feedtype"} 0 0 0
53 0 ▶ $p{feedtitle}="RSS Feed for $p{title}" unless defined $p{feedtitle};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p{"feedtitle"} 0 0 0
54 }
55  
56 0 my $now=time2str(time());
57 0 ▶my $expires=(defined $p{expires} ? time2str(iso2time($p{expires})) : $now);
Branch: 1 branch
BranchTrueFalseTotal
defined $p{'expires'} ? : 0 0 0
58  
59 0 ▶unless ($p{isfile})
Branch: 1 branch
BranchTrueFalseTotal
unless ($p{"isfile"}) 0 0 0
60 {
61 0 $page.="Expires: $expires\n";
62 0 $page.="Date: $now\n";
63 0 $page.="Content-type: $p{content_type}; charset=$charset\n\n";
64 }
65  
66 0 ▶$page.="<?xml version=\"1.0\" encoding=\"" . lc($charset) . "\"?>\n" unless $p{noxml} || $p{nohead};
Branch: 1 branch
BranchTrueFalseTotal
unless $p{"noxml"} or $p{"nohead"} 0 0 0
Condition0%0/3
$p{"noxml"} or $p{"nohead"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p{"noxml"} or $p{"nohead"}
$p{"noxml"} $p{"nohead"}
Truth table0%0/3
A or B
A= $p{"noxml"}B= $p{"nohead"}
ABresult
1X1
011
000
67 0 ▶$page.="<!DOCTYPE html\n\tPUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" unless $p{nodoctype} || $p{nohead};
Branch: 1 branch
BranchTrueFalseTotal
unless $p{"nodoctype"} or $p{"nohead"} 0 0 0
Condition0%0/3
$p{"nodoctype"} or $p{"nohead"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p{"nodoctype"} or $p{"nohead"}
$p{"nodoctype"} $p{"nohead"}
Truth table0%0/3
A or B
A= $p{"nodoctype"}B= $p{"nohead"}
ABresult
1X1
011
000
68  
69 0 $page.=<<EOT;
70 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="$p{lang}" lang="$p{lang}">
71 <head>
72 <title>$p{title}</title>
73 <link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" />
74 <link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" />
75 <meta name="DC.language" scheme="DCTERMS.RFC1766" content="$p{lang}" />
76 <meta name="DC.type" scheme="DCTERMS.DCMIType" content="Text" />
77 <meta name="DC.format" scheme="DCTERMS.IMT" content="text/html; charset=$charset" />
78 <meta name="DC.title" lang="$p{lang}" content="$p{dctitle}" />
79 EOT
80  
81 0 ▶$page.="<meta name=\"DC.description\" lang=\"$p{lang}\" content=\"$p{description}\" />\n" if defined $p{description};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{"description"} 0 0 0
82 0 ▶$page.="<meta name=\"DC.creator\" content=\"$p{creator}\" />\n" if defined $p{creator};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{"creator"} 0 0 0
83 0 ▶$page.="<meta name=\"DC.identifier\" content=\"$p{identifier}\" />\n" if defined $p{identifier};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{"identifier"} 0 0 0
84 0 ▶$page.="<meta name=\"DC.subject\" lang=\"$p{lang}\" content=\"$p{subject}\" />\n" if defined $p{subject};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{"subject"} 0 0 0
85 0 ▶$page.="<meta name=\"DC.rights\" content=\"$p{rights}\" />\n" if defined $p{rights};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{"rights"} 0 0 0
86 0 ▶$page.="<meta name=\"DCTERMS.created\" scheme=\"DCTERMS.W3CDTF\" content=\"$p{created}\" />\n" if defined $p{created};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{"created"} 0 0 0
87 0 ▶$page.="<meta name=\"DCTERMS.modified\" scheme=\"DCTERMS.W3CDTF\" content=\"$p{modified}\" />\n" if defined $p{modified};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{"modified"} 0 0 0
88 0 ▶$page.="<meta name=\"DC.date\" content=\"$p{date}\" />\n" if defined $p{date};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{"date"} 0 0 0
89  
90 0 ▶if (defined $p{legacy} && defined $p{description} && defined $p{subject})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p{"legacy"} and defined $p{"description"} and defined $p{"subject"}) 0 0 0
Condition0%0/6
defined $p{"legacy"} and defined $p{"description"} and defined $p{"subject"}
!ll&&!rl&&r
000
defined $p{"legacy"} and defined $p{"description"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $p{"legacy"} and defined $p{"description"} and defined $p{"subject"}
defined $p{"legacy"} defined $p{"description"} defined $p{"subject"}
Truth table0%0/4
A and B and C
A= defined $p{"legacy"}B= defined $p{"description"}C= defined $p{"subject"}
ABCresult
0XX0
10X0
1100
1111
91 {
92 0 my $kwds=$p{subject};
93 0 $kwds=~s/;/,/g;
94 0 $page.="<meta name=\"description\" content=\"$p{description}\" />\n";
95 0 $page.="<meta name=\"keywords\" content=\"$kwds\" />\n";
96 }
97  
98 0 ▶$page.="<link rel=\"stylesheet\" type=\"text/css\" href=\"$p{csssrc}\" />\n" if defined $p{csssrc};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{"csssrc"} 0 0 0
99 0 ▶$page.="<style type=\"text/css\">$p{css}</style>\n" if defined $p{css};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{"css"} 0 0 0
100 $page.="<link rel=\"alternate\" type=\"$p{feedtype}\" title=\"$p{feedtitle}\" href=\"$p{feed}\" />\n"
101 0 ▶ if defined $p{feed};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{"feed"} 0 0 0
102 $page.="<link rel=\"meta\" type=\"application/rdf+xml\" title=\"$p{foaftitle}\" href=\"$p{foaf}\" />\n"
103 0 ▶ if defined $p{foaf};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{"foaf"} 0 0 0
104 0 ▶$page.=$p{extras} if defined $p{extras};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{"extras"} 0 0 0
105 0 $page.="</head><body>\n";
106  
107 0 ▶if (defined $p{body})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p{"body"}) 0 0 0
108 {
109 0 $page.=$p{body};
110 0 my %footp=%p;
111 0 $footp{string}=1;
112 0 $page.=end_page(\%footp);
113 }
114  
115 0 ▶if ($p{string})
Branch: 1 branch
BranchTrueFalseTotal
if ($p{'string'}) { } 0 0 0
116 {
117 0 return $page;
118 }
119 else
120 {
121 0 print $page;
122 }
123  
124 } #</start_page>
125  
126 sub end_page
127 0 ▶{
Subroutine end_page: not called CC=3 SCAR=24.8
Pod documented
128 0 my $page;
129  
130 0 ▶ $_[0]={} unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
131  
132 0 my %p=%{$_[0]};
133 0 $page.="\n</body></html>\n";
134  
135 0 ▶ if ($p{string})
Branch: 1 branch
BranchTrueFalseTotal
if ($p{'string'}) { } 0 0 0
136 {
137 0 return $page;
138 }
139 else
140 {
141 0 print $page;
142 }
143 }
144  
145 sub iso2time
146 0 ▶{
Subroutine iso2time: not called CC=2 SCAR=17.9
Pod undocumented
147 0 ▶ $_[0] =~ /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/ or return undef 0 0 0
148 0 return timelocal($6,$5,$4,$3,$2-1,$1-1900);
149 }
150  
151 sub getvars
152 0 ▶{
Subroutine getvars: not called CC=4 SCAR=30.0
Pod undocumented
153 # A 'Lite' version of CGI.pm's param function
154 # Returns a reference to a hash of arrays of
155 # name/value pairs.
156  
157 0 my (@nvps,%vars);
158  
159 # Look after anything coming from a
160 # POST form
161 0 ▶ if (lc($ENV{REQUEST_METHOD}) eq 'post')
Branch: 1 branch
BranchTrueFalseTotal
if (lc $ENV{"REQUEST_METHOD"} eq "post") 0 0 0
162 {
163 0 read(STDIN, my $postdata, $ENV{CONTENT_LENGTH});
164 0 push(@nvps,split(/&/,$postdata));
165 }
166  
167 # Pick up anything passed through the
168 # query string, either by a GET form
169 # or direct by URI
170 0 my $qs=$ENV{QUERY_STRING};
171 0 $qs=~s/&/;/g;
172 0 push(@nvps,split(/;/,$qs));
173
174 0 foreach my $nv (@nvps)
175 {
176 0 my @a=split(/=/,$nv);
177 0 $a[0]=~tr/+/ /;
178 0 $a[0]=~s/%([\da-f][\da-f])/chr(hex($1))/egi;
179 0 ▶ $a[1]="" unless defined $a[1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a[1] 0 0 0
180 0 $a[1]=~tr/+/ /;
181 0 $a[1]=~s/%([\da-f][\da-f])/chr(hex($1))/egi;
182 0 push @{$vars{$a[0]}},$a[1];
183 }
184 0 return %vars;
185 }
186  
187 1 1;
188 __END__
↑ Summary