blib/lib/Pod/Advent.pm

filter: Statementstmt 95.9% 215 / 224 Branchbran 96.2% 152 / 158 Conditioncond 87.5% 70 / 80 MC/DCmcdc 81.2% 39 / 48 Subroutinesub 100% 20 / 20 Podpod 100% 8 / 8 totaltotal 93.6% 504 / 538 CC 110 SCAR 33.8
CC
110
Cov
95%
_handle_element_end
42.0
_handle_element_start
33.0
_handle_text
29.1
CRAP 29.5
↑ Summary bin/pod2advent »
1 package Pod::Advent;
2  
3 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 17 ▶use base qw(Pod::Simple);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶use Perl::Tidy;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 17 ▶use File::Basename();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use HTML::Entities();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 17 our $VERSION = '0.24';
12  
13 17 our @mode;
14 17 our $section;
15 17 our %data;
16 17 our %blocks;
17 17 our %M_values_seen;
18 17 our $BODY_ONLY;
19 17 our $speller;
20 17 our @misspelled;
21 17 our %footnotes;
22 17 our @PERLTIDY_ARGV = qw/ -npro -html -pre /;
23  
24 17 __PACKAGE__->__reset();
25  
26 93 ▶sub __reset(){
Subroutine __reset: called CC=2 SCAR=7.0
27 93 my $self = shift;
28  
29 93 @mode = ();
30 93 $section = '';
31 93 %data = (
32 title => undef,
33 author => undef,
34 year => (localtime)[5]+1900,
35 day => 0,
36 body => '',
37 file => undef,
38 css_url => '../style.css',
39 isAdvent => 1,
40 );
41 93 %blocks = (
42 code => '',
43 codeNNN => '',
44 pre => '',
45 sourced_file => '',
46 sourced_desc => '',
47 );
48 93 %M_values_seen = ();
49 93 $BODY_ONLY = 0;
50 93 $speller = undef;
51 93 eval {
52 93 require Text::Aspell;
53 0 $speller = Text::Aspell->new;
54 0 $speller->set_option('lang','en_US');
55 };
56 93 ▶ $self->spellcheck_enabled or warn "Couldn't load Text::Aspell -- spellchecking disabled.";
Branch: 1 branch
BranchTrueFalseTotal
$self->spellcheck_enabled or warn "Couldn't load Text::Aspell -- spellchecking disabled." 0 93 93
57 93 @misspelled = ();
58 93 %footnotes = ();
59 }
60  
61 317 ▶sub spellcheck_enabled {
Subroutine spellcheck_enabled: called CC=2 SCAR=7.2
Pod documented
62 317 my $self = shift;
63 317 ▶ return ref($speller) eq 'Text::Aspell' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $Pod::Advent::speller eq 'Text::Aspell' ? : 0 317 317
64 }
65  
66 76 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
67 76 my $self = shift;
68 76 $self = $self->SUPER::new(@_);
69 76 $self->accept_codes( qw/A D M N P/ );
70 76 $self->accept_targets_as_text( qw/advent_title advent_author advent_year advent_day/ );
71 76 $self->accept_targets( qw/code codeNNN pre/ );
72 76 $self->accept_targets_as_text( qw/quote eds footnote/ );
73 76 $self->accept_directive_as_data('sourcedcode');
74 76 $self->__reset();
75 76 return $self;
76 }
77  
78 4 ▶sub css_url {
Subroutine css_url: called CC=2 SCAR=6.9
Pod documented
79 4 my $self = shift;
80 4 ▶ if( scalar @_ ){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 2 2 4
81 2 $data{css_url} = $_[0];
82 }
83 4 return $data{css_url};
84 }
85  
86 10 ▶sub parse_file {
Subroutine parse_file: called CC=2 SCAR=6.9
Pod documented
87 10 my $self = shift;
88 10 my $filename = shift;
89 10 my $cwd = getcwd();
90 10 ▶ if( ! ref($filename) ){ # if it's a scalar, meaning a filename
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $filename) 7 3 10
91 7 my( $f, $d) = File::Basename::fileparse($filename);
92 7 $data{file} = $f;
93 7 $filename = $f;
94 7 chdir $d;
95 }
96 10 $self = $self->SUPER::parse_file($filename, @_);
97 10 chdir $cwd;
98 }
99  
100 889 ▶sub add {
Subroutine add: called CC=1 SCAR=0.0
Pod documented
101 889 my $self = shift;
102 889 my $s = shift;
103 889 $data{body} .= $s;
104 }
105  
106 149 ▶sub nl {
Subroutine nl: called CC=1 SCAR=0.0
Pod documented
107 149 my $self = shift;
108 149 $self->add("\n");
109 }
110  
111 423 ▶sub _handle_element_start {
Subroutine _handle_element_start: called CC=33 SCAR=35.0
112 423 my($parser, $element_name, $attr_hash_r) = @_;
113 423 push @mode, $element_name;
114 423 ▶ if( $element_name eq 'Document' ){
Branch: 21 branches
BranchTrueFalseTotal
if ($element_name eq 'Document') { } 75 348 423
elsif ($element_name eq 'head1') { } 6 342 348
elsif ($element_name eq 'head2') { } 7 335 342
elsif ($element_name eq 'head3') { } 3 332 335
elsif ($element_name eq 'head4') { } 3 329 332
elsif ($element_name eq 'Para' and $Pod::Advent::mode[-2] eq 'footnote') { } 10 319 329
elsif ($element_name eq 'Para' and $Pod::Advent::mode[-2] ne 'for') { } 108 211 319
elsif ($element_name eq 'L') { } 7 204 211
elsif ($element_name eq 'A') { } 12 192 204
elsif ($element_name eq 'M') { } 12 180 192
elsif ($element_name eq 'F') { } 6 174 180
elsif ($element_name eq 'C') { } 3 171 174
elsif ($element_name eq 'I') { } 14 157 171
elsif ($element_name eq 'B') { } 17 140 157
elsif ($element_name eq 'for' and $attr_hash_r->{'target'} =~ /^advent_(\w+)$/) { } 26 114 140
elsif ($element_name eq 'for' and $attr_hash_r->{'target'} eq 'footnote') { } 9 105 114
elsif ($element_name eq 'for' and $attr_hash_r->{'target'} eq 'quote') { } 3 102 105
elsif ($element_name eq 'for' and $attr_hash_r->{'target'} eq 'eds') { } 3 99 102
elsif ($element_name eq 'for' and $attr_hash_r->{'target'} eq 'code') { } 5 94 99
elsif ($element_name eq 'for' and $attr_hash_r->{'target'} eq 'codeNNN') { } 3 91 94
elsif ($element_name eq 'for' and $attr_hash_r->{'target'} eq 'pre') { } 5 172 177
115 }elsif( $element_name eq 'head1' ){
116 6 $parser->add('<h1>');
117 }elsif( $element_name eq 'head2' ){
118 7 $parser->add('<h2>');
119 }elsif( $element_name eq 'head3' ){
120 3 $parser->add('<h3>');
121 }elsif( $element_name eq 'head4' ){
122 3 $parser->add('<h4>');
123 ▶ }elsif( $element_name eq 'Para' && $mode[-2] eq 'footnote' ){
Condition100%3/3
$element_name eq "Para" and $Pod::Advent::mode[-2] eq "footnote"
!ll&&!rl&&r
18513410
MC/DC100%2/2
$element_name eq "Para" and $Pod::Advent::mode[-2] eq "footnote"
$element_name eq "Para" $Pod::Advent::mode[-2] eq "footnote"
Truth table100%3/3
A and B
A= $element_name eq "Para"B= $Pod::Advent::mode[-2] eq "footnote"
ABresult
0X0
100
111
124 # nothing
125 ▶ }elsif( $element_name eq 'Para' && $mode[-2] ne 'for' ){
Condition100%3/3
$element_name eq "Para" and $Pod::Advent::mode[-2] ne "for"
!ll&&!rl&&r
18526108
MC/DC100%2/2
$element_name eq "Para" and $Pod::Advent::mode[-2] ne "for"
$element_name eq "Para" $Pod::Advent::mode[-2] ne "for"
Truth table100%3/3
A and B
A= $element_name eq "Para"B= $Pod::Advent::mode[-2] ne "for"
ABresult
0X0
100
111
126 108 $parser->add('<p>');
127 }elsif( $element_name eq 'L' ){
128 7 $parser->add( sprintf('<a href="%s">',$attr_hash_r->{to}) );
129 }elsif( $element_name eq 'A' ){
130 }elsif( $element_name eq 'M' ){
131 12 $parser->add('<tt>');
132 }elsif( $element_name eq 'F' ){
133 6 $parser->add('<tt>');
134 }elsif( $element_name eq 'C' ){
135 3 $parser->add('<tt>');
136 }elsif( $element_name eq 'I' ){
137 14 $parser->add('<span style="font-style: italic">');
138 }elsif( $element_name eq 'B' ){
139 17 $parser->add('<span style="font-weight: bold">');
140 ▶ }elsif( $element_name eq 'for' && $attr_hash_r->{target} =~ /^advent_(\w+)$/ ){
Condition100%3/3
$element_name eq "for" and $attr_hash_r->{"target"} =~ /^advent_(\w+)$/
!ll&&!rl&&r
862826
MC/DC100%2/2
$element_name eq "for" and $attr_hash_r->{"target"} =~ /^advent_(\w+)$/
$element_name eq "for" $attr_hash_r->{"target"} =~ /^advent_(\w+)$/
Truth table100%3/3
A and B
A= $element_name eq "for"B= $attr_hash_r->{"target"} =~ /^advent_(\w+)$/
ABresult
0X0
100
111
141 26 $section = $1;
142 ▶ }elsif( $element_name eq 'for' && $attr_hash_r->{target} eq 'footnote' ){
Condition100%3/3
$element_name eq "for" and $attr_hash_r->{"target"} eq "footnote"
!ll&&!rl&&r
86199
MC/DC100%2/2
$element_name eq "for" and $attr_hash_r->{"target"} eq "footnote"
$element_name eq "for" $attr_hash_r->{"target"} eq "footnote"
Truth table100%3/3
A and B
A= $element_name eq "for"B= $attr_hash_r->{"target"} eq "footnote"
ABresult
0X0
100
111
143 9 $mode[-1] = $attr_hash_r->{target};
144 9 $section = $attr_hash_r->{title};
145 9 ▶ my $n = delete $footnotes{$section} or die "footnote '$section' is not referenced.";
Branch: 1 branch
BranchTrueFalseTotal
my $n = delete $Pod::Advent::footnotes{$Pod::Advent::section} or die "footnote '$Pod::Advent::section' is not referenced." 8 1 9
146 8 $parser->add( sprintf '<p><a name="footnote_%s" id="footnote_%s"></a>%d. ', $section, $section, $n);
147 ▶ }elsif( $element_name eq 'for' && $attr_hash_r->{target} eq 'quote' ){
Condition100%3/3
$element_name eq "for" and $attr_hash_r->{"target"} eq "quote"
!ll&&!rl&&r
86163
MC/DC100%2/2
$element_name eq "for" and $attr_hash_r->{"target"} eq "quote"
$element_name eq "for" $attr_hash_r->{"target"} eq "quote"
Truth table100%3/3
A and B
A= $element_name eq "for"B= $attr_hash_r->{"target"} eq "quote"
ABresult
0X0
100
111
148 3 $mode[-1] = $attr_hash_r->{target};
149 3 $parser->add('<blockquote>');
150 ▶ }elsif( $element_name eq 'for' && $attr_hash_r->{target} eq 'eds' ){
Condition100%3/3
$element_name eq "for" and $attr_hash_r->{"target"} eq "eds"
!ll&&!rl&&r
86133
MC/DC100%2/2
$element_name eq "for" and $attr_hash_r->{"target"} eq "eds"
$element_name eq "for" $attr_hash_r->{"target"} eq "eds"
Truth table100%3/3
A and B
A= $element_name eq "for"B= $attr_hash_r->{"target"} eq "eds"
ABresult
0X0
100
111
151 3 $mode[-1] = $attr_hash_r->{target};
152 3 $parser->add('<blockquote>');
153 ▶ }elsif( $element_name eq 'for' && $attr_hash_r->{target} eq 'code' ){
Condition100%3/3
$element_name eq "for" and $attr_hash_r->{"target"} eq "code"
!ll&&!rl&&r
8685
MC/DC100%2/2
$element_name eq "for" and $attr_hash_r->{"target"} eq "code"
$element_name eq "for" $attr_hash_r->{"target"} eq "code"
Truth table100%3/3
A and B
A= $element_name eq "for"B= $attr_hash_r->{"target"} eq "code"
ABresult
0X0
100
111
154 5 $section = $attr_hash_r->{target};
155 ▶ }elsif( $element_name eq 'for' && $attr_hash_r->{target} eq 'codeNNN' ){
Condition100%3/3
$element_name eq "for" and $attr_hash_r->{"target"} eq "codeNNN"
!ll&&!rl&&r
8653
MC/DC100%2/2
$element_name eq "for" and $attr_hash_r->{"target"} eq "codeNNN"
$element_name eq "for" $attr_hash_r->{"target"} eq "codeNNN"
Truth table100%3/3
A and B
A= $element_name eq "for"B= $attr_hash_r->{"target"} eq "codeNNN"
ABresult
0X0
100
111
156 3 $section = $attr_hash_r->{target};
157 ▶ }elsif( $element_name eq 'for' && $attr_hash_r->{target} eq 'pre' ){
Condition66%2/3
$element_name eq "for" and $attr_hash_r->{"target"} eq "pre"
!ll&&!rl&&r
8605
MC/DC50%1/2
$element_name eq "for" and $attr_hash_r->{"target"} eq "pre"
$element_name eq "for" $attr_hash_r->{"target"} eq "pre"
Truth table66%2/3
A and B
A= $element_name eq "for"B= $attr_hash_r->{"target"} eq "pre"
ABresult
0X0
100
111
158 5 $mode[-1] = $attr_hash_r->{target};
159 5 ▶ $section = $attr_hash_r->{title} || 'normal';
Condition100%2/2
$attr_hash_r->{'title'} || 'normal'
l!l
14
MC/DC100%1/1
$attr_hash_r->{'title'} || 'normal'
$attr_hash_r->{'title'}
Truth table100%2/2
A
A= $attr_hash_r->{'title'}
Aresult
11
00
160 }
161 }
162  
163 376 ▶sub _handle_element_end {
Subroutine _handle_element_end: called CC=42 SCAR=37.4
164 376 my($parser, $element_name) = @_;
165 376 my $mode = pop @mode;
166 376 ▶ if( $element_name eq 'Document' ){
Branch: 19 branches
BranchTrueFalseTotal
if ($element_name eq 'Document') { } 59 317 376
elsif ($element_name eq 'head1') { } 6 311 317
elsif ($element_name eq 'head2') { } 7 304 311
elsif ($element_name eq 'head3') { } 3 301 304
elsif ($element_name eq 'head4') { } 3 298 301
elsif ($element_name eq 'Para' and $Pod::Advent::mode[-1] eq 'footnote') { } 10 288 298
elsif ($element_name eq 'Para' and $Pod::Advent::mode[-1] ne 'for') { } 93 195 288
elsif ($element_name eq 'for' and $mode eq 'quote') { } 3 192 195
elsif ($element_name eq 'for' and $mode eq 'eds') { } 3 189 192
elsif ($element_name eq 'for' and $mode eq 'footnote') { } 8 181 189
elsif ($element_name eq 'for' and $Pod::Advent::section eq 'code' || $Pod::Advent::section eq 'codeNNN') { } 8 173 181
elsif ($element_name eq 'for' and $mode eq 'pre') { } 5 168 173
elsif ($element_name eq 'L') { } 7 161 168
elsif ($element_name eq 'M') { } 12 149 161
elsif ($element_name eq 'A') { } 12 137 149
elsif ($element_name eq 'F') { } 6 131 137
elsif ($element_name eq 'C') { } 3 128 131
elsif ($element_name eq 'I') { } 14 114 128
elsif ($element_name eq 'B') { } 17 97 114
167 59 die "footnote '$_' is not defined" for keys %footnotes;
168 my ($htmlTitle, $pageTitle) = $data{isAdvent}
169 114 ▶ ? ( sprintf('%d Perl Advent Calendar: %s',map {defined($_)?$_:''} @data{qw/year title/}),
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 63 51 114
170 171 ▶ sprintf('<h1><a href="../">Perl Advent Calendar %d-12</a>-%02d</h1>'."\n".'<h2 align="center">%s</h2>',,map {defined($_)?$_:''} @data{qw/year day title/}) )
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 120 51 171
Condition50%2/4
$Pod::Advent::data{"title"} or ""
l!l
10
$Pod::Advent::data{'title'} || ''
l!l
10
MC/DC0%0/1
$Pod::Advent::data{"title"} or ""
$Pod::Advent::data{"title"}
MC/DC0%0/1
$Pod::Advent::data{'title'} || ''
$Pod::Advent::data{'title'}
Truth table50%1/2
A
A= $Pod::Advent::data{"title"}
Aresult
11
00
Truth table50%1/2
A
A= $Pod::Advent::data{'title'}
Aresult
11
00
171 : ( $data{title}||'',
172 58 ▶ sprintf('<h1>%s</h1>',$data{title}||'') )
Branch: 1 branch
BranchTrueFalseTotal
$Pod::Advent::data{'isAdvent'} ? : 57 1 58
173 ;
174 58 my $fmt = <<'EOF';
175 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
176 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
177 <!-- Generated by Pod::Advent %s (Pod::Simple %s, Perl::Tidy %s) on %04d-%02d-%02d %02d:%02d:%02d -->
178 <html xmlns="http://www.w3.org/1999/xhtml">
179 <head>
180 <title>%s</title>
181 <link rel="stylesheet" href="%s" type="text/css" />
182 %s
183 </head>
184 <body>
185 %s
186 %s
187 EOF
188 58 my @d = (localtime)[5,4,3,2,1,0]; $d[1]++; $d[0]+=1900;
189 58 ▶ my $fh = $parser->output_fh() || \*STDOUT;
Condition100%2/2
$parser->output_fh || \*STDOUT
l!l
4810
MC/DC100%1/1
$parser->output_fh || \*STDOUT
$parser->output_fh
Truth table100%2/2
A
A= $parser->output_fh
Aresult
11
00
190 printf( $fh $fmt,
191 $Pod::Advent::VERSION, $Pod::Simple::VERSION, $Perl::Tidy::VERSION,
192 @d[0..5],
193 $htmlTitle,
194 $data{css_url},
195 $data{file} ? qq{<link rel="alternate" type="text/plain" href="$data{file}" />} : "",
196 $pageTitle,
197 58 ▶ $data{author} ? qq{<h3 align="center">by $data{author}</h3>} : '',
Branch: 3 branches
BranchTrueFalseTotal
unless $Pod::Advent::BODY_ONLY 10 48 58
$Pod::Advent::data{'file'} ? : 7 3 10
$Pod::Advent::data{'author'} ? : 6 4 10
198 ) unless $BODY_ONLY;
199 58 print $fh $data{body};
200 58 ▶ if( $data{file} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($Pod::Advent::data{"file"}) 7 51 58
201 7 printf $fh '<div style="float: right; font-size: 10pt"><a href="%s">View Source (POD)</a></div><br />'."\n", $data{file};
202 }
203 58 ▶ print $fh <<'EOF' unless $BODY_ONLY;
Branch: 1 branch
BranchTrueFalseTotal
unless $Pod::Advent::BODY_ONLY 10 48 58
204 </body>
205 </html>
206 EOF
207 }elsif( $element_name eq 'head1' ){
208 6 $parser->add('</h1>');
209 6 $parser->nl;
210 }elsif( $element_name eq 'head2' ){
211 7 $parser->add('</h2>');
212 7 $parser->nl;
213 }elsif( $element_name eq 'head3' ){
214 3 $parser->add('</h3>');
215 3 $parser->nl;
216 }elsif( $element_name eq 'head4' ){
217 3 $parser->add('</h4>');
218 3 $parser->nl;
219 ▶ }elsif( $element_name eq 'Para' && $mode[-1] eq 'footnote' ){
Condition100%3/3
$element_name eq "Para" and $Pod::Advent::mode[-1] eq "footnote"
!ll&&!rl&&r
16911910
MC/DC100%2/2
$element_name eq "Para" and $Pod::Advent::mode[-1] eq "footnote"
$element_name eq "Para" $Pod::Advent::mode[-1] eq "footnote"
Truth table100%3/3
A and B
A= $element_name eq "Para"B= $Pod::Advent::mode[-1] eq "footnote"
ABresult
0X0
100
111
220 10 $parser->add('<br>');
221 10 $parser->nl;
222 ▶ }elsif( $element_name eq 'Para' && $mode[-1] ne 'for' ){
Condition100%3/3
$element_name eq "Para" and $Pod::Advent::mode[-1] ne "for"
!ll&&!rl&&r
1692693
MC/DC100%2/2
$element_name eq "Para" and $Pod::Advent::mode[-1] ne "for"
$element_name eq "Para" $Pod::Advent::mode[-1] ne "for"
Truth table100%3/3
A and B
A= $element_name eq "Para"B= $Pod::Advent::mode[-1] ne "for"
ABresult
0X0
100
111
223 93 $parser->add('</p>');
224 93 $parser->nl;
225 ▶ }elsif( $element_name eq 'for' && $mode eq 'quote' ){
Condition100%3/3
$element_name eq "for" and $mode eq "quote"
!ll&&!rl&&r
142503
MC/DC100%2/2
$element_name eq "for" and $mode eq "quote"
$element_name eq "for" $mode eq "quote"
Truth table100%3/3
A and B
A= $element_name eq "for"B= $mode eq "quote"
ABresult
0X0
100
111
226 3 $parser->add('</blockquote>');
227 3 $parser->nl;
228 ▶ }elsif( $element_name eq 'for' && $mode eq 'eds' ){
Condition100%3/3
$element_name eq "for" and $mode eq "eds"
!ll&&!rl&&r
142473
MC/DC100%2/2
$element_name eq "for" and $mode eq "eds"
$element_name eq "for" $mode eq "eds"
Truth table100%3/3
A and B
A= $element_name eq "for"B= $mode eq "eds"
ABresult
0X0
100
111
229 3 $parser->add('</blockquote>');
230 3 $parser->nl;
231 ▶ }elsif( $element_name eq 'for' && $mode eq 'footnote' ){
Condition100%3/3
$element_name eq "for" and $mode eq "footnote"
!ll&&!rl&&r
142398
MC/DC100%2/2
$element_name eq "for" and $mode eq "footnote"
$element_name eq "for" $mode eq "footnote"
Truth table100%3/3
A and B
A= $element_name eq "for"B= $mode eq "footnote"
ABresult
0X0
100
111
232 8 $parser->add('</p>');
233 8 $parser->nl;
234 ▶ }elsif( $element_name eq 'for' && ($section eq 'code' || $section eq 'codeNNN') ){
Condition100%6/6
$element_name eq "for" and $Pod::Advent::section eq "code" || $Pod::Advent::section eq "codeNNN"
!ll&&!rl&&r
142318
$Pod::Advent::section eq "code" or $Pod::Advent::section eq "codeNNN"
l!l&&r!l&&!r
5331
MC/DC100%3/3
$element_name eq "for" and $Pod::Advent::section eq "code" || $Pod::Advent::section eq "codeNNN"
$element_name eq "for" $Pod::Advent::section eq "code" $Pod::Advent::section eq "codeNNN"
Truth table100%4/4
A and B or C
A= $element_name eq "for"B= $Pod::Advent::section eq "code"C= $Pod::Advent::section eq "codeNNN"
ABCresult
0XX0
1000
11X1
1011
235 8 my $s;
236 8 $blocks{$section} =~ s/\s+$//;
237 Perl::Tidy::perltidy(
238 8 ▶ source => \$blocks{$section},
Branch: 1 branch
BranchTrueFalseTotal
$Pod::Advent::section =~ /NNN/ ? : 3 5 8
239 destination => \$s,
240 argv => [ @PERLTIDY_ARGV, ($section=~/NNN/?'-nnn':()) ],
241 );
242 8 $parser->add($s);
243 8 $parser->nl;
244 8 $blocks{$section} = '';
245 8 $section = '';
246 ▶ }elsif( $element_name eq 'for' && $mode eq 'pre' ){
Condition100%3/3
$element_name eq "for" and $mode eq "pre"
!ll&&!rl&&r
142265
MC/DC100%2/2
$element_name eq "for" and $mode eq "pre"
$element_name eq "for" $mode eq "pre"
Truth table100%3/3
A and B
A= $element_name eq "for"B= $mode eq "pre"
ABresult
0X0
100
111
247 5 $blocks{$section} =~ s/\s+$//s;
248 5 $parser->add('<pre><span class="c">');
249 5 my $s = $blocks{$section};
250 5 ▶ $s = HTML::Entities::encode_entities($s) if $section eq 'encode_entities';
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Advent::section eq "encode_entities" 1 4 5
251 5 $parser->add( $s );
252 5 $parser->add('</span></pre>');
253 5 $parser->nl;
254 5 $blocks{$section} = '';
255 5 $section = '';
256 }elsif( $element_name eq 'L' ){
257 7 $parser->add('</a>');
258 }elsif( $element_name eq 'M' ){
259 12 $parser->add('</tt>');
260 }elsif( $element_name eq 'A' ){
261 }elsif( $element_name eq 'F' ){
262 6 $parser->add('</tt>');
263 }elsif( $element_name eq 'C' ){
264 3 $parser->add('</tt>');
265 }elsif( $element_name eq 'I' ){
266 14 $parser->add('</span>');
267 }elsif( $element_name eq 'B' ){
268 17 $parser->add('</span>');
269 }
270 }
271  
272 314 ▶sub _handle_text {
Subroutine _handle_text: called CC=29 SCAR=33.7
273 314 my($parser, $text) = @_;
274 314 my $mode = $mode[-1];
275 314 my $out = '';
276 314 ▶ if( $mode eq 'Verbatim' ){
Branch: 12 branches
BranchTrueFalseTotal
if ($mode eq 'Verbatim') { } 2 312 314
elsif ($mode eq 'C') { } 3 309 312
elsif ($mode eq 'N') { } 11 298 309
elsif ($mode eq 'P') { } 21 277 298
elsif ($mode eq 'sourcedcode') { } 5 272 277
elsif ($mode eq 'Para' and $Pod::Advent::section) { } 34 238 272
elsif ($mode eq 'A') { } 12 226 238
elsif ($mode eq 'M') { } 12 214 226
elsif ($mode eq 'Data' and $Pod::Advent::section) { } 19 195 214
elsif ($mode eq 'F') { } 6 189 195
elsif ($mode eq 'L') { } 7 182 189
elsif ($mode eq 'D') { } 4 178 182
277 2 my $s;
278 2 Perl::Tidy::perltidy(
279 source => \$text,
280 destination => \$s,
281 argv => [ @PERLTIDY_ARGV ],
282 );
283 2 $out .= $s;
284 }elsif( $mode eq 'C' ){
285 3 my $s;
286 3 Perl::Tidy::perltidy(
287 source => \$text,
288 destination => \$s,
289 argv => [ @PERLTIDY_ARGV ],
290 );
291 3 $s =~ s#^<pre>\s*(.*?)\s*</pre>\s*$#$1#si;
292 3 $out .= $s;
293 }elsif( $mode eq 'N' ){
294 11 ▶ die "footnote '$text' is already referenced" if exists $footnotes{$text};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Pod::Advent::footnotes{$text} 1 10 11
295 10 $footnotes{$text} = 1 + scalar keys %footnotes;
296 10 $out .= sprintf '<sup><a href="#footnote_%s">%s</a></sup>', $text, $footnotes{$text};
297 }elsif( $mode eq 'P' ){
298 21 my ($year, $day, $label) = $text =~ m/^(\d{4})-(?:12-)?(\d{1,2})(?:\|(.+))?$/;
299 21 my $CURYEAR = (localtime)[5] + 1900;
300 21 ▶ die "invalid date from P<$text>" unless $year && 2000 <= $year && $year <= $CURYEAR && 1 <= $day && $day <= 25;
Branch: 1 branch
BranchTrueFalseTotal
unless $year and 2000 <= $year and $year <= $CURYEAR and 1 <= $day and $day <= 25 14 7 21
Condition75%9/12
$year and 2000 <= $year and $year <= $CURYEAR and 1 <= $day and $day <= 25
!ll&&!rl&&r
1227
$year and 2000 <= $year and $year <= $CURYEAR and 1 <= $day
!ll&&!rl&&r
1209
$year and 2000 <= $year and $year <= $CURYEAR
!ll&&!rl&&r
1209
$year and 2000 <= $year
!ll&&!rl&&r
1209
MC/DC40%2/5
$year and 2000 <= $year and $year <= $CURYEAR and 1 <= $day and $day <= 25
$year 2000 <= $year $year <= $CURYEAR 1 <= $day $day <= 25
Truth table50%3/6
A and B and C and D and E
A= $yearB= 2000 <= $yearC= $year <= $CURYEARD= 1 <= $dayE= $day <= 25
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
301 7 ▶ $out .= sprintf '<a href="../../%d/%d/">%s</a>',
Branch: 1 branch
BranchTrueFalseTotal
$label ? : 2 5 7
302 $year, $day, ($label ? $label : sprintf '%d/%d', $year, $day);
303  
304 }elsif( $mode eq 'sourcedcode' ){
305 5 ▶ die "bad filename '$text'" unless -r $text;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $text 1 4 5
306 4 $blocks{sourced_file} = $text;
307 4 $out .= sprintf '<a name="%s" id="%s"></a><h2><a href="%s">%s</a></h2>', ($text)x4;
308 4 my $s;
309 4 Perl::Tidy::perltidy(
310 source => $text,
311 destination => \$s,
312 argv => [ @PERLTIDY_ARGV, '-nnn' ],
313 # formatter => bless( {file=>$text, dest => \$s}, 'Pod::Advent::Tidy' ),
314 );
315 4 $s =~ s#^\s*(\d+) #<a name="$text.$1"></a>$&#mg;
316 4 $out .= $s;
317 ▶ }elsif( $mode eq 'Para' && $section ){
Condition100%3/3
$mode eq "Para" and $Pod::Advent::section
!ll&&!rl&&r
11412434
MC/DC100%2/2
$mode eq "Para" and $Pod::Advent::section
$mode eq "Para" $Pod::Advent::section
Truth table100%3/3
A and B
A= $mode eq "Para"B= $Pod::Advent::section
ABresult
0X0
100
111
318 34 $data{$section} = $text;
319 34 $section = '';
320 34 $parser->__spellcheck($text);
321 34 ▶ $out .= $text if $mode[-2] eq 'footnote';
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Advent::mode[-2] eq "footnote" 8 26 34
322 }elsif( $mode eq 'A' ){
323 12 my $href;
324 12 ($href, $text) = split /\|/, $text, 2;
325 12 ▶ $text = $href unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 4 8 12
326 12 ▶ $parser->__spellcheck($text) unless $text =~ /^http/;
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /^http/ 7 5 12
327 12 $parser->add( sprintf('<a href="%s">%s</a>',$href,$text) );
328 }elsif( $mode eq 'M' ){
329 12 my($real, $alt);
330 12 ▶ unless( ($real, $alt) = split /\|/, $text, 2 ){
Branch: 1 branch
BranchTrueFalseTotal
unless (() = split(/\|/, $text, 2)) 0 12 12
331 0 $real = $text;
332 }
333 12 ▶ $alt = $real if !defined $alt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $alt 11 1 12
334 12 ▶ if( $M_values_seen{$real}++ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($Pod::Advent::M_values_seen{$real}++) { } 2 10 12
335 2 $parser->add( sprintf('<span title="%s">%s</span>', $real, $alt) );
336 }else{
337 10 $parser->add( sprintf('<a href="http://search.cpan.org/perldoc?%s" title="%s">%s</a>',$real,$real, $alt) );
338 }
339 ▶ }elsif( $mode eq 'Data' && $section ){
Condition66%2/3
$mode eq "Data" and $Pod::Advent::section
!ll&&!rl&&r
195019
MC/DC50%1/2
$mode eq "Data" and $Pod::Advent::section
$mode eq "Data" $Pod::Advent::section
Truth table66%2/3
A and B
A= $mode eq "Data"B= $Pod::Advent::section
ABresult
0X0
100
111
340 19 $blocks{$section} .= $text . "\n\n";
341 }elsif( $mode eq 'F' ){
342 6 $out .= $text;
343 }elsif( $mode eq 'L' ){
344 7 $out .= $text;
345 }elsif( $mode eq 'D' ){
346 4 $out .= $text;
347 }else{
348 178 $parser->__spellcheck($text);
349 178 $out .= $text;
350 }
351 298 $parser->add( $out, undef );
352 }
353  
354 219 ▶sub __spellcheck {
Subroutine __spellcheck: called CC=5 SCAR=27.4
355 219 my $parser = shift;
356 219 my $text = shift;
357 219 ▶ return unless $parser->spellcheck_enabled;
Branch: 1 branch
BranchTrueFalseTotal
unless $parser->spellcheck_enabled 219 0 219
358 0 my $bad_ct = 0;
359 0 foreach my $word ( split /\W+/, $text ){
360 0 ▶ next if $speller->check( $word ) || $word =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Advent::speller->check($word) or $word =~ /^\d+$/ 0 0 0
Condition0%0/3
$Pod::Advent::speller->check($word) or $word =~ /^\d+$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$Pod::Advent::speller->check($word) or $word =~ /^\d+$/
$Pod::Advent::speller->check($word) $word =~ /^\d+$/
Truth table0%0/3
A or B
A= $Pod::Advent::speller->check($word)B= $word =~ /^\d+$/
ABresult
1X1
011
000
361 0 push @misspelled, $word;
362 0 $bad_ct++;
363 }
364 0 return $bad_ct;
365 }
366  
367 1 ▶sub spelling_errors {
Subroutine spelling_errors: called CC=1 SCAR=0.0
Pod documented
368 1 my $self = shift;
369 1 return @misspelled;
370 }
371  
372 8 ▶sub num_spelling_errors {
Subroutine num_spelling_errors: called CC=1 SCAR=0.0
Pod documented
373 8 my $self = shift;
374 8 return scalar @misspelled;
375 }
376  
377 17 1; # End of Pod::Advent
378  
379 #package Pod::Advent::Tidy;
380 #sub write_line {
381 # my ( $self, $line_of_tokens ) = @_;
382 # ${ $self->{dest} } .= sprintf q{<a name="%s.%s"></a>%4d %s},
383 # $self->{file},
384 # $line_of_tokens->{_line_number},
385 # $line_of_tokens->{_line_number},
386 # $line_of_tokens->{_line_text},
387 # ;
388 #}
389 #1;
390  
391 __END__
↑ Summary bin/pod2advent »