Simple/HTMLBatch.pm

filter: Statementstmt 88.7% 338 / 381 Branchbran 51.2% 82 / 160 Conditioncond 36.4% 35 / 96 MC/DCmcdc 1.7% 1 / 56 Subroutinesub 97.6% 41 / 42 Podpod 25.0% 4 / 16 totaltotal 66.7% 501 / 751 CC 127 SCAR 24.2
CC
127
Cov
71%
go
56.0
_batch_convert_main
27.6
batch_convert
26.5
CRAP 11.2
« Simple/HTML.pm ↑ Summary Simple/LinkSection.pm »
1 package Pod::Simple::HTMLBatch;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 our $VERSION = '3.48';
4 2 our @ISA = (); # Yup, we're NOT a subclass of Pod::Simple::HTML!
5  
6 # TODO: nocontents stylesheets. Strike some of the color variations?
7  
8 2 ▶use Pod::Simple::HTML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶BEGIN {*esc = \&Pod::Simple::HTML::esc }
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Pod::Simple::Search;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶our $SEARCH_CLASS ||= 'Pod::Simple::Search';
Condition50%1/2
our $SEARCH_CLASS ||= "Pod::Simple::Search"
l!l
02
MC/DC0%0/1
our $SEARCH_CLASS ||= "Pod::Simple::Search"
our $SEARCH_CLASS
Truth table50%1/2
A
A= our $SEARCH_CLASS
Aresult
11
00
14  
15 2 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=13.1
16 2 ▶ if(defined &DEBUG) { } # no-op
Branch: 2 branches
BranchTrueFalseTotal
if (defined &Pod::Simple::HTMLBatch::DEBUG) { } 0 2 2
elsif (defined &Pod::Simple::DEBUG) { } 2 0 2
17 2 elsif( defined &Pod::Simple::DEBUG ) { *DEBUG = \&Pod::Simple::DEBUG }
18 0 else { *DEBUG = sub () {0}; }
19 }
20  
21 2 our $SLEEPY;
22 2 ▶$SLEEPY = 1 if !defined $SLEEPY and $^O =~ /mswin|mac/i;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $Pod::Simple::HTMLBatch::SLEEPY and $^O =~ /mswin|mac/i 0 2 2
Condition33%1/3
not defined $Pod::Simple::HTMLBatch::SLEEPY and $^O =~ /mswin|mac/i
!ll&&!rl&&r
020
MC/DC0%0/2
not defined $Pod::Simple::HTMLBatch::SLEEPY and $^O =~ /mswin|mac/i
not defined $Pod::Simple::HTMLBatch::SLEEPY $^O =~ /mswin|mac/i
Truth table33%1/3
not(A) and B
A= not defined $Pod::Simple::HTMLBatch::SLEEPYB= $^O =~ /mswin|mac/i
ABresult
0X0
100
111
23 # flag to occasionally sleep for $SLEEPY - 1 seconds.
24  
25 2 ▶our $HTML_RENDER_CLASS ||= "Pod::Simple::HTML";
Condition50%1/2
our $HTML_RENDER_CLASS ||= "Pod::Simple::HTML"
l!l
02
MC/DC0%0/1
our $HTML_RENDER_CLASS ||= "Pod::Simple::HTML"
our $HTML_RENDER_CLASS
Truth table50%1/2
A
A= our $HTML_RENDER_CLASS
Aresult
11
00
26 2 our $HTML_EXTENSION;
27  
28 #
29 # Methods beginning with "_" are particularly internal and possibly ugly.
30 #
31  
32 2 Pod::Simple::_accessorize( __PACKAGE__,
33 'verbose', # how verbose to be during batch conversion
34 'html_render_class', # what class to use to render
35 'search_class', # what to use to search for POD documents
36 'contents_file', # If set, should be the name of a file (in current directory)
37 # to write the list of all modules to
38 'index', # will set $htmlpage->index(...) to this (true or false)
39 'progress', # progress object
40 'contents_page_start', 'contents_page_end',
41  
42 'css_flurry', '_css_wad', 'javascript_flurry', '_javascript_wad',
43 'no_contents_links', # set to true to suppress automatic adding of << links.
44 '_contents',
45 );
46  
47 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
48 # Just so we can run from the command line more easily
49 0 ▶sub go {
Subroutine go: not called CC=7 SCAR=40.3
Pod undocumented
50 0 ▶ @ARGV == 2 or die sprintf(
Branch: 1 branch
BranchTrueFalseTotal
@ARGV == 2 or die "Usage: perl -MPod::Simple::HTMLBatch -e Pod::Simple::HTMLBatch:go indirs outdir\n (or use \"\@INC\" for indirs)\n" 0 0 0
51 "Usage: perl -M%s -e %s:go indirs outdir\n (or use \"\@INC\" for indirs)\n",
52 __PACKAGE__, __PACKAGE__,
53 );
54  
55 0 ▶ if(defined($ARGV[1]) and length($ARGV[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ARGV[1] and length $ARGV[1]) 0 0 0
Condition0%0/3
defined $ARGV[1] and length $ARGV[1]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ARGV[1] and length $ARGV[1]
defined $ARGV[1] length $ARGV[1]
Truth table0%0/3
A and B
A= defined $ARGV[1]B= length $ARGV[1]
ABresult
0X0
100
111
56 0 my $d = $ARGV[1];
57 0 ▶ -e $d or die "I see no output directory named \"$d\"\nAborting";
Branch: 1 branch
BranchTrueFalseTotal
-e $d or die qq[I see no output directory named "$d"\nAborting] 0 0 0
58 0 ▶ -d $d or die "But \"$d\" isn't a directory!\nAborting";
Branch: 1 branch
BranchTrueFalseTotal
-d $d or die qq[But "$d" isn't a directory!\nAborting] 0 0 0
59 0 ▶ -w $d or die "Directory \"$d\" isn't writeable!\nAborting";
Branch: 1 branch
BranchTrueFalseTotal
-w $d or die qq[Directory "$d" isn't writeable!\nAborting] 0 0 0
60 }
61  
62 0 __PACKAGE__->batch_convert(@ARGV);
63 }
64 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
65  
66  
67 1 ▶sub new {
Subroutine new: called CC=5 SCAR=17.0
Pod documented
68 1 ▶ my $new = bless {}, ref($_[0]) || $_[0];
Condition33%1/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
69 1 $new->html_render_class($HTML_RENDER_CLASS);
70 1 $new->search_class($SEARCH_CLASS);
71 1 $new->verbose(1 + DEBUG);
72 1 $new->_contents([]);
73  
74 1 $new->index(1);
75  
76 1 $new-> _css_wad([]); $new->css_flurry(1);
77 1 $new->_javascript_wad([]); $new->javascript_flurry(1);
78  
79 1 ▶ $new->contents_file(
Condition33%1/3
$Pod::Simple::HTMLBatch::HTML_EXTENSION || $Pod::Simple::HTML::HTML_EXTENSION
l!l&&r!l&&!r
010
MC/DC0%0/2
$Pod::Simple::HTMLBatch::HTML_EXTENSION || $Pod::Simple::HTML::HTML_EXTENSION
$Pod::Simple::HTMLBatch::HTML_EXTENSION $Pod::Simple::HTML::HTML_EXTENSION
Truth table33%1/3
A || B
A= $Pod::Simple::HTMLBatch::HTML_EXTENSIONB= $Pod::Simple::HTML::HTML_EXTENSION
ABresult
1X1
011
000
80 'index' . ($HTML_EXTENSION || $Pod::Simple::HTML::HTML_EXTENSION)
81 );
82  
83 1 $new->contents_page_start( join "\n", grep $_,
84 $Pod::Simple::HTML::Doctype_decl,
85 "<html><head>",
86 "<title>Perl Documentation</title>",
87 $Pod::Simple::HTML::Content_decl,
88 "</head>",
89 "\n<body class='contentspage'>\n<h1>Perl Documentation</h1>\n"
90 ); # override if you need a different title
91  
92  
93 $new->contents_page_end( sprintf(
94 "\n\n<p class='contentsfooty'>Generated by %s v%s under Perl v%s\n<br >At %s GMT.</p>\n\n</body></html>\n",
95 esc(
96 ref($new),
97 1 ▶ eval {$new->VERSION} || $VERSION,
Condition50%1/2
$ENV{'SOURCE_DATE_EPOCH'} || time
l!l
01
MC/DC0%0/1
$ENV{'SOURCE_DATE_EPOCH'} || time
$ENV{'SOURCE_DATE_EPOCH'}
Truth table50%1/2
A
A= $ENV{'SOURCE_DATE_EPOCH'}
Aresult
11
00
98 1 ▶ $], scalar(gmtime($ENV{SOURCE_DATE_EPOCH} || time)),
Condition33%1/3
eval { do { $new->VERSION } } || $Pod::Simple::HTMLBatch::VERSION
l!l&&r!l&&!r
100
MC/DC0%0/2
eval { do { $new->VERSION } } || $Pod::Simple::HTMLBatch::VERSION
eval { do { $new->VERSION } } $Pod::Simple::HTMLBatch::VERSION
Truth table33%1/3
A || B
A= eval { do { $new->VERSION } }B= $Pod::Simple::HTMLBatch::VERSION
ABresult
1X1
011
000
99 )));
100  
101 1 return $new;
102 }
103  
104 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
105  
106 10 ▶sub muse {
Subroutine muse: called CC=2 SCAR=7.6
Pod undocumented
107 10 my $self = shift;
108 10 ▶ if($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 10 10
109 0 print 'T+', int(time() - $self->{'_batch_start_time'}), "s: ", @_, "\n";
110 }
111 10 return 1;
112 }
113  
114 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
115  
116 1 ▶sub batch_convert {
Subroutine batch_convert: called CC=10 SCAR=32.8
Pod documented
117 1 my($self, $dirs, $outdir) = @_;
118 1 ▶ $self ||= __PACKAGE__; # tolerate being called as an optionless function
Condition50%1/2
$self ||= __PACKAGE__
l!l
10
MC/DC0%0/1
$self ||= __PACKAGE__
$self
Truth table50%1/2
A
A= $self
Aresult
11
00
119 1 ▶ $self = $self->new unless ref $self; # tolerate being used as a class method
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 1 1
120  
121 1 ▶ if(!defined($dirs) or $dirs eq '' or $dirs eq '@INC' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $dirs or $dirs eq '' or $dirs eq '@INC') { } 0 1 1
elsif (ref $dirs) { } 1 0 1
Condition33%2/6
not defined $dirs or $dirs eq "" or $dirs eq "\@INC"
l!l&&r!l&&!r
001
not defined $dirs or $dirs eq ""
l!l&&r!l&&!r
001
MC/DC0%0/3
not defined $dirs or $dirs eq "" or $dirs eq "\@INC"
not defined $dirs $dirs eq "" $dirs eq "\@INC"
Truth table25%1/4
not(A) or B or C
A= not defined $dirsB= $dirs eq ""C= $dirs eq "\@INC"
ABCresult
1XX1
01X1
0011
0000
122 0 $dirs = '';
123 } elsif(ref $dirs) {
124 # OK, it's an explicit set of dirs to scan, specified as an arrayref.
125 } else {
126 # OK, it's an explicit set of dirs to scan, specified as a
127 # string like "/thing:/also:/whatever/perl" (":"-delim, as usual)
128 # or, under MSWin, like "c:/thing;d:/also;c:/whatever/perl" (";"-delim!)
129 0 require Config;
130 0 ▶ my $ps = quotemeta( $Config::Config{'path_sep'} || ":" );
Condition0%0/2
$Config::Config{'path_sep'} || ':'
l!l
00
MC/DC0%0/1
$Config::Config{'path_sep'} || ':'
$Config::Config{'path_sep'}
Truth table0%0/2
A
A= $Config::Config{'path_sep'}
Aresult
11
00
131 0 $dirs = [ grep length($_), split qr/$ps/, $dirs ];
132 }
133  
134 1 ▶ $outdir = $self->filespecsys->curdir
Branch: 1 branch
BranchTrueFalseTotal
unless defined $outdir and length $outdir 0 1 1
Condition33%1/3
defined $outdir and length $outdir
!ll&&!rl&&r
001
MC/DC0%0/2
defined $outdir and length $outdir
defined $outdir length $outdir
Truth table33%1/3
A and B
A= defined $outdirB= length $outdir
ABresult
0X0
100
111
135 unless defined $outdir and length $outdir;
136  
137 1 $self->_batch_convert_main($dirs, $outdir);
138 }
139  
140 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
141  
142 1 ▶sub _batch_convert_main {
Subroutine _batch_convert_main: called CC=13 SCAR=33.2
143 1 my($self, $dirs, $outdir) = @_;
144 # $dirs is either false, or an arrayref.
145 # $outdir is a pathspec.
146  
147 1 ▶ $self->{'_batch_start_time'} ||= time();
Condition50%1/2
$self->{"_batch_start_time"} ||= time
l!l
01
MC/DC0%0/1
$self->{"_batch_start_time"} ||= time
$self->{"_batch_start_time"}
Truth table50%1/2
A
A= $self->{"_batch_start_time"}
Aresult
11
00
148  
149 1 $self->muse( "= ", scalar(localtime) );
150 1 $self->muse( "Starting batch conversion to \"$outdir\"" );
151  
152 1 my $progress = $self->progress;
153 1 ▶ if(!$progress and $self->verbose > 0 and $self->verbose() <= 5) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $progress and $self->verbose > 0 and $self->verbose <= 5) 0 1 1
Condition33%2/6
not $progress and $self->verbose > 0 and $self->verbose <= 5
!ll&&!rl&&r
100
not $progress and $self->verbose > 0
!ll&&!rl&&r
010
MC/DC0%0/3
not $progress and $self->verbose > 0 and $self->verbose <= 5
not $progress $self->verbose > 0 $self->verbose <= 5
Truth table25%1/4
not(A) and B and C
A= not $progressB= $self->verbose > 0C= $self->verbose <= 5
ABCresult
0XX0
10X0
1100
1111
154 0 require Pod::Simple::Progress;
155 0 ▶ $progress = Pod::Simple::Progress->new(
Branch: 2 branches
BranchTrueFalseTotal
$self->verbose < 2 ? : 0 0 0
$self->verbose == 2 ? : 0 0 0
156 ($self->verbose < 2) ? () # Default omission-delay
157 : ($self->verbose == 2) ? 1 # Reduce the omission-delay
158 : 0 # Eliminate the omission-delay
159 );
160 0 $self->progress($progress);
161 }
162  
163 1 ▶ if($dirs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirs) { } 1 0 1
164 1 $self->muse(scalar(@$dirs), " dirs to scan: @$dirs");
165 } else {
166 0 $self->muse("Scanning \@INC. This could take a minute or two.");
167 }
168 1 ▶ my $mod2path = $self->find_all_pods($dirs ? $dirs : ());
Branch: 1 branch
BranchTrueFalseTotal
$dirs ? : 1 0 1
169 1 $self->muse("Done scanning.");
170  
171 1 my $total = keys %$mod2path;
172 1 ▶ unless($total) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($total) 0 1 1
173 0 $self->muse("No pod found. Aborting batch conversion.\n");
174 0 return $self;
175 }
176  
177 1 ▶ $progress and $progress->goal($total);
Branch: 1 branch
BranchTrueFalseTotal
$progress and $progress->goal($total) 0 1 1
178 1 ▶ $self->muse("Now converting pod files to HTML.",
Branch: 1 branch
BranchTrueFalseTotal
$total > 25 ? : 0 1 1
179 ($total > 25) ? " This will take a while more." : ()
180 );
181  
182 1 $self->_spray_css( $outdir );
183 1 $self->_spray_javascript( $outdir );
184  
185 1 $self->_do_all_batch_conversions($mod2path, $outdir);
186  
187 $progress and $progress->done(sprintf (
188 1 ▶ "Done converting %d files.", $self->{"__batch_conv_page_count"}
Branch: 1 branch
BranchTrueFalseTotal
$progress and $progress->done(sprintf("Done converting %d files.", $self->{"__batch_conv_page_count"})) 0 1 1
189 ));
190 1 return $self->_batch_convert_finish($outdir);
191 0 return $self;
192 }
193  
194  
195 1 ▶sub _do_all_batch_conversions {
Subroutine _do_all_batch_conversions: called CC=3 SCAR=11.0
196 1 my($self, $mod2path, $outdir) = @_;
197 1 $self->{"__batch_conv_page_count"} = 0;
198  
199 1 foreach my $module (sort {lc($a) cmp lc($b)} keys %$mod2path) {
200 10 $self->_do_one_batch_conversion($module, $mod2path, $outdir);
201 10 ▶ sleep($SLEEPY - 1) if $SLEEPY;
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Simple::HTMLBatch::SLEEPY 0 10 10
202 }
203  
204 1 return;
205 }
206  
207 1 ▶sub _batch_convert_finish {
Subroutine _batch_convert_finish: called CC=2 SCAR=7.0
208 1 my($self, $outdir) = @_;
209 1 $self->write_contents_file($outdir);
210 1 $self->muse("Done with batch conversion. $$self{'__batch_conv_page_count'} files done.");
211 1 $self->muse( "= ", scalar(localtime) );
212 1 ▶ $self->progress and $self->progress->done("All done!");
Branch: 1 branch
BranchTrueFalseTotal
$self->progress and $self->progress->done("All done!") 0 1 1
213 1 return;
214 }
215  
216 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
217  
218 10 ▶sub _do_one_batch_conversion {
Subroutine _do_one_batch_conversion: called CC=10 SCAR=24.8
219 10 my($self, $module, $mod2path, $outdir, $outfile) = @_;
220  
221 10 my $retval;
222 10 my $total = scalar keys %$mod2path;
223 10 my $infile = $mod2path->{$module};
224 10 my @namelets = grep m/\S/, split "::", $module;
225 # this can stick around in the contents LoL
226 10 my $depth = scalar @namelets;
227 10 ▶ die "Contentless thingie?! $module $infile" unless @namelets; #sanity
Branch: 1 branch
BranchTrueFalseTotal
unless @namelets 0 10 10
228  
229 10 ▶ $outfile ||= do {
Condition33%1/3
$outfile ||= do { my(@n) = @namelets; $n[-1] .= $Pod::Simple::HTMLBatch::HTML_EXTENSION || $Pod::Simple::HTML::HTML_EXTENSION; $self->filespecsys->catfile($outdir, @n) }
l!l&&r!l&&!r
0100
MC/DC0%0/2
$outfile ||= do { my(@n) = @namelets; $n[-1] .= $Pod::Simple::HTMLBatch::HTML_EXTENSION || $Pod::Simple::HTML::HTML_EXTENSION; $self->filespecsys->catfile($outdir, @n) }
$outfile do { my(@n) = @namelets; $n[-1] .= $Pod::Simple::HTMLBatch::HTML_EXTENSION || $Pod::Simple::HTML::HTML_EXTENSION; $self->filespecsys->catfile($outdir, @n) }
Truth table33%1/3
A ||= B
A= $outfileB= do { my(@n) = @namelets; $n[-1] .= $Pod::Simple::HTMLBatch::HTML_EXTENSION || $Pod::Simple::HTML::HTML_EXTENSION; $self->filespecsys->catfile($outdir, @n) }
ABresult
1X1
011
000
230 10 my @n = @namelets;
231 10 ▶ $n[-1] .= $HTML_EXTENSION || $Pod::Simple::HTML::HTML_EXTENSION;
Condition33%1/3
$Pod::Simple::HTMLBatch::HTML_EXTENSION || $Pod::Simple::HTML::HTML_EXTENSION
l!l&&r!l&&!r
0100
MC/DC0%0/2
$Pod::Simple::HTMLBatch::HTML_EXTENSION || $Pod::Simple::HTML::HTML_EXTENSION
$Pod::Simple::HTMLBatch::HTML_EXTENSION $Pod::Simple::HTML::HTML_EXTENSION
Truth table33%1/3
A || B
A= $Pod::Simple::HTMLBatch::HTML_EXTENSIONB= $Pod::Simple::HTML::HTML_EXTENSION
ABresult
1X1
011
000
232 10 $self->filespecsys->catfile( $outdir, @n );
233 };
234  
235 10 my $progress = $self->progress;
236  
237 10 my $page = $self->html_render_class->new;
238 10 if(DEBUG > 5) {
239 $self->muse($self->{"__batch_conv_page_count"} + 1, "/$total: ",
240 ref($page), " render ($depth) $module => $outfile");
241 0 } elsif(DEBUG > 2) {
242 $self->muse($self->{"__batch_conv_page_count"} + 1, "/$total: $module => $outfile")
243 }
244  
245 # Give each class a chance to init the converter:
246 10 ▶ $page->batch_mode_page_object_init($self, $module, $infile, $outfile, $depth)
Branch: 1 branch
BranchTrueFalseTotal
if $page->can("batch_mode_page_object_init") 10 0 10
247 if $page->can('batch_mode_page_object_init');
248 # Init for the index (TOC), too.
249 10 ▶ $self->batch_mode_page_object_init($page, $module, $infile, $outfile, $depth)
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("batch_mode_page_object_init") 10 0 10
250 if $self->can('batch_mode_page_object_init');
251  
252 # Now get busy...
253 10 $self->makepath($outdir => \@namelets);
254  
255 10 ▶ $progress and $progress->reach($self->{"__batch_conv_page_count"}, "Rendering $module");
Branch: 1 branch
BranchTrueFalseTotal
$progress and $progress->reach($self->{"__batch_conv_page_count"}, "Rendering $module") 0 10 10
256  
257 10 ▶ if( $retval = $page->parse_from_file($infile, $outfile) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retval = $page->parse_from_file($infile, $outfile)) { } 10 0 10
258 10 ++ $self->{"__batch_conv_page_count"} ;
259 10 $self->note_for_contents_file( \@namelets, $infile, $outfile );
260 } else {
261 0 $self->muse("Odd, parse_from_file(\"$infile\", \"$outfile\") returned false.");
262 }
263  
264 10 ▶ $page->batch_mode_page_object_kill($self, $module, $infile, $outfile, $depth)
Branch: 1 branch
BranchTrueFalseTotal
if $page->can("batch_mode_page_object_kill") 0 10 10
265 if $page->can('batch_mode_page_object_kill');
266 # The following isn't a typo. Note that it switches $self and $page.
267 10 ▶ $self->batch_mode_page_object_kill($page, $module, $infile, $outfile, $depth)
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("batch_mode_page_object_kill") 0 10 10
268 if $self->can('batch_mode_page_object_kill');
269  
270 10 DEBUG > 4 and printf STDERR "%s %sb < $infile %s %sb\n",
271 $outfile, -s $outfile, $infile, -s $infile
272 ;
273  
274 10 undef($page);
275 10 return $retval;
276 }
277  
278 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
279 28 ▶sub filespecsys { $_[0]{'_filespecsys'} || 'File::Spec' }
Subroutine filespecsys: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"_filespecsys"} or "File::Spec" 0 28 28
280  
281 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
282  
283 10 ▶sub note_for_contents_file {
Subroutine note_for_contents_file: called CC=2 SCAR=7.0
Pod undocumented
284 10 my($self, $namelets, $infile, $outfile) = @_;
285  
286 # I think the infile and outfile parts are never used. -- SMB
287 # But it's handy to have them around for debugging.
288  
289 10 ▶ if( $self->contents_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->contents_file) 10 0 10
290 10 my $c = $self->_contents();
291 10 push @$c,
292 [ join("::", @$namelets), $infile, $outfile, $namelets ]
293 # 0 1 2 3
294 ;
295 10 DEBUG > 3 and print STDERR "Noting @$c[-1]\n";
296 }
297 10 return;
298 }
299  
300 #_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
301  
302 1 ▶sub write_contents_file {
Subroutine write_contents_file: called CC=3 SCAR=11.3
Pod undocumented
303 1 my($self, $outdir) = @_;
304 1 ▶ my $outfile = $self->_contents_filespec($outdir) || return;
Condition50%1/2
$self->_contents_filespec($outdir) || (return)
l!l
10
MC/DC0%0/1
$self->_contents_filespec($outdir) || (return)
$self->_contents_filespec($outdir)
Truth table50%1/2
A
A= $self->_contents_filespec($outdir)
Aresult
11
00
305  
306 1 $self->muse("Preparing list of modules for ToC");
307  
308 1 my($toplevel, # maps toplevelbit => [all submodules]
309 $toplevel_form_freq, # ends up being 'foo' => 'Foo'
310 ) = $self->_prep_contents_breakdown;
311  
312 1 my $Contents = eval { $self->_wopen($outfile) };
313 1 ▶ if( $Contents ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Contents) { } 1 0 1
314 1 $self->muse( "Writing contents file $outfile" );
315 } else {
316 0 warn "Couldn't write-open contents file $outfile: $!\nAbort writing to $outfile at all";
317 0 return;
318 }
319  
320 1 $self->_write_contents_start( $Contents, $outfile, );
321 1 $self->_write_contents_middle( $Contents, $outfile, $toplevel, $toplevel_form_freq );
322 1 $self->_write_contents_end( $Contents, $outfile, );
323 1 return $outfile;
324 }
325  
326 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
327  
328 1 ▶sub _write_contents_start {
Subroutine _write_contents_start: called CC=5 SCAR=17.6
329 1 my($self, $Contents, $outfile) = @_;
330 1 ▶ my $starter = $self->contents_page_start || '';
Condition50%1/2
$self->contents_page_start || ''
l!l
10
MC/DC0%0/1
$self->contents_page_start || ''
$self->contents_page_start
Truth table50%1/2
A
A= $self->contents_page_start
Aresult
11
00
331  
332 {
333 1 my $css_wad = $self->_css_wad_to_markup(1);
334 1 ▶ if( $css_wad ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($css_wad) 1 0 1
335 1 $starter =~ s{(</head>)}{\n$css_wad\n$1}i; # otherwise nevermind
336 }
337  
338 1 my $javascript_wad = $self->_javascript_wad_to_markup(1);
339 1 ▶ if( $javascript_wad ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($javascript_wad) 1 0 1
340 1 $starter =~ s{(</head>)}{\n$javascript_wad\n$1}i; # otherwise nevermind
341 }
342 }
343  
344 1 ▶ unless(print $Contents $starter, "<dl class='superindex'>\n" ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (print $Contents $starter, "<dl class='superindex'>\n") 0 1 1
345 0 warn "Couldn't print to $outfile: $!\nAbort writing to $outfile at all";
346 0 close($Contents);
347 0 return 0;
348 }
349 1 return 1;
350 }
351  
352 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
353  
354 1 ▶sub _write_contents_middle {
Subroutine _write_contents_middle: called CC=4 SCAR=13.9
355 1 my($self, $Contents, $outfile, $toplevel2submodules, $toplevel_form_freq) = @_;
356  
357 1 foreach my $t (sort keys %$toplevel2submodules) {
358 5 my @downlines = sort {$a->[-1] cmp $b->[-1]}
359 6 @{ $toplevel2submodules->{$t} };
360  
361 printf $Contents qq[<dt><a name="%s">%s</a></dt>\n<dd>\n],
362 6 esc( $t, $toplevel_form_freq->{$t} )
363 ;
364  
365 6 my($path, $name);
366 6 foreach my $e (@downlines) {
367 10 $name = $e->[0];
368 10 ▶ $path = join( "/", '.', esc( @{$e->[3]} ) )
Condition33%1/3
$Pod::Simple::HTMLBatch::HTML_EXTENSION || $Pod::Simple::HTML::HTML_EXTENSION
l!l&&r!l&&!r
0100
MC/DC0%0/2
$Pod::Simple::HTMLBatch::HTML_EXTENSION || $Pod::Simple::HTML::HTML_EXTENSION
$Pod::Simple::HTMLBatch::HTML_EXTENSION $Pod::Simple::HTML::HTML_EXTENSION
Truth table33%1/3
A || B
A= $Pod::Simple::HTMLBatch::HTML_EXTENSIONB= $Pod::Simple::HTML::HTML_EXTENSION
ABresult
1X1
011
000
369 . ($HTML_EXTENSION || $Pod::Simple::HTML::HTML_EXTENSION);
370 10 print $Contents qq{ <a href="$path">}, esc($name), "</a>&nbsp;&nbsp;\n";
371 }
372 6 print $Contents "</dd>\n\n";
373 }
374 1 return 1;
375 }
376  
377 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
378  
379 1 ▶sub _write_contents_end {
Subroutine _write_contents_end: called CC=4 SCAR=15.6
380 1 my($self, $Contents, $outfile) = @_;
381 1 ▶ unless(
Branch: 1 branch
BranchTrueFalseTotal
unless (print $Contents "</dl>\n", $self->contents_page_end || "") 0 1 1
Condition50%1/2
$self->contents_page_end || ''
l!l
10
MC/DC0%0/1
$self->contents_page_end || ''
$self->contents_page_end
Truth table50%1/2
A
A= $self->contents_page_end
Aresult
11
00
382 print $Contents "</dl>\n",
383 $self->contents_page_end || '',
384 ) {
385 0 warn "Couldn't write to $outfile: $!";
386 }
387 1 ▶ close($Contents) or warn "Couldn't close $outfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $Contents or warn "Couldn't close ${outfile}: $!" 1 0 1
388 1 return 1;
389 }
390  
391 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
392  
393 1 ▶sub _prep_contents_breakdown {
Subroutine _prep_contents_breakdown: called CC=6 SCAR=19.1
394 1 my($self) = @_;
395 1 my $contents = $self->_contents;
396 1 my %toplevel; # maps lctoplevelbit => [all submodules]
397 my %toplevel_form_freq; # ends up being 'foo' => 'Foo'
398 # (mapping anycase forms to most freq form)
399  
400 1 foreach my $entry (@$contents) {
401 10 ▶ my $toplevel =
Branch: 1 branch
BranchTrueFalseTotal
$entry->[0] =~ /^perl\w*$/ ? : 2 8 10
402 $entry->[0] =~ m/^perl\w*$/ ? 'perl_core_docs'
403 # group all the perlwhatever docs together
404 : $entry->[3][0] # normal case
405 ;
406 10 ++$toplevel_form_freq{ lc $toplevel }{ $toplevel };
407 10 push @{ $toplevel{ lc $toplevel } }, $entry;
408 10 push @$entry, lc($entry->[0]); # add a sort-order key to the end
409 }
410  
411 1 foreach my $toplevel (sort keys %toplevel) {
412 6 my $fgroup = $toplevel_form_freq{$toplevel};
413 $toplevel_form_freq{$toplevel} =
414 (
415 0 ▶ sort { $fgroup->{$b} <=> $fgroup->{$a} or $a cmp $b }
Condition0%0/3
$fgroup->{$b} <=> $fgroup->{$a} || $a cmp $b
l!l&&r!l&&!r
000
MC/DC0%0/2
$fgroup->{$b} <=> $fgroup->{$a} || $a cmp $b
$fgroup->{$b} <=> $fgroup->{$a} $a cmp $b
Truth table0%0/3
A || B
A= $fgroup->{$b} <=> $fgroup->{$a}B= $a cmp $b
ABresult
1X1
011
000
416 keys %$fgroup
417 # This hash is extremely unlikely to have more than 4 members, so this
418 # sort isn't so very wasteful
419 )[0];
420 }
421  
422 1 ▶ return(\%toplevel, \%toplevel_form_freq) if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 1 0 1
423 0 return \%toplevel;
424 }
425  
426 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
427  
428 1 ▶sub _contents_filespec {
Subroutine _contents_filespec: called CC=2 SCAR=7.0
429 1 my($self, $outdir) = @_;
430 1 my $outfile = $self->contents_file;
431 1 ▶ return unless $outfile;
Branch: 1 branch
BranchTrueFalseTotal
unless $outfile 0 1 1
432 1 return $self->filespecsys->catfile( $outdir, $outfile );
433 }
434  
435 #_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
436  
437 10 ▶sub makepath {
Subroutine makepath: called CC=6 SCAR=18.0
Pod undocumented
438 10 my($self, $outdir, $namelets) = @_;
439 10 ▶ return unless @$namelets > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$namelets > 1 5 5 10
440 5 for my $i (0 .. ($#$namelets - 1)) {
441 5 my $dir = $self->filespecsys->catdir( $outdir, @$namelets[0 .. $i] );
442 5 ▶ if(-e $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $dir) 2 3 5
443 2 ▶ die "$dir exists but not as a directory!?" unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 2 2
444 2 next;
445 }
446 3 DEBUG > 3 and print STDERR " Making $dir\n";
447 3 ▶ mkdir $dir, 0777
Branch: 1 branch
BranchTrueFalseTotal
mkdir $dir, 511 or die "Can't mkdir ${dir}: $!\nAborting" 3 0 3
448 or die "Can't mkdir $dir: $!\nAborting"
449 ;
450 }
451 5 return;
452 }
453  
454 #_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
455  
456 10 ▶sub batch_mode_page_object_init {
Subroutine batch_mode_page_object_init: called CC=1 SCAR=0.0
Pod undocumented
457 10 my $self = shift;
458 10 my($page, $module, $infile, $outfile, $depth) = @_;
459  
460 # TODO: any further options to percolate onto this new object here?
461  
462 10 $page->default_title($module);
463 10 $page->index( $self->index );
464  
465 10 $page->html_css( $self-> _css_wad_to_markup($depth) );
466 10 $page->html_javascript( $self->_javascript_wad_to_markup($depth) );
467  
468 10 $self->add_header_backlink($page, $module, $infile, $outfile, $depth);
469 10 $self->add_footer_backlink($page, $module, $infile, $outfile, $depth);
470  
471  
472 10 return $self;
473 }
474  
475 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
476  
477 10 ▶sub add_header_backlink {
Subroutine add_header_backlink: called CC=4 SCAR=14.6
Pod undocumented
478 10 my $self = shift;
479 10 ▶ return if $self->no_contents_links;
Branch: 1 branch
BranchTrueFalseTotal
if $self->no_contents_links 0 10 10
480 10 my($page, $module, $infile, $outfile, $depth) = @_;
481 10 ▶ $page->html_header_after_title( join '',
Branch: 1 branch
BranchTrueFalseTotal
if $self->contents_file 10 0 10
Condition50%1/2
$page->html_header_after_title || ''
l!l
100
MC/DC0%0/1
$page->html_header_after_title || ''
$page->html_header_after_title
Truth table50%1/2
A
A= $page->html_header_after_title
Aresult
11
00
482 $page->html_header_after_title || '',
483  
484 qq[<p class="backlinktop"><b><a name="___top" href="],
485 $self->url_up_to_contents($depth),
486 qq[" accesskey="1" title="All Documents">&lt;&lt;</a></b></p>\n],
487 )
488 if $self->contents_file
489 ;
490 10 return;
491 }
492  
493 10 ▶sub add_footer_backlink {
Subroutine add_footer_backlink: called CC=4 SCAR=14.6
Pod undocumented
494 10 my $self = shift;
495 10 ▶ return if $self->no_contents_links;
Branch: 1 branch
BranchTrueFalseTotal
if $self->no_contents_links 0 10 10
496 10 my($page, $module, $infile, $outfile, $depth) = @_;
497 10 ▶ $page->html_footer( join '',
Branch: 1 branch
BranchTrueFalseTotal
if $self->contents_file 10 0 10
Condition50%1/2
$page->html_footer || ''
l!l
100
MC/DC0%0/1
$page->html_footer || ''
$page->html_footer
Truth table50%1/2
A
A= $page->html_footer
Aresult
11
00
498 qq[<p class="backlinkbottom"><b><a name="___bottom" href="],
499 $self->url_up_to_contents($depth),
500 qq[" title="All Documents">&lt;&lt;</a></b></p>\n],
501  
502 $page->html_footer || '',
503 )
504 if $self->contents_file
505 ;
506 10 return;
507 }
508  
509 20 ▶sub url_up_to_contents {
Subroutine url_up_to_contents: called CC=1 SCAR=0.0
Pod undocumented
510 20 my($self, $depth) = @_;
511 20 --$depth;
512 20 return join '/', ('..') x $depth, esc($self->contents_file);
513 }
514  
515 #_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
516  
517 1 ▶sub find_all_pods {
Subroutine find_all_pods: called CC=1 SCAR=0.0
Pod undocumented
518 1 my($self, $dirs) = @_;
519 # You can override find_all_pods in a subclass if you want to
520 # do extra filtering or whatnot. But for the moment, we just
521 # pass to modnames2paths:
522 1 return $self->modnames2paths($dirs);
523 }
524  
525 #_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
526  
527 1 ▶sub modnames2paths { # return a hashref mapping modulenames => paths
Subroutine modnames2paths: called CC=6 SCAR=18.6
Pod undocumented
528 1 my($self, $dirs) = @_;
529  
530 1 my $m2p;
531 {
532 1 my $search = $self->search_class->new;
533 1 DEBUG and print STDERR "Searching via $search\n";
534 1 $search->verbose(1) if DEBUG > 10;
535 1 ▶ $search->progress( $self->progress->copy->goal(0) ) if $self->progress;
Branch: 1 branch
BranchTrueFalseTotal
if $self->progress 0 1 1
536 1 $search->shadows(0); # don't bother noting shadowed files
537 1 ▶ $search->inc( $dirs ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$dirs ? : 1 0 1
538 1 ▶ $search->survey( $dirs ? @$dirs : () );
Branch: 1 branch
BranchTrueFalseTotal
$dirs ? : 1 0 1
539 1 $m2p = $search->name2path;
540 1 ▶ die "What, no name2path?!" unless $m2p;
Branch: 1 branch
BranchTrueFalseTotal
unless $m2p 0 1 1
541 }
542  
543 1 ▶ $self->muse("That's odd... no modules found!") unless keys %$m2p;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$m2p 0 1 1
544 1 if( DEBUG > 4 ) {
545 print STDERR "Modules found (name => path):\n";
546 foreach my $m (sort {lc($a) cmp lc($b)} keys %$m2p) {
547 print STDERR " $m $$m2p{$m}\n";
548 }
549 print STDERR "(total ", scalar(keys %$m2p), ")\n\n";
550 0 } elsif( DEBUG ) {
551 print STDERR "Found ", scalar(keys %$m2p), " modules.\n";
552 }
553 1 $self->muse( "Found ", scalar(keys %$m2p), " modules." );
554  
555 # return the Foo::Bar => /whatever/Foo/Bar.pod|pm hashref
556 1 return $m2p;
557 }
558  
559 #===========================================================================
560  
561 13 ▶sub _wopen {
Subroutine _wopen: called CC=2 SCAR=7.6
562 # this is abstracted out so that the daemon class can override it
563 13 my($self, $outpath) = @_;
564 13 require Symbol;
565 13 my $out_fh = Symbol::gensym();
566 13 DEBUG > 5 and print STDERR "Write-opening to $outpath\n";
567 13 ▶ return $out_fh if open($out_fh, "> $outpath");
Branch: 1 branch
BranchTrueFalseTotal
if open $out_fh, "> $outpath" 13 0 13
568 0 require Carp;
569 0 Carp::croak("Can't write-open $outpath: $!");
570 }
571  
572 #==========================================================================
573  
574 11 ▶sub add_css {
Subroutine add_css: called CC=8 SCAR=28.2
Pod documented
575 11 my($self, $url, $is_default, $name, $content_type, $media, $_code) = @_;
576 11 ▶ return unless $url;
Branch: 1 branch
BranchTrueFalseTotal
unless $url 0 11 11
577 11 ▶ unless($name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name) 0 11 11
578 # cook up a reasonable name based on the URL
579 0 $name = $url;
580 0 ▶ if( $name !~ m/\?/ and $name =~ m{([^/]+)$}s ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $name =~ /\?/ and $name =~ m[([^/]+)$]s) 0 0 0
Condition0%0/3
not $name =~ /\?/ and $name =~ m[([^/]+)$]s
!ll&&!rl&&r
000
MC/DC0%0/2
not $name =~ /\?/ and $name =~ m[([^/]+)$]s
not $name =~ /\?/ $name =~ m[([^/]+)$]s
Truth table0%0/3
not(A) and B
A= not $name =~ /\?/B= $name =~ m[([^/]+)$]s
ABresult
0X0
100
111
581 0 $name = $1;
582 0 $name =~ s/\.css//i;
583 }
584 }
585 11 ▶ $media ||= 'all';
Condition50%1/2
$media ||= "all"
l!l
011
MC/DC0%0/1
$media ||= "all"
$media
Truth table50%1/2
A
A= $media
Aresult
11
00
586 11 ▶ $content_type ||= 'text/css';
Condition50%1/2
$content_type ||= "text/css"
l!l
011
MC/DC0%0/1
$content_type ||= "text/css"
$content_type
Truth table50%1/2
A
A= $content_type
Aresult
11
00
587  
588 11 my $bunch = [$url, $name, $content_type, $media, $_code];
589 0 ▶ if($is_default) { unshift @{ $self->_css_wad }, $bunch }
Branch: 1 branch
BranchTrueFalseTotal
if ($is_default) { } 0 11 11
590 11 else { push @{ $self->_css_wad }, $bunch }
591 11 return;
592 }
593  
594 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
595  
596 1 ▶sub _spray_css {
Subroutine _spray_css: called CC=6 SCAR=18.9
597 1 my($self, $outdir) = @_;
598  
599 1 ▶ return unless $self->css_flurry();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->css_flurry 0 1 1
600 1 $self->_gen_css_wad();
601  
602 1 my $lol = $self->_css_wad;
603 1 foreach my $chunk (@$lol) {
604 11 my $url = $chunk->[0];
605 11 my $outfile;
606 11 ▶ if( ref($chunk->[-1]) and $url =~ m{^(_[-a-z0-9_]+\.css$)} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $chunk->[-1] and $url =~ /^(_[-a-z0-9_]+\.css$)/) { } 11 0 11
Condition33%1/3
ref $chunk->[-1] and $url =~ /^(_[-a-z0-9_]+\.css$)/
!ll&&!rl&&r
0011
MC/DC0%0/2
ref $chunk->[-1] and $url =~ /^(_[-a-z0-9_]+\.css$)/
ref $chunk->[-1] $url =~ /^(_[-a-z0-9_]+\.css$)/
Truth table33%1/3
A and B
A= ref $chunk->[-1]B= $url =~ /^(_[-a-z0-9_]+\.css$)/
ABresult
0X0
100
111
607 11 $outfile = $self->filespecsys->catfile( $outdir, "$1" );
608 11 DEBUG > 5 and print STDERR "Noting $$chunk[0] as a file I'll create.\n";
609 } else {
610 0 DEBUG > 5 and print STDERR "OK, noting $$chunk[0] as an external CSS.\n";
611 # Requires no further attention.
612 0 next;
613 }
614  
615 #$self->muse( "Writing autogenerated CSS file $outfile" );
616 11 my $Cssout = $self->_wopen($outfile);
617 11 ▶ print $Cssout ${$chunk->[-1]}
Branch: 1 branch
BranchTrueFalseTotal
print $Cssout ${$chunk->[-1];} or warn "Couldn't print to ${outfile}: $!\nAbort writing to $outfile at all" 11 0 11
618 or warn "Couldn't print to $outfile: $!\nAbort writing to $outfile at all";
619 11 close($Cssout);
620 11 DEBUG > 5 and print STDERR "Wrote $outfile\n";
621 }
622  
623 1 return;
624 }
625  
626 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
627  
628 11 ▶sub _css_wad_to_markup {
Subroutine _css_wad_to_markup: called CC=7 SCAR=20.0
629 11 my($self, $depth) = @_;
630  
631 11 ▶ my @css = @{ $self->_css_wad || return '' };
Condition50%1/2
$self->_css_wad || (return '')
l!l
110
MC/DC0%0/1
$self->_css_wad || (return '')
$self->_css_wad
Truth table50%1/2
A
A= $self->_css_wad
Aresult
11
00
632 11 ▶ return '' unless @css;
Branch: 1 branch
BranchTrueFalseTotal
unless @css 0 11 11
633  
634 11 my $rel = 'stylesheet';
635 11 my $out = '';
636  
637 11 --$depth;
638 11 ▶ my $uplink = $depth ? ('../' x $depth) : '';
Branch: 1 branch
BranchTrueFalseTotal
$depth ? : 5 6 11
639  
640 11 foreach my $chunk (@css) {
641 121 ▶ next unless $chunk and @$chunk;
Branch: 1 branch
BranchTrueFalseTotal
unless $chunk and @$chunk 0 121 121
Condition33%1/3
$chunk and @$chunk
!ll&&!rl&&r
00121
MC/DC0%0/2
$chunk and @$chunk
$chunk @$chunk
Truth table33%1/3
A and B
A= $chunkB= @$chunk
ABresult
0X0
100
111
642  
643 121 my( $url1, $url2, $title, $type, $media) = (
644 $self->_maybe_uplink( $chunk->[0], $uplink ),
645 esc(grep !ref($_), @$chunk)
646 );
647  
648 121 $out .= qq{<link rel="$rel" title="$title" type="$type" href="$url1$url2" media="$media" >\n};
649  
650 121 $rel = 'alternate stylesheet'; # alternates = all non-first iterations
651 }
652 11 return $out;
653 }
654  
655 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
656 132 ▶sub _maybe_uplink {
Subroutine _maybe_uplink: called CC=3 SCAR=13.1
657 # if the given URL looks relative, return the given uplink string --
658 # otherwise return emptystring
659 132 my($self, $url, $uplink) = @_;
660 132 ▶ ($url =~ m{^\./} or $url !~ m{[/\:]} )
Branch: 1 branch
BranchTrueFalseTotal
$url =~ m[^\./] || !($url =~ m[[/\:]]) ? : 132 0 132
Condition33%1/3
$url =~ m[^\./] or not $url =~ m[[/\:]]
l!l&&r!l&&!r
01320
MC/DC0%0/2
$url =~ m[^\./] or not $url =~ m[[/\:]]
$url =~ m[^\./] not $url =~ m[[/\:]]
Truth table33%1/3
A or not(B)
A= $url =~ m[^\./]B= not $url =~ m[[/\:]]
ABresult
1X1
011
000
661 ? $uplink
662 : ''
663 # qualify it, if/as needed
664 }
665  
666 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
667 1 ▶sub _gen_css_wad {
Subroutine _gen_css_wad: called CC=10 SCAR=23.0
668 1 my $self = $_[0];
669 1 my $css_template = $self->_css_template;
670 1 foreach my $variation (
671  
672 # Commented out for sake of concision:
673 #
674 # 011n=black_with_red_on_white
675 # 001n=black_with_yellow_on_white
676 # 101n=black_with_green_on_white
677 # 110=white_with_yellow_on_black
678 # 010=white_with_green_on_black
679 # 011=white_with_blue_on_black
680 # 100=white_with_red_on_black
681 '110n=blkbluw', # black_with_blue_on_white
682 '010n=blkmagw', # black_with_magenta_on_white
683 '100n=blkcynw', # black_with_cyan_on_white
684 '101=whtprpk', # white_with_purple_on_black
685 '001=whtnavk', # white_with_navy_blue_on_black
686 '010a=grygrnk', # grey_with_green_on_black
687 '010b=whtgrng', # white_with_green_on_grey
688 '101an=blkgrng', # black_with_green_on_grey
689 '101bn=grygrnw', # grey_with_green_on_white
690 ) {
691  
692 9 my $outname = $variation;
693 9 ▶ my($flipmode, @swap) = ( ($4 || ''), $1,$2,$3)
Branch: 1 branch
BranchTrueFalseTotal
if $outname =~ s/^([012])([012])([[012])([a-z]*)=?//s 9 0 9
Condition100%2/2
$4 || ''
l!l
72
MC/DC100%1/1
$4 || ''
$4
Truth table100%2/2
A
A= $4
Aresult
11
00
694 if $outname =~ s/^([012])([012])([[012])([a-z]*)=?//s;
695 9 ▶ @swap = () if '010' eq join '', @swap; # 010 is a swop-no-op!
Branch: 1 branch
BranchTrueFalseTotal
if "010" eq join("", @swap) 3 6 9
696  
697 9 my $this_css =
698 "/* This file is autogenerated. Do not edit. $variation */\n\n"
699 . $css_template;
700  
701 # Only look at three-digitty colors, for now at least.
702 9 ▶ if( $flipmode =~ m/n/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flipmode =~ /n/) 5 4 9
703 5 $this_css =~ s/(#[0-9a-fA-F]{3})\b/_color_negate($1)/eg;
704 5 $this_css =~ s/\bthin\b/medium/g;
705 }
706 9 ▶ $this_css =~ s<#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])\b>
Branch: 1 branch
BranchTrueFalseTotal
if @swap 6 3 9
707 132 < join '', '#', ($1,$2,$3)[@swap] >eg if @swap;
708  
709 9 ▶ if( $flipmode =~ m/a/)
Branch: 2 branches
BranchTrueFalseTotal
if ($flipmode =~ /a/) { } 2 7 9
elsif ($flipmode =~ /b/) { } 2 5 7
710 2 { $this_css =~ s/#fff\b/#999/gi } # black -> dark grey
711 elsif($flipmode =~ m/b/)
712 2 { $this_css =~ s/#000\b/#666/gi } # white -> light grey
713  
714 9 my $name = $outname;
715 9 $name =~ tr/-_/ /;
716 9 $self->add_css( "_$outname.css", 0, $name, 0, 0, \$this_css);
717 }
718  
719 # Now a few indexless variations:
720 1 my %variations = (
721 blkbluw => 'black_with_blue_on_white',
722 whtpurk => 'white_with_purple_on_black',
723 whtgrng => 'white_with_green_on_grey',
724 grygrnw => 'grey_with_green_on_white',
725 );
726 1 for (my ($outfile, $variation) = each %variations) {
727 2 my $this_css = join "\n",
728 "/* This file is autogenerated. Do not edit. $outfile */\n",
729 "\@import url(\"./_$variation.css\");",
730 ".indexgroup { display: none; }",
731 "\n",
732 ;
733 2 my $name = $outfile;
734 2 $name =~ tr/-_/ /;
735 2 $self->add_css( "_$outfile.css", 0, $name, 0, 0, \$this_css);
736 }
737  
738 1 return;
739 }
740  
741 110 ▶sub _color_negate {
Subroutine _color_negate: called CC=1 SCAR=0.0
742 110 my $x = lc $_[0];
743 110 $x =~ tr[0123456789abcdef]
744 [fedcba9876543210];
745 110 return $x;
746 }
747  
748 #===========================================================================
749  
750 1 ▶sub add_javascript {
Subroutine add_javascript: called CC=3 SCAR=11.3
Pod documented
751 1 my($self, $url, $content_type, $_code) = @_;
752 1 ▶ return unless $url;
Branch: 1 branch
BranchTrueFalseTotal
unless $url 0 1 1
753 1 ▶ push @{ $self->_javascript_wad }, [
Condition50%1/2
$content_type || 'text/javascript'
l!l
01
MC/DC0%0/1
$content_type || 'text/javascript'
$content_type
Truth table50%1/2
A
A= $content_type
Aresult
11
00
754 $url, $content_type || 'text/javascript', $_code
755 ];
756 1 return;
757 }
758  
759 1 ▶sub _spray_javascript {
Subroutine _spray_javascript: called CC=6 SCAR=18.9
760 1 my($self, $outdir) = @_;
761 1 ▶ return unless $self->javascript_flurry();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->javascript_flurry 0 1 1
762 1 $self->_gen_javascript_wad();
763  
764 1 my $lol = $self->_javascript_wad;
765 1 foreach my $script (@$lol) {
766 1 my $url = $script->[0];
767 1 my $outfile;
768  
769 1 ▶ if( ref($script->[-1]) and $url =~ m{^(_[-a-z0-9_]+\.js$)} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $script->[-1] and $url =~ /^(_[-a-z0-9_]+\.js$)/) { } 1 0 1
Condition33%1/3
ref $script->[-1] and $url =~ /^(_[-a-z0-9_]+\.js$)/
!ll&&!rl&&r
001
MC/DC0%0/2
ref $script->[-1] and $url =~ /^(_[-a-z0-9_]+\.js$)/
ref $script->[-1] $url =~ /^(_[-a-z0-9_]+\.js$)/
Truth table33%1/3
A and B
A= ref $script->[-1]B= $url =~ /^(_[-a-z0-9_]+\.js$)/
ABresult
0X0
100
111
770 1 $outfile = $self->filespecsys->catfile( $outdir, "$1" );
771 1 DEBUG > 5 and print STDERR "Noting $$script[0] as a file I'll create.\n";
772 } else {
773 0 DEBUG > 5 and print STDERR "OK, noting $$script[0] as an external JavaScript.\n";
774 0 next;
775 }
776  
777 #$self->muse( "Writing JavaScript file $outfile" );
778 1 my $Jsout = $self->_wopen($outfile);
779  
780 1 ▶ print $Jsout ${$script->[-1]}
Branch: 1 branch
BranchTrueFalseTotal
print $Jsout ${$script->[-1];} or warn "Couldn't print to ${outfile}: $!\nAbort writing to $outfile at all" 1 0 1
781 or warn "Couldn't print to $outfile: $!\nAbort writing to $outfile at all";
782 1 close($Jsout);
783 1 DEBUG > 5 and print STDERR "Wrote $outfile\n";
784 }
785  
786 1 return;
787 }
788  
789 1 ▶sub _gen_javascript_wad {
Subroutine _gen_javascript_wad: called CC=2 SCAR=7.0
790 1 my $self = $_[0];
791 1 ▶ my $js_code = $self->_javascript || return;
Condition50%1/2
$self->_javascript || (return)
l!l
10
MC/DC0%0/1
$self->_javascript || (return)
$self->_javascript
Truth table50%1/2
A
A= $self->_javascript
Aresult
11
00
792 1 $self->add_javascript( "_podly.js", 0, \$js_code);
793 1 return;
794 }
795  
796 11 ▶sub _javascript_wad_to_markup {
Subroutine _javascript_wad_to_markup: called CC=7 SCAR=20.2
797 11 my($self, $depth) = @_;
798  
799 11 ▶ my @scripts = @{ $self->_javascript_wad || return '' };
Condition50%1/2
$self->_javascript_wad || (return '')
l!l
110
MC/DC0%0/1
$self->_javascript_wad || (return '')
$self->_javascript_wad
Truth table50%1/2
A
A= $self->_javascript_wad
Aresult
11
00
800 11 ▶ return '' unless @scripts;
Branch: 1 branch
BranchTrueFalseTotal
unless @scripts 0 11 11
801  
802 11 my $out = '';
803  
804 11 --$depth;
805 11 ▶ my $uplink = $depth ? ('../' x $depth) : '';
Branch: 1 branch
BranchTrueFalseTotal
$depth ? : 5 6 11
806  
807 11 foreach my $s (@scripts) {
808 11 ▶ next unless $s and @$s;
Branch: 1 branch
BranchTrueFalseTotal
unless $s and @$s 0 11 11
Condition33%1/3
$s and @$s
!ll&&!rl&&r
0011
MC/DC0%0/2
$s and @$s
$s @$s
Truth table33%1/3
A and B
A= $sB= @$s
ABresult
0X0
100
111
809  
810 11 my( $url1, $url2, $type, $media) = (
811 $self->_maybe_uplink( $s->[0], $uplink ),
812 esc(grep !ref($_), @$s)
813 );
814  
815 11 $out .= qq{<script type="$type" src="$url1$url2"></script>\n};
816 }
817 11 return $out;
818 }
819  
820 #===========================================================================
821  
822 2 our $CSS = <<'EOCSS';
823 /* For accessibility reasons, never specify text sizes in px/pt/pc/in/cm/mm */
824  
825 @media all { .hide { display: none; } }
826  
827 @media print {
828 .noprint, div.indexgroup, .backlinktop, .backlinkbottom { display: none }
829  
830 * {
831 border-color: black !important;
832 color: black !important;
833 background-color: transparent !important;
834 background-image: none !important;
835 }
836  
837 dl.superindex > dd {
838 word-spacing: .6em;
839 }
840 }
841  
842 @media aural, braille, embossed {
843 div.indexgroup { display: none; } /* Too noisy, don't you think? */
844 dl.superindex > dt:before { content: "Group "; }
845 dl.superindex > dt:after { content: " contains:"; }
846 .backlinktop a:before { content: "Back to contents"; }
847 .backlinkbottom a:before { content: "Back to contents"; }
848 }
849  
850 @media aural {
851 dl.superindex > dt { pause-before: 600ms; }
852 }
853  
854 @media screen, tty, tv, projection {
855 .noscreen { display: none; }
856  
857 a:link { color: #7070ff; text-decoration: underline; }
858 a:visited { color: #e030ff; text-decoration: underline; }
859 a:active { color: #800000; text-decoration: underline; }
860 body.contentspage a { text-decoration: none; }
861 a.u { color: #fff !important; text-decoration: none; }
862  
863 body.pod {
864 margin: 0 5px;
865 color: #fff;
866 background-color: #000;
867 }
868  
869 body.pod h1, body.pod h2, body.pod h3,
870 body.pod h4, body.pod h5, body.pod h6 {
871 font-family: Tahoma, Verdana, Helvetica, Arial, sans-serif;
872 font-weight: normal;
873 margin-top: 1.2em;
874 margin-bottom: .1em;
875 border-top: thin solid transparent;
876 /* margin-left: -5px; border-left: 2px #7070ff solid; padding-left: 3px; */
877 }
878  
879 body.pod h1 { border-top-color: #0a0; }
880 body.pod h2 { border-top-color: #080; }
881 body.pod h3 { border-top-color: #040; }
882 body.pod h4 { border-top-color: #010; }
883 body.pod h5 { border-top-color: #010; }
884 body.pod h6 { border-top-color: #010; }
885  
886 p.backlinktop + h1 { border-top: none; margin-top: 0em; }
887 p.backlinktop + h2 { border-top: none; margin-top: 0em; }
888 p.backlinktop + h3 { border-top: none; margin-top: 0em; }
889 p.backlinktop + h4 { border-top: none; margin-top: 0em; }
890 p.backlinktop + h5 { border-top: none; margin-top: 0em; }
891 p.backlinktop + h6 { border-top: none; margin-top: 0em; }
892  
893 body.pod dt {
894 font-size: 105%; /* just a wee bit more than normal */
895 }
896  
897 .indexgroup { font-size: 80%; }
898  
899 .backlinktop, .backlinkbottom {
900 margin-left: -5px;
901 margin-right: -5px;
902 background-color: #040;
903 border-top: thin solid #050;
904 border-bottom: thin solid #050;
905 }
906  
907 .backlinktop a, .backlinkbottom a {
908 text-decoration: none;
909 color: #080;
910 background-color: #000;
911 border: thin solid #0d0;
912 }
913 .backlinkbottom { margin-bottom: 0; padding-bottom: 0; }
914 .backlinktop { margin-top: 0; padding-top: 0; }
915  
916 body.contentspage {
917 color: #fff;
918 background-color: #000;
919 }
920  
921 body.contentspage h1 {
922 color: #0d0;
923 margin-left: 1em;
924 margin-right: 1em;
925 text-indent: -.9em;
926 font-family: Tahoma, Verdana, Helvetica, Arial, sans-serif;
927 font-weight: normal;
928 border-top: thin solid #fff;
929 border-bottom: thin solid #fff;
930 text-align: center;
931 }
932  
933 dl.superindex > dt {
934 font-family: Tahoma, Verdana, Helvetica, Arial, sans-serif;
935 font-weight: normal;
936 font-size: 90%;
937 margin-top: .45em;
938 /* margin-bottom: -.15em; */
939 }
940 dl.superindex > dd {
941 word-spacing: .6em; /* most important rule here! */
942 }
943 dl.superindex > a:link {
944 text-decoration: none;
945 color: #fff;
946 }
947  
948 .contentsfooty {
949 border-top: thin solid #999;
950 font-size: 90%;
951 }
952  
953 }
954  
955 /* The End */
956  
957 EOCSS
958  
959 #==========================================================================
960  
961 2 our $JAVASCRIPT = <<'EOJAVASCRIPT';
962  
963 // From http://www.alistapart.com/articles/alternate/
964  
965 function setActiveStyleSheet(title) {
966 var i, a, main;
967 for(i=0 ; (a = document.getElementsByTagName("link")[i]) ; i++) {
968 if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
969 a.disabled = true;
970 if(a.getAttribute("title") == title) a.disabled = false;
971 }
972 }
973 }
974  
975 function getActiveStyleSheet() {
976 var i, a;
977 for(i=0 ; (a = document.getElementsByTagName("link")[i]) ; i++) {
978 if( a.getAttribute("rel").indexOf("style") != -1
979 && a.getAttribute("title")
980 && !a.disabled
981 ) return a.getAttribute("title");
982 }
983 return null;
984 }
985  
986 function getPreferredStyleSheet() {
987 var i, a;
988 for(i=0 ; (a = document.getElementsByTagName("link")[i]) ; i++) {
989 if( a.getAttribute("rel").indexOf("style") != -1
990 && a.getAttribute("rel").indexOf("alt") == -1
991 && a.getAttribute("title")
992 ) return a.getAttribute("title");
993 }
994 return null;
995 }
996  
997 function createCookie(name,value,days) {
998 if (days) {
999 var date = new Date();
1000 date.setTime(date.getTime()+(days*24*60*60*1000));
1001 var expires = "; expires="+date.toGMTString();
1002 }
1003 else expires = "";
1004 document.cookie = name+"="+value+expires+"; path=/";
1005 }
1006  
1007 function readCookie(name) {
1008 var nameEQ = name + "=";
1009 var ca = document.cookie.split(';');
1010 for(var i=0 ; i < ca.length ; i++) {
1011 var c = ca[i];
1012 while (c.charAt(0)==' ') c = c.substring(1,c.length);
1013 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
1014 }
1015 return null;
1016 }
1017  
1018 window.onload = function(e) {
1019 var cookie = readCookie("style");
1020 var title = cookie ? cookie : getPreferredStyleSheet();
1021 setActiveStyleSheet(title);
1022 }
1023  
1024 window.onunload = function(e) {
1025 var title = getActiveStyleSheet();
1026 createCookie("style", title, 365);
1027 }
1028  
1029 var cookie = readCookie("style");
1030 var title = cookie ? cookie : getPreferredStyleSheet();
1031 setActiveStyleSheet(title);
1032  
1033 // The End
1034  
1035 EOJAVASCRIPT
1036  
1037 1 ▶sub _css_template { return $CSS }
Subroutine _css_template: called CC=1 SCAR=0.0
1038 1 ▶sub _javascript { return $JAVASCRIPT }
Subroutine _javascript: called CC=1 SCAR=0.0
1039  
1040 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1041 2 1;
1042 __END__
« Simple/HTML.pm ↑ Summary Simple/LinkSection.pm »