blib/lib/Pod/Inherit.pm

filter: Statementstmt 85.5% 350 / 409 Branchbran 66.0% 169 / 256 Conditioncond 61.9% 44 / 71 MC/DCmcdc 24.3% 10 / 41 Subroutinesub 83.3% 35 / 42 Podpod 75.0% 3 / 4 totaltotal 74.2% 611 / 823 CC 170 SCAR 39.3
CC
170
Cov
76%
create_pod
109.5
write_pod
43.6
_any_to_type_array
26.6
CRAP 50.8
↑ Summary
1 # *sigh* Pod::Tree does this with a simple get_deep_text method...
2  
3 ### TODO: This should probably be its own distro ###
4 package Pod::POM::View::TextStrip;
5  
6 6 ▶use parent 'Pod::POM::View::Text';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 ▶sub view_seq_bold { $_[1] }
Subroutine view_seq_bold: not called CC=1 SCAR=6.9
9 0 ▶sub view_seq_italic { $_[1] }
Subroutine view_seq_italic: not called CC=1 SCAR=6.9
10 1 ▶sub view_seq_code { $_[1] }
Subroutine view_seq_code: called CC=1 SCAR=0.0
11 0 ▶sub view_seq_file { $_[1] }
Subroutine view_seq_file: not called CC=1 SCAR=6.9
12 0 ▶sub view_verbatim { $_[1] }
Subroutine view_verbatim: not called CC=1 SCAR=6.9
13 0 ▶sub view_seq_link {
Subroutine view_seq_link: not called CC=1 SCAR=6.9
14 0 my ($self, $link) = @_;
15 0 $link =~ s/^.*?\|//;
16 0 return $link;
17 }
18  
19 6 1;
20  
21 package Pod::Inherit;
22  
23 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 6 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 ▶use Sub::Identify;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 6 ▶use Pod::POM;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 6 ▶use List::AllUtils qw(any first firstidx);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 6 ▶use Class::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 6 our $DEBUG = 0;
34  
35 # Eww, monkeypatching. Also, eww, replacing Perl's exception handling... poorly.
36 6 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
37 6 delete $Pod::POM::Node::{error};
38 }
39 0 ▶sub Pod::POM::Node::error {
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
40 0 my ($self, @rest) = @_;
41 0 print STDERR Carp::longmess;
42 0 die "->error on Pod::POM::Node: @rest";
43 }
44  
45 6 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 6 ▶use Scalar::Util 'refaddr';
Subroutine BEGIN: called CC=1 SCAR=0.0
47 6 our $VERSION = '0.91';
48  
49 =head1 NAME
50  
51 Pod::Inherit - auto-create POD sections listing inherited methods
52  
53 =head1 SYNOPSIS
54  
55 use Pod::Inherit;
56  
57 my $config = {
58 out_dir => "/usr/src/perl/dbix-class/bast/DBIx-Class/0.08/trunk/doc",
59 input_files => ['/usr/src/perl/dbix-class/bast/DBIx-Class/0.08/trunk/lib/'],
60 skip_underscored => 1,
61 class_map => {
62 'DBIx::Class::Relationship::HasMany' => 'DBIx::Class::Relationship',
63 'DBIx::Class::Relationship::HasOne' => 'DBIx::Class::Relationship',
64 'DBIx::Class::Relationship::BelongsTo' => 'DBIx::Class::Relationship',
65 'DBIx::Class::Relationship::ManyToMany' => 'DBIx::Class::Relationship',
66 'DBIx::Class::ResultSourceProxy' => 'DBIx::Class::ResultSource',
67 'DBIx::Class::ResultSourceProxy::Table' => 'DBIx::Class::ResultSource',
68 },
69 skip_classes => [
70 'lib/DBIx/Class/Serialize/Storable.pm',
71 'DBIx::Class::Serialize::Storable',
72 ],
73 skip_inherits => [ qw/
74 DBIx::Class::Componentised
75 Class::C3::Componentised
76 / ],
77 force_inherits => {
78 'lib/DBIx/Class/ResultClass.pod' => 'DBIx::Class::Core',
79 'DBIx::Class::AccessorGroup' => [
80 'Class::Accessor',
81 'Class::Accessor::Grouped'
82 ]
83 },
84 method_format => 'L<%m|%c/%m>',
85 dead_links => '',
86 debug => 1,
87 };
88  
89 my $pi = Pod::Inherit->new( $config });
90 $pi->write_pod;
91  
92 =head1 DESCRIPTION
93  
94 Ever written a module distribution with base classes and dependencies,
95 that had the POD for the various methods next to them, but hard to
96 find for the user of your modules? Ever wished POD could be
97 inheritable? Now it can.
98  
99 This module will B<load> each of the classes in the list of input
100 files or directories given (default: C<@ARGV>), auto-discover which
101 methods each class provides, locate the actual class the method is
102 defined in, and produce a list in POD.
103  
104 The resulting documentation is written out to a separate F<.pod> file
105 for each class (F<.pm>) encountered. The new file contains the
106 original POD from the Perl Module file, plus a section called
107 C<INHERITED METHODS>. The new section lists each class that the
108 current class inherits from, plus each method that can be used in the
109 current class as a result.
110  
111 By default, methods beginning with an underscore, C<_> are skipped, as
112 by convention these are private methods.
113  
114 =head2 METHODS
115  
116 =head3 new
117  
118 =over
119  
120 =item B<Arguments:> \%config
121  
122 =item B<Return Value:> Pod::Inherit object
123  
124 =back
125  
126 Create a new Pod::Inherit object.
127  
128 =head3 \%config
129  
130 The config hashref can contain the following keys:
131  
132 =head4 skip_underscored
133  
134 =over
135  
136 =item B<Input:> boolean
137  
138 =item B<Default:> true
139  
140 =back
141  
142 Do not display inherited methods that begin with an underscore. Set to
143 0 to display these as well.
144  
145 =head4 input_files
146  
147 =over
148  
149 =item B<Input:> [ @directories ] | $directory
150  
151 =item B<Default:> [ @ARGV ]
152  
153 =back
154  
155 Arrayref of directories to search for F<.pm> files in, or a list of
156 F<.pm> files or a mixture.
157  
158 =head4 out_dir
159  
160 =over
161  
162 =item B<Input:> $directory
163  
164 =item B<Default:> Same as input_files
165  
166 =back
167  
168 A directory to output the results into. If not supplied, the F<.pod>
169 file is created alongside the F<.pm> file it came from.
170  
171 =head4 force_permissions
172  
173 =over
174  
175 =item B<Input:> boolean
176  
177 =item B<Default:> false
178  
179 =back
180  
181 ExtUtils::MakeMaker makes directories in blib read-only before we'd
182 like to write into them. If this is set to a true value, we'll catch
183 permission denied errors, and try to make the directory writeable,
184 write the file, and then set it back to how it was before.
185  
186 =head4 class_map
187  
188 =over
189  
190 =item B<Input:> { $class_only => $class_only, ... }
191  
192 =item B<Default:> none
193  
194 =back
195  
196 The keys represent classes in which inherited methods will be found;
197 the values are the classes which it should link to in the new POD for
198 the actual POD of the methods.
199  
200 Some distributions will already have noticed the plight of the users,
201 and documented the methods of some of their base classes further up
202 the inheritance chain. This config option lets you tell Pod::Inherit
203 where you moved the POD to.
204  
205 =head4 skip_classes
206  
207 =over
208  
209 =item B<Input:> [ @class_or_pm_files ] | $class_or_pm_file
210  
211 =item B<Default:> none
212  
213 =back
214  
215 Any class/file found in the list will be skipped for POD creation.
216  
217 =head4 skip_inherits
218  
219 =over
220  
221 =item B<Input:> [ @classes_only ] | $classes_only
222  
223 =item B<Default:> none
224  
225 =back
226  
227 This is a list of classes that shouldn't show up in any of the
228 C<INHERITED METHODS> sections. Good candidates include:
229  
230 Class::C3::Componentised
231 Any other *::Componentised
232 Class::Accessor::Grouped
233 Moose::Object or most Moose stuff
234 Exporter
235  
236 =head4 force_inherits
237  
238 =over
239  
240 =item B<Input:> { $class_or_pmpod_file => $class_only | [ @classes_only ], ... }
241  
242 =item B<Default:> none
243  
244 =back
245  
246 A hashref of arrayrefs. Like the opposite of skip_inherits, this
247 will forcefully add the classes listed to the C<INHERITED METHODS>
248 sections, except this will only work on a per-class basis. The keys
249 represent the classes affected; the values are arrayrefs (or single
250 strings) specifying which classes to add.
251  
252 In order to access the methods for the new modules, we'll need to
253 load them manually after the main class is loaded. If there are
254 some sort of weird conflicts, this may cause undesirable results.
255 Also, any methods that the NEW module inherits will also be added
256 to the method list.
257  
258 You can also use this option to add a C<INHERITED METHODS> to a
259 separate POD file. Note that this is the B<only> case where a POD
260 would get loaded and read, since it really can't work otherwise.
261 Also, be sure to specify a different output directory, else you will
262 likely overwrite your existing POD.
263  
264 =head4 method_format
265  
266 =over
267  
268 =item B<Input:> $format_string
269  
270 =item B<Default:> '%m'
271  
272 =back
273  
274 A string with a few custom percent-encoded variables. This string
275 will be used on each method name found when writing the new POD
276 section. The custom variables are:
277  
278 %m = method name
279 %c = class name
280 %% = literal percent sign
281  
282 Thus, the default just prints out the method name, unaltered.
283  
284 This string can be used to add method links to the POD files (like
285 C<'LZ<><%m|%c/%m>'>), or to change the formatting (like C<'CZ<><%m>'>).
286  
287 =head4 dead_links
288  
289 =over
290  
291 =item B<Input:> $format_string
292  
293 =item B<Default:> undef
294  
295 =back
296  
297 A string with the same format as C<method_format>. This is the
298 string used for methods that don't exist in the inherited module's
299 documentation. A blank string (C<''>) will remove any dead links.
300 The default is to not check for dead links.
301  
302 This option typically only makes sense if C<method_format> is a
303 link, but it can be used to automatically remove undocumented
304 methods or present them in a different manner.
305  
306 =head4 debug
307  
308 =over
309  
310 =item B<Input:> 0|1|2
311  
312 =item B<Default:> 0
313  
314 =back
315  
316 A debug level of 1 will print out a managable level of debug
317 information per module. To get POD outputs, set this to 2.
318  
319 This used to be set with C<$Pod::Inherit::DEBUG>, but this property
320 is now preferred. However, the old method still works for
321 backwards-compatibility.
322  
323 =cut
324  
325 27 ▶sub new {
Subroutine new: called CC=14 SCAR=30.0
Pod documented
326 27 my ($class, $args) = @_;
327 $args = {
328 skip_underscored => 1,
329 input_files => [], # \@ARGV,
330 out_dir => '',
331 class_map => {},
332 skip_classes => [],
333 skip_inherits => [],
334 force_inherits => {},
335 method_format => '%m',
336 27 ▶ %{ $args || {} },
Condition50%1/2
$args || {}
l!l
270
MC/DC0%0/1
$args || {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
337 };
338  
339 27 ▶ $DEBUG = $args->{debug} || 0;
Condition50%1/2
$args->{'debug'} || 0
l!l
027
MC/DC0%0/1
$args->{'debug'} || 0
$args->{'debug'}
Truth table50%1/2
A
A= $args->{'debug'}
Aresult
11
00
340 27 ▶ if ($DEBUG >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Pod::Inherit::DEBUG >= 2) 0 27 27
341 0 require Data::Dump::Streamer;
342 0 Data::Dump::Streamer->import('Dump');
343 }
344  
345 # Accept just a single filename in here -- OR A SINGLE Path::Class::File!
346 27 for (qw/input_files skip_classes skip_inherits/) {
347 81 ▶ $args->{$_} = [$args->{$_}] if not ref($args->{$_}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args->{$_} eq "ARRAY" 4 77 81
348 }
349 27 ▶ if (my $fi = $args->{force_inherits}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fi = $args->{"force_inherits"}) 27 0 27
350 27 for (keys %$fi) {
351 4 ▶ $fi->{$_} = [$fi->{$_}] if not ref($fi->{$_}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $fi->{$_} eq "ARRAY" 2 2 4
352 }
353 }
354  
355 27 my $self = bless($args, $class);
356  
357 # deep cleaning of the "any" types: skip_classes & force_inherits keys
358 27 @{$self->{skip_classes}} = grep { ref } map { $self->_any_to_type_array($_, 0, 'skip_classes'); } @{$self->{skip_classes}};
359  
360 27 ▶ if (my $fi = $self->{force_inherits}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fi = $self->{"force_inherits"}) 27 0 27
361 27 $self->{force_inherits_type} = {}; # we can't just put an ARRAYREF on a key
362 27 my @fi_keys = keys %$fi;
363  
364 27 foreach my $dest_doc (@fi_keys) {
365 4 my $type_any = $self->_any_to_type_array($dest_doc, 1, 'force_inherits keys');
366 4 ▶ unless ($type_any) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type_any) 0 4 4
367 0 delete $fi->{$dest_doc};
368 0 next;
369 }
370  
371 4 my ($type, $any) = @$type_any;
372 4 $self->{force_inherits_type}{$any} = $type;
373  
374 # need to delete the old key after adding the new one
375 4 ▶ if ($dest_doc ne $any) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dest_doc ne $any) 0 4 4
376 # if $fi->{$any} already exists, combine them
377 0 ▶ $fi->{$any} = $fi->{$any} ? [ @{$fi->{$any}}, @{$fi->{$dest_doc}} ] : $fi->{$dest_doc};
Branch: 1 branch
BranchTrueFalseTotal
$fi->{$any} ? : 0 0 0
378 0 delete $fi->{$dest_doc};
379 }
380 }
381 }
382  
383 27 return $self;
384 }
385  
386 =head3 write_pod
387  
388 =over
389  
390 =item B<Arguments:> none
391  
392 =item B<Return Value:> 1 on success
393  
394 =back
395  
396 Run the pod creation stage.
397  
398 =cut
399  
400 27 ▶sub write_pod {
Subroutine write_pod: called CC=29 SCAR=37.8
Pod documented
401 27 my ($self) = @_;
402  
403 27 my ($fi, $fit) = ($self->{force_inherits}, $self->{force_inherits_type});
404 my @targets = map {
405 # The origtarget needs to be a directory; if it's a file, lie and claim to the rest
406 # of the code that the user passed the directory containing this file.
407 26 ▶ -d $_ ? [$_, $_] : [$_, Path::Class::File->new($_)->dir]
Branch: 1 branch
BranchTrueFalseTotal
-d $_ ? : 3 23 26
408 27 } @{ $self->{input_files} };
409  
410 27 ▶ die "no targets" if (!@targets);
Branch: 1 branch
BranchTrueFalseTotal
unless @targets 1 26 27
411  
412 26 ▶ while (@targets) {
Branch: 1 branch
BranchTrueFalseTotal
if (@targets) 102 25 127
413 102 my ($target, $origtarget) = @{shift @targets};
414 102 ▶ print "target=$target origtarget=$origtarget \n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 102 102
415  
416 102 ▶ my $filename = (-d $target ? Path::Class::Dir->new($target) : Path::Class::File->new($target))->cleanup->resolve;
Branch: 1 branch
BranchTrueFalseTotal
-d $target ? : 8 94 102
417 101 my $classname = $self->_pure_filename_to_classname( $filename->relative($origtarget) );
418  
419 # Check skip list before we do anything
420 101 ▶ if ( my $skipped = first { $self->_match_filename_to_type_array($classname, $filename, $_); } @{$self->{skip_classes}} ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (my $skipped = &first(sub { $self->_match_filename_to_type_array($classname, $filename, $_); } , @{$$self{"skip_classes"};})) 6 95 101
421 6 ▶ print " target skipped per skip_classes: ".(ref $skipped ? $skipped->[1] : $skipped)."\n" if ($DEBUG);
Branch: 2 branches
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 6 6
ref $skipped ? : 0 0 0
422 6 next;
423 }
424  
425 95 ▶ if (-d $target) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $target) 6 89 95
426 6 ▶ print " directory: adding children as new targets\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 6 6
427 6 unshift @targets, map { [$_, $origtarget] } ($filename->children);
428 6 next;
429 }
430  
431 89 my $should_process = 0;
432 89 ▶ $should_process = 1 if ($target =~ m/\.pm$/);
Branch: 1 branch
BranchTrueFalseTotal
if $target =~ /\.pm$/ 77 12 89
433 89 ▶ if ($target =~ m/\.pod$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target =~ /\.pod$/) 9 80 89
434 9 ▶ print " POD: found\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 9 9
435 9 ▶ if (my $forced = first { $self->_match_filename_to_type_array($classname, $filename, [$fit->{$_}, $_]); } keys %$fi) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (my $forced = &first(sub { $self->_match_filename_to_type_array($classname, $filename, [$fit->{$_}, $_]); } , keys %$fi)) 4 5 9
436 4 ▶ print " POD: processing due to force_inherits match: $forced\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 4 4
437 4 $should_process = 1;
438 }
439 }
440  
441 89 ▶ if ($should_process) {
Branch: 1 branch
BranchTrueFalseTotal
if ($should_process) 81 8 89
442 81 ▶ my $output_filename = $self->{out_dir} ? $filename->relative($origtarget)->absolute($self->{out_dir}) : $filename;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'out_dir'} ? : 69 12 81
443  
444 81 $output_filename =~ s/\.pm$/.pod/;
445 81 $output_filename = Path::Class::File->new($output_filename);
446  
447 81 ▶ if ($self->_is_ours($output_filename)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_ours($output_filename)) 80 1 81
448 80 my $allpod = $self->create_pod($target, $origtarget);
449 # Don't create the output file if there would be nothing in it!
450 80 ▶ if (!$allpod) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($allpod) 41 39 80
451 41 ▶ print " not creating empty file $output_filename\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 41 41
452 41 next;
453 }
454  
455 39 my $dir = $output_filename->dir;
456 39 my $ret = $dir->mkpath;
457  
458 39 my ($outfh, $oldperm);
459 39 ▶ print " Writing $output_filename\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 39 39
460 39 ▶ unless ( $outfh = $output_filename->open('w') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($outfh = $output_filename->open("w")) 0 39 39
461 0 ▶ if ($!{EACCES} and $self->{force_permissions} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($!{'EACCES'} and $self->{'force_permissions'}) { } 0 0 0
Condition0%0/3
$!{"EACCES"} and $self->{"force_permissions"}
!ll&&!rl&&r
000
MC/DC0%0/2
$!{"EACCES"} and $self->{"force_permissions"}
$!{"EACCES"} $self->{"force_permissions"}
Truth table0%0/3
A and B
A= $!{"EACCES"}B= $self->{"force_permissions"}
ABresult
0X0
100
111
462 0 $output_filename->remove;
463 0 $oldperm = $dir->stat->mode;
464 0 ▶ chmod $oldperm | 0200, $dir or die "Can't chmod ".$dir." (or write into it)";
Branch: 1 branch
BranchTrueFalseTotal
chmod $oldperm | 128, $dir or die q[Can't chmod ] . $dir . ' (or write into it)' 0 0 0
465 0 ▶ $outfh = $output_filename->open('w') or die "Can't open $output_filename for output (even after chmodding it's parent directory): $!";
Branch: 1 branch
BranchTrueFalseTotal
$outfh = $output_filename->open("w") or die "Can't open $output_filename for output (even after chmodding it's parent directory): $!" 0 0 0
466 } else {
467 0 die "Can't open $output_filename for output: $!";
468 }
469 }
470  
471 39 $outfh->print($allpod);
472 39 $outfh->close;
473 39 ▶ if (defined $oldperm) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $oldperm) 0 39 39
474 0 ▶ chmod $oldperm, $dir or die sprintf "Can't chmod %s back to 0%o", $dir, $oldperm;
Branch: 1 branch
BranchTrueFalseTotal
chmod $oldperm, $dir or die sprintf("Can't chmod %s back to 0%o", $dir, $oldperm) 0 0 0
475 }
476 }
477 }
478 }
479  
480 25 return 1;
481 }
482  
483 =pod
484  
485 =head3 create_pod
486  
487 =over
488  
489 =item B<Arguments:> $src, $root_dir?
490  
491 =item B<Return Value:> $pod_text | undef
492  
493 =back
494  
495 Creates a POD file. Actually, this just outputs the text of the
496 resulting file, so it's up to you to write this somewhere. If the POD
497 wouldn't produce a C<INHERITED METHODS>, this will return undef.
498  
499 Strange situations, such as non-existant files, do/require problems,
500 etc. will warn and return undef as well.
501  
502 The optional $root_dir would basically be whatever lib/blib directory
503 is in the $src, used mainly for POD->Class conversion. That part of
504 the directory would still need to be on $src.
505  
506 =cut
507  
508 80 ▶sub create_pod {
Subroutine create_pod: called CC=76 SCAR=47.0
Pod documented
509 80 my ($self, $src, $root_dir) = @_;
510 80 my $class_map = $self->{class_map};
511 80 ▶ die "create_pod needs a source file argument!" unless ($src);
Branch: 1 branch
BranchTrueFalseTotal
unless $src 0 80 80
512  
513 # Canonize src; not only does not doing it produce a minor testing & prettiness problem
514 # with the generated-data comment, far more importantly, it will keep require from
515 # knowing that t/lib//foo and t/lib/foo are the same library, leading to "redefined"
516 # warnings.
517 80 $src = Path::Class::File->new($src)->cleanup->resolve;
518  
519 80 my ($fi, $fit) = ($self->{force_inherits}, $self->{force_inherits_type});
520 80 my ($tt_stash, $classname, @isa_flattened);
521  
522 80 ▶ unless ($src =~ m/\.pod$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src =~ /\.pod$/) { } 4 76 80
523 76 ▶ $classname = $tt_stash->{classname} = $self->_require_class($src) || return;
Condition100%2/2
$self->_require_class($src) || (return)
l!l
733
MC/DC100%1/1
$self->_require_class($src) || (return)
$self->_require_class($src)
Truth table100%2/2
A
A= $self->_require_class($src)
Aresult
11
00
524 73 @isa_flattened = @{mro::get_linear_isa($classname)};
525 }
526 # here be PODs
527 else {
528 4 ▶ $classname = $tt_stash->{classname} = $self->_pure_filename_to_classname( $root_dir ? $src->relative($root_dir) : $src );
Branch: 1 branch
BranchTrueFalseTotal
$root_dir ? : 4 0 4
529 4 $self->_check_pod_sections($src, $classname);
530 }
531  
532 # Check for force inherits to add
533 77 ▶ my $force_inherits = (first { $self->_match_filename_to_type_array($classname, $src, [$fit->{$_}, $_]); } keys %$fi) || '';
Subroutine __ANON__: called CC=1 SCAR=0.0
Condition100%2/2
&first(sub { $self->_match_filename_to_type_array($classname, $src, [$fit->{$_}, $_]); } , keys %$fi) || ''
l!l
473
MC/DC100%1/1
&first(sub { $self->_match_filename_to_type_array($classname, $src, [$fit->{$_}, $_]); } , keys %$fi) || ''
&first(sub { $self->_match_filename_to_type_array($classname, $src, [$fit->{$_}, $_]); } , keys %$fi)
Truth table100%2/2
A
A= &first(sub { $self->_match_filename_to_type_array($classname, $src, [$fit->{$_}, $_]); } , keys %$fi)
Aresult
11
00
534 77 $force_inherits = $fi->{$force_inherits};
535 77 ▶ if ($force_inherits) {
Branch: 1 branch
BranchTrueFalseTotal
if ($force_inherits) 4 73 77
536 # Forced inherits still need to be loaded manually
537 4 foreach my $class (@$force_inherits) {
538 6 ▶ print " Found force inherit: $class\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 6 6
539 6 ▶ $self->_require_class(undef, $class) || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_require_class(undef, $class) or return 6 0 6
540 6 push @isa_flattened, @{mro::get_linear_isa($class)};
541 }
542 }
543  
544 # Now for ones to skip (including its own class)
545 77 foreach my $s ( @{ $self->{skip_inherits} }, $classname ) {
546 113 ▶ for (my $i = 0; $i < @isa_flattened; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @isa_flattened) 178 113 291
547 178 ▶ if ($s eq $isa_flattened[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s eq $isa_flattened[$i]) 81 97 178
548 81 ▶ print " Skipped per skip_inherits: $s\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 81 81
549 81 splice(@isa_flattened, $i--, 1);
550 }
551 }
552 }
553  
554 # We can't possibly find anything. Just short-circuit and save ourselves a lot of trouble.
555 77 ▶ if (!@isa_flattened) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@isa_flattened) 33 44 77
556 33 ▶ print " No parent classes\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 33 33
557 33 return;
558 }
559 44 $tt_stash->{isa_flattened} = \@isa_flattened;
560  
561 # Read POD sections for new classes
562 44 ▶ if (exists $self->{dead_links}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"dead_links"}) 6 38 44
563 6 foreach my $class (@isa_flattened) {
564 8 $self->_check_pod_sections(undef, $class);
565 }
566 }
567  
568 44 my %seen;
569 44 for my $parent_class (@isa_flattened) {
570 57 ▶ print " Parent class: $parent_class\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 57 57
571 57 my $stash;
572 {
573 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
574 57 $stash = \%{"$parent_class\::"};
575 }
576 # There's something subtle and brain-melting going on here, but I think it works.
577 57 my $local_config = $stash->{_pod_inherit_config};
578 57 ▶ if (not exists $local_config->{skip_underscored}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $local_config->{"skip_underscored"}) 45 12 57
579 45 $local_config->{skip_underscored} = $self->{skip_underscored};
580 }
581 57 ▶ $local_config->{class_map} ||= $class_map;
Condition66%2/3
$local_config->{"class_map"} ||= $class_map
l!l&&r!l&&!r
12450
MC/DC0%0/2
$local_config->{"class_map"} ||= $class_map
$local_config->{"class_map"} $class_map
Truth table66%2/3
A ||= B
A= $local_config->{"class_map"}B= $class_map
ABresult
1X1
011
000
582  
583 57 for my $globname (sort keys %$stash) {
584 170 ▶ next if ($local_config->{skip_underscored} and $globname =~ m/^_/);
Branch: 1 branch
BranchTrueFalseTotal
if $local_config->{"skip_underscored"} and $globname =~ /^_/ 9 161 170
Condition100%3/3
$local_config->{"skip_underscored"} and $globname =~ /^_/
!ll&&!rl&&r
85769
MC/DC100%2/2
$local_config->{"skip_underscored"} and $globname =~ /^_/
$local_config->{"skip_underscored"} $globname =~ /^_/
Truth table100%3/3
A and B
A= $local_config->{"skip_underscored"}B= $globname =~ /^_/
ABresult
0X0
100
111
585 161 ▶ next if $seen{$globname};
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$globname} 9 152 161
586  
587 # Skip the typical UPPERCASE sub blocks that aren't really user-friendly methods
588 152 ▶ next if ($globname =~ m/^(?:AUTOLOAD|CLONE|DESTROY|BEGIN|UNITCHECK|CHECK|INIT|END)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $globname =~ /^(?:AUTOLOAD|CLONE|DESTROY|BEGIN|UNITCHECK|CHECK|INIT|END)$/ 57 95 152
589  
590 95 my $glob = $stash->{$globname};
591 # Skip over things that aren't *code* globs, and cache entries.
592 # (You might think that ->can will return false for non-code globs. You'd be right. It'll return true
593 # for cache globs, and we want to skip those, so that we'll get them later.)
594 95 my $exists;
595 95 eval {
596 # Don't next here directly, it'll cause a warning.
597 95 $exists = exists &$glob;
598 };
599 95 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 95 95
600 # This specific error happens in DBIx::Class::Storage O_LARGEFILE, which is exported from IO::File
601 # (I loose track of exactly how...)
602 # Strange, considering O_LARGEFILE clearly *is* a subroutine...
603 0 ▶ if ($@ =~ /Not a subroutine reference/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ =~ /Not a subroutine reference/) { } 0 0 0
604 0 ▶ print " Got not a subref for $globname in $parent_class; it is probably imported accidentally.\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 0 0
605 0 $exists=0;
606 } else {
607 0 die "While checking if $parent_class $globname is a sub: $@";
608 }
609 }
610 95 ▶ next unless ($exists);
Branch: 1 branch
BranchTrueFalseTotal
unless $exists 33 62 95
611  
612 # This should probably be in the template.
613 62 my $nice_name;
614 62 ▶ if ($globname eq '()') {
Branch: 2 branches
BranchTrueFalseTotal
if ($globname eq '()') { } 6 56 62
elsif ($globname =~ /^\((.*)/) { } 11 45 56
615 6 $nice_name = 'I<overload table>';
616 } elsif ($globname =~ m/^\((.*)/) {
617 11 my $sort = $1;
618 11 $sort =~ s/(.)/sprintf "E<%d>", ord $1/ge;
619 11 $nice_name = "I<$sort overloading>";
620 } else {
621 45 $nice_name = $globname;
622 }
623  
624 62 my $subref = $classname->can($globname);
625 62 ▶ if ($force_inherits && !$subref) { # forced inherits may be the ones with the methods...
Branch: 1 branch
BranchTrueFalseTotal
if ($force_inherits and not $subref) 6 56 62
Condition66%2/3
$force_inherits and not $subref
!ll&&!rl&&r
5606
MC/DC50%1/2
$force_inherits and not $subref
$force_inherits not $subref
Truth table66%2/3
A and not(B)
A= $force_inheritsB= not $subref
ABresult
0X0
100
111
626 6 foreach my $class (@$force_inherits) {
627 10 ▶ $subref = $class->can($globname)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $subref 8 2 10
628 unless defined $subref;
629 }
630 }
631 # Must not be a method, but some other strange beastie.
632 62 ▶ next if !$subref;
Branch: 1 branch
BranchTrueFalseTotal
unless $subref 0 62 62
633  
634 62 my $identify_name = Sub::Identify::stash_name($subref);
635 # No reason to list it, really. Then again, no reason not to,
636 # really... Yes there is. It's just noise for anybody who actually knows perl.
637 62 ▶ next if $identify_name eq 'UNIVERSAL';
Branch: 1 branch
BranchTrueFalseTotal
if $identify_name eq "UNIVERSAL" 0 62 62
638  
639 62 ▶ if ($identify_name ne $parent_class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identify_name ne $parent_class) 14 48 62
640 # warn "Probable unexpected import of $nice_name from $identify_name into $parent_class"
641 # if $] >= 5.010;
642 14 next;
643 }
644 # Note that this needs to happen *after* we determine if it's a cache entry, so that we *will* get them later.
645 48 $seen{$globname} = $parent_class;
646 # push @derived, { $parent_class => $nice_name };
647  
648 48 ▶ my $doc_parent_class = $local_config->{class_map}->{$parent_class} || $parent_class;
Condition66%2/3
$local_config->{'class_map'}{$parent_class} || $parent_class
l!l&&r!l&&!r
9390
MC/DC0%0/2
$local_config->{'class_map'}{$parent_class} || $parent_class
$local_config->{'class_map'}{$parent_class} $parent_class
Truth table66%2/3
A || B
A= $local_config->{'class_map'}{$parent_class}B= $parent_class
ABresult
1X1
011
000
649  
650 # Dead link checks
651 48 ▶ if (exists $self->{dead_links}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"dead_links"}) 9 39 48
652 # Tolerate grandparent documentation for methods (but check parent first)
653 9 my $found_doc = 0;
654 9 foreach my $class ($parent_class, @isa_flattened, @{mro::get_linear_isa($parent_class)}) {
655 22 ▶ next if (first { $_ eq $class } @{ $self->{skip_inherits} });
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
if &first(sub { $_ eq $class; } , @{$$self{"skip_inherits"};}) 0 22 22
656 22 ▶ my $map_class = $local_config->{class_map}->{$class} || $class;
Condition66%2/3
$local_config->{'class_map'}{$class} || $class
l!l&&r!l&&!r
9130
MC/DC0%0/2
$local_config->{'class_map'}{$class} || $class
$local_config->{'class_map'}{$class} $class
Truth table66%2/3
A || B
A= $local_config->{'class_map'}{$class}B= $class
ABresult
1X1
011
000
657  
658 # Mapped class might have not been read for POD sections yet
659 22 $self->_check_pod_sections(undef, $map_class);
660  
661 # Found it!
662 22 ▶ if ($self->{pod_sections}{$map_class}{$globname}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"pod_sections"}{$map_class}{$globname}) 3 19 22
663 3 ▶ print " Method documentation on grandparent: $map_class"."::$globname\n"
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG and $doc_parent_class ne $map_class 0 3 3
Condition33%1/3
$Pod::Inherit::DEBUG and $doc_parent_class ne $map_class
!ll&&!rl&&r
300
MC/DC0%0/2
$Pod::Inherit::DEBUG and $doc_parent_class ne $map_class
$Pod::Inherit::DEBUG $doc_parent_class ne $map_class
Truth table33%1/3
A and B
A= $Pod::Inherit::DEBUGB= $doc_parent_class ne $map_class
ABresult
0X0
100
111
664 if ($DEBUG && $doc_parent_class ne $map_class);
665  
666 3 $doc_parent_class = $map_class;
667 3 $found_doc = 1;
668 3 last;
669 }
670 }
671  
672 # Skip over undocumented methods if dead_links is set to ''
673 9 ▶ if ($self->{dead_links} eq '' && !$found_doc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"dead_links"} eq "" and not $found_doc) 6 3 9
Condition66%2/3
$self->{"dead_links"} eq "" and not $found_doc
!ll&&!rl&&r
036
MC/DC50%1/2
$self->{"dead_links"} eq "" and not $found_doc
$self->{"dead_links"} eq "" not $found_doc
Truth table66%2/3
A and not(B)
A= $self->{"dead_links"} eq ""B= not $found_doc
ABresult
0X0
100
111
674 6 ▶ print " Skipped due to lack of documentation: $globname\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 6 6
675 6 next;
676 }
677 }
678  
679 42 push @{$tt_stash->{methods}{$doc_parent_class}}, $nice_name;
680 7 ▶ splice(@isa_flattened, (firstidx { $_ eq $parent_class } @isa_flattened), 0, $doc_parent_class)
Subroutine __ANON__: called CC=1 SCAR=0.0
681 42 ▶ unless (any {$_ eq $doc_parent_class} @isa_flattened);
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $_ eq $doc_parent_class; } , @isa_flattened) 6 36 42
682 }
683 }
684  
685 # There were parent classes, but we don't inherit any methods from them. Don't insert an empty section.
686 44 ▶ return if !keys %{$tt_stash->{methods}};
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$$tt_stash{"methods"};} 5 39 44
687  
688 # We used to use TT here, but TT doesn't like hash elements that have
689 # names beginning with underscores.
690  
691 39 my $new_pod = <<'__END_POD__';
692 =head1 INHERITED METHODS
693  
694 =over
695  
696 __END_POD__
697  
698 # Indent, so doesn't show up as POD::Inherit's own POD.
699 39 $new_pod =~ s/^ //mg;
700  
701 39 for my $class (@{$tt_stash->{isa_flattened}}) {
702 52 ▶ next unless ($tt_stash->{methods}{$class});
Branch: 1 branch
BranchTrueFalseTotal
unless $tt_stash->{"methods"}{$class} 12 40 52
703 40 $new_pod .= "=item L<$class>\n\n";
704  
705 # Put in the method format
706 $new_pod .= join(", ", map {
707 42 my $method = $_;
708 my $mlf = (exists $self->{dead_links} && $self->{dead_links} ne '' && !$self->{pod_sections}{$class}{$method}) ?
709 42 ▶ $self->{dead_links} : $self->{method_format};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'dead_links'} && $self->{'dead_links'} ne '' && !$self->{'pod_sections'}{$class}{$method} ? : 0 42 42
Condition50%3/6
exists $self->{"dead_links"} and $self->{"dead_links"} ne "" and not $self->{"pod_sections"}{$class}{$method}
!ll&&!rl&&r
4200
exists $self->{"dead_links"} and $self->{"dead_links"} ne ""
!ll&&!rl&&r
3930
MC/DC0%0/3
exists $self->{"dead_links"} and $self->{"dead_links"} ne "" and not $self->{"pod_sections"}{$class}{$method}
exists $self->{"dead_links"} $self->{"dead_links"} ne "" not $self->{"pod_sections"}{$class}{$method}
Truth table50%2/4
A and B and not(C)
A= exists $self->{"dead_links"}B= $self->{"dead_links"} ne ""C= not $self->{"pod_sections"}{$class}{$method}
ABCresult
0XX0
10X0
1100
1111
710 42 $mlf =~ s/\%m/$method/g;
711 42 $mlf =~ s/\%c/$class/g;
712 42 $mlf =~ s/\%\%/\%/g;
713 42 $mlf;
714 40 } @{$tt_stash->{methods}{$class}}) . "\n\n";
715 }
716  
717 39 $new_pod .= "=back\n\n=cut\n\n";
718  
719 39 ▶ print "New pod, before Pod::POMification: \n", $new_pod if ($DEBUG >= 2);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG >= 2 0 39 39
720  
721 39 my $parser = Pod::POM->new;
722 39 ▶ $new_pod = $parser->parse_text($new_pod)
Branch: 1 branch
BranchTrueFalseTotal
$new_pod = $parser->parse_text($new_pod) or die "Generated pod invalid?" 39 0 39
723 or die "Generated pod invalid?";
724  
725 # examine any warnings raised
726 39 foreach my $warning ($parser->warnings()) {
727 0 warn "Generated pod warning: $warning\n";
728 }
729  
730 39 ▶ if ($DEBUG >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Pod::Inherit::DEBUG >= 2) 0 39 39
731 0 print "New pod, after Pod::POMification: \n";
732 0 print $new_pod->dump;
733 }
734  
735 39 $parser = Pod::POM->new;
736 39 ▶ my $pod = $parser->parse_file($src->stringify) # Make it a string again, because otherwise Pod::Parser gets confused.
Branch: 1 branch
BranchTrueFalseTotal
my $pod = $parser->parse_file($src->stringify) or die "Couldn't parse existing pod in ${src}: " . $parser->error 39 0 39
737 or die "Couldn't parse existing pod in $src: ".$parser->error;
738 39 my $outstr = $self->_get_inherit_header($classname, $src);
739  
740 # If set, we should go *before* the insertion point.
741 # Otherwise we should go *after*.
742 39 my $before;
743 # What is the index of the section that we should be going before / after?
744 my $insertion_point;
745  
746 39 my $i = 0;
747 39 for (reverse $pod->content) {
748 13 $i--;
749 13 ▶ next unless $_->isa('Pod::POM::Node::Head1');
Branch: 1 branch
BranchTrueFalseTotal
unless $_->isa("Pod::POM::Node::Head1") 0 13 13
750  
751 13 my $title = $_->title;
752 # This should be a list of all POD sections that should be "at the end of the file".
753 # That is, things that we should go before.
754 ### TODO: Config variable? ###
755 13 ▶ if (grep {$title eq $_} qw<LICENSE AUTHORS LIMITATIONS CONTRIBUTORS AUTHOR CAVEATS COPYRIGHT BUGS>, 'SEE ALSO', 'ALSO SEE', 'WHERE TO GO NEXT', 'COPYRIGHT AND LICENSE') {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$title eq $_;} ('LICENSE', 'AUTHORS', 'LIMITATIONS', 'CONTRIBUTORS', 'AUTHOR', 'CAVEATS', 'COPYRIGHT', 'BUGS'), 'SEE ALSO', 'ALSO SEE', 'WHERE TO GO NEXT', 'COPYRIGHT AND LICENSE') { } 8 5 13
756 8 ▶ print " Fount head $title at index $i, going before that section\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 8 8
757 8 $insertion_point = $i;
758 8 $before = 1;
759 8 last;
760 } else {
761 5 ▶ print " Found head $title at index $i, going after that section\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 5 5
762 5 $insertion_point = $i;
763 5 $before = 0;
764 5 last;
765 }
766 }
767  
768  
769 39 ▶ if (!$insertion_point and $pod->content) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $insertion_point and $pod->content) 26 13 39
Condition66%2/3
not $insertion_point and $pod->content
!ll&&!rl&&r
13026
MC/DC50%1/2
not $insertion_point and $pod->content
not $insertion_point $pod->content
Truth table66%2/3
not(A) and B
A= not $insertion_pointB= $pod->content
ABresult
0X0
100
111
770 26 ▶ print " Going at end\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 26 26
771 26 $insertion_point = -1;
772 26 $before = 0;
773 }
774 39 ▶ if (!$insertion_point) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($insertion_point) 0 39 39
775 0 ▶ print " Going as only section\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 0 0
776 0 $insertion_point = $pod;
777 0 $outstr .= $new_pod;
778 0 return $outstr;
779 }
780  
781 39 ▶ if (not $before and $insertion_point == -1) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $before and $insertion_point == -1) { } 31 8 39
elsif ($before) { } 8 0 8
Condition66%2/3
not $before and $insertion_point == -1
!ll&&!rl&&r
8031
MC/DC50%1/2
not $before and $insertion_point == -1
not $before $insertion_point == -1
Truth table66%2/3
not(A) and B
A= not $beforeB= $insertion_point == -1
ABresult
0X0
100
111
782 31 push @{$pod->{content}}, $new_pod;
783 } elsif ($before) {
784 8 splice(@{$pod->content}, $insertion_point-1, 0, $new_pod);
785 } else {
786 0 splice(@{$pod->content}, $insertion_point, 0, $new_pod);
787 }
788  
789 39 $outstr .= $pod;
790  
791 39 return $outstr;
792 }
793  
794 ### TODO: These need to be a separate module someday ###
795 76 ▶sub _file_to_package {
Subroutine _file_to_package: called CC=7 SCAR=21.8
796 76 my ($self, $file) = @_;
797 76 ▶ open my $fh, "<", $file or die "Can't open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Can't open ${file}: $!" 76 0 76
798 76 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 82 3 85
799 82 ▶ return $1 if (m/^package\s+([A-Za-z0-9_:]+);/);
Branch: 1 branch
BranchTrueFalseTotal
if /^package\s+([A-Za-z0-9_:]+);/ 73 9 82
800 9 ▶ if (m/^package\b/) { # still not immune to "hide from PAUSE" tricks
Branch: 1 branch
BranchTrueFalseTotal
if (/^package\b/) 0 9 9
801 0 ▶ print " Package hidden with anti-PAUSE tricks in $file\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 0 0
802 0 return undef;
803 }
804 }
805  
806 3 ▶ print " Couldn't find any package statement in $file\n" if ($DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG 0 3 3
807 3 return undef;
808 }
809  
810 105 ▶sub _pure_filename_to_classname {
Subroutine _pure_filename_to_classname: called CC=1 SCAR=0.0
811 105 my ($self, $pure_filename) = @_;
812 105 $pure_filename =~ s/\.p(?:m|od)$//i;
813 105 return join '::', split(/::|\/|\\/, $pure_filename);
814 }
815  
816 97 ▶sub _any_to_pm_filename {
Subroutine _any_to_pm_filename: called CC=1 SCAR=0.0
817 97 my ($self, $any) = @_;
818 97 $any =~ s/\.p(?:m|od)$//i;
819 97 return Path::Class::File->new( split(/::|\/|\\/, $any.'.pm') )->cleanup;
820 }
821  
822 17 ▶sub _any_to_real_file {
Subroutine _any_to_real_file: called CC=8 SCAR=20.9
823 17 my ($self, $any, $try_pods, $try_dirs) = @_;
824 17 my $filename = $self->_any_to_pm_filename($any);
825  
826 17 foreach my $d (@{ $self->{input_files} }, '.') { # include "current directory" last, wherever that is
827 24 ▶ my $pd = -d $d ? $d : Path::Class::File->new($d)->dir;
Branch: 1 branch
BranchTrueFalseTotal
-d $d ? : 24 0 24
828 24 my $f = Path::Class::File->new($pd, $filename)->cleanup;
829 24 ▶ return $f->resolve if (-f $f);
Branch: 1 branch
BranchTrueFalseTotal
if -f $f 10 14 24
830  
831 14 ▶ next unless $try_pods;
Branch: 1 branch
BranchTrueFalseTotal
unless $try_pods 6 8 14
832 8 $f =~ s/m$/od/;
833 8 ▶ return Path::Class::File->new($f)->resolve if (-f $f);
Branch: 1 branch
BranchTrueFalseTotal
if -f $f 4 4 8
834  
835 4 ▶ next unless $try_dirs;
Branch: 1 branch
BranchTrueFalseTotal
unless $try_dirs 0 4 4
836 4 $f =~ s/\.pod$//;
837 4 ▶ return Path::Class::Dir->new($f)->resolve if (-d $f);
Branch: 1 branch
BranchTrueFalseTotal
if -d $f 0 4 4
838 }
839 3 return undef;
840 }
841  
842 10 ▶sub _any_to_type_array {
Subroutine _any_to_type_array: called CC=13 SCAR=32.8
843 10 my ($self, $any, $try_pods, $value_type) = @_;
844 10 ▶ return undef unless defined $any;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $any 0 10 10
845 10 my $type;
846 10 ▶ $value_type = $value_type ? "[Found in $value_type] " : '';
Branch: 1 branch
BranchTrueFalseTotal
$value_type ? : 10 0 10
847  
848 # figure out what 'any' is
849 10 my $crossplat_any = Path::Class::File->new( split(/\/|\\/, $any) )->cleanup->stringify;
850 10 my $real_file = $self->_any_to_real_file($any, $try_pods, 1);
851  
852 0 ▶ if ($any =~ /::/) { $type = 'c'; } # has to be a class with ::
Branch: 6 branches
BranchTrueFalseTotal
if ($any =~ /::/) { } 0 10 10
elsif ($any =~ /\.p(?:m|od)$/i) { } 4 6 10
elsif (-d $crossplat_any) { } 2 4 6
elsif (-e $crossplat_any) { } 0 4 4
elsif ($any =~ m[/|\\]) { } 0 4 4
elsif ($real_file) { } 4 0 4
853 4 elsif ($any =~ /\.p(?:m|od)$/i) { $type = 'f'; } # has to be a file with .pm/.pod
854 2 elsif (-d $crossplat_any) { $type = 'd'; } # might also be a class, but take priority on existing dirs relative to .
855 0 elsif (-e $crossplat_any) { $type = 'f'; } # has to be a file
856 elsif ($any =~ /\/|\\/) { # assume is a file/dir that (maybe) we can't find
857 0 ▶ unless ($real_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($real_file) 0 0 0
858 0 warn $value_type."Appears to be a file/dir, but it doesn't exist: $any";
859 0 return undef;
860 }
861 0 ▶ $type = -d $real_file ? 'd' : 'f';
Branch: 1 branch
BranchTrueFalseTotal
-d $real_file ? : 0 0 0
862 }
863 4 elsif ($real_file) { $type = 'c'; } # this leaves top-level classes, so check to see if it exists
864 else {
865 0 warn $value_type."Cannot even guess to what this is, as it doesn't exist anywhere: $any";
866 0 return undef;
867 }
868  
869 # classes should remain as-is; file/dir should match the exact file
870 10 ▶ return [$type, ($type eq 'c') ? $any : ($real_file || $crossplat_any)];
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'c' ? : 4 6 10
Condition66%2/3
$real_file or $crossplat_any
l!l&&r!l&&!r
420
MC/DC0%0/2
$real_file or $crossplat_any
$real_file $crossplat_any
Truth table66%2/3
A or B
A= $real_fileB= $crossplat_any
ABresult
1X1
011
000
871 }
872  
873 224 ▶sub _match_filename_to_type_array {
Subroutine _match_filename_to_type_array: called CC=5 SCAR=16.5
874 224 my ($self, $classname, $full_filename, $type_any) = @_;
875 224 ▶ $type_any = $self->_any_to_type_array($type_any) unless ref $type_any; # this should have already been done...
Branch: 1 branch
BranchTrueFalseTotal
unless ref $type_any 0 224 224
876 224 my ($type, $any) = @$type_any;
877  
878 224 ▶ return $classname eq $any if ($type eq 'c');
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "c" 88 136 224
879 136 ▶ return $full_filename eq $any if ($type eq 'f');
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "f" 90 46 136
880 46 ▶ return $full_filename =~ /^\Q$any\E/ if ($type eq 'd'); # treat these as recursive matches
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "d" 46 0 46
881 0 return undef;
882 }
883  
884 82 ▶sub _require_class {
Subroutine _require_class: called CC=10 SCAR=27.4
885 82 my ($self, $src, $classname) = @_;
886  
887 82 ▶ $classname ||= $self->_file_to_package($src) || return undef;
Condition80%4/5
$classname ||= $self->_file_to_package($src) || (return undef)
l!l&&r!l&&!r
6760
$self->_file_to_package($src) || (return undef)
l!l
733
MC/DC0%0/2
$classname ||= $self->_file_to_package($src) || (return undef)
$classname $self->_file_to_package($src)
Truth table66%2/3
A ||= B
A= $classnameB= $self->_file_to_package($src)
ABresult
1X1
011
000
888 79 ▶ $src ||= $self->_any_to_real_file($classname);
Condition66%2/3
$src ||= $self->_any_to_real_file($classname)
l!l&&r!l&&!r
7360
MC/DC0%0/2
$src ||= $self->_any_to_real_file($classname)
$src $self->_any_to_real_file($classname)
Truth table66%2/3
A ||= B
A= $srcB= $self->_any_to_real_file($classname)
ABresult
1X1
011
000
889  
890 # What we had here was hack on top of hack on top of hack, and still didn't work.
891 # Fuckit. Rewrite.
892 79 my $class_as_filename = $self->_any_to_pm_filename($classname);
893  
894 # Let's just snuff this one right away
895 6 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
896  
897 79 local $|=1;
898 79 my $old_sig_warn = $SIG{__WARN__};
899 0 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
900 # Still getting these; we need to filter here...
901 0 ▶ return if ($_[0] =~ /^(?:Constant )?[Ss]ubroutine [\w\:]+ redefined /);
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /^(?:Constant )?[Ss]ubroutine [\w\:]+ redefined / 0 0 0
902  
903 0 my $warning = " While loading $src: ".$_[0];
904 0 ▶ $old_sig_warn ? $old_sig_warn->($warning) : warn $warning;
Branch: 1 branch
BranchTrueFalseTotal
$old_sig_warn ? : 0 0 0
905 79 };
906  
907 # Just like require, except without that pesky checking @INC thing,
908 # but making sure we put the "right" thing in %INC.
909 79 ▶ unless (exists $INC{$class_as_filename}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $INC{$class_as_filename}) 63 16 79
910 # Still no source? Great... we'll have to pray that require will work...
911 63 ▶ print "Still no source found for $classname; forced to use 'require'\n" if ($DEBUG && !$src);
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Inherit::DEBUG and not $src 0 63 63
Condition33%1/3
$Pod::Inherit::DEBUG and not $src
!ll&&!rl&&r
6300
MC/DC0%0/2
$Pod::Inherit::DEBUG and not $src
$Pod::Inherit::DEBUG not $src
Truth table33%1/3
A and not(B)
A= $Pod::Inherit::DEBUGB= not $src
ABresult
0X0
100
111
912 63 ▶ my $did_it = $src ? do $src : Class::Load::load_optional_class($classname);
Branch: 1 branch
BranchTrueFalseTotal
$src ? : 63 0 63
913 63 ▶ unless ($did_it) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($did_it) 0 63 63
914 0 my $err = $@;
915 0 $err =~ s/ \(\@INC contains: .*\)//;
916 0 $SIG{__WARN__} = $old_sig_warn; # only need it for the do/require
917  
918 0 warn "Couldn't autogenerate documentation for $src: $err\n";
919 0 return undef;
920 }
921 }
922 # There's what is arguably a bug in perl itself lurking here: Foo.pm
923 # dies during complation (IE not because it wasn't in @INC). An
924 # undef entry is left in %INC, but it's a READONLY undef, which
925 # means that you can't just assign something else to the slot.
926 79 ▶ $INC{$class_as_filename} = $src unless (exists $INC{$class_as_filename});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $INC{$class_as_filename} 63 16 79
927  
928 # While we are here, check the POD text for sections
929 79 $self->_check_pod_sections($src, $classname);
930  
931 79 return $classname;
932 }
933  
934 113 ▶sub _check_pod_sections {
Subroutine _check_pod_sections: called CC=9 SCAR=24.0
935 113 my ($self, $src, $classname) = @_;
936 113 ▶ return 0 unless ($classname);
Branch: 1 branch
BranchTrueFalseTotal
unless $classname 0 113 113
937 113 ▶ return 0 unless (exists $self->{dead_links} && not $self->{pod_sections}{$classname});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"dead_links"} and not $self->{"pod_sections"}{$classname} 92 21 113
Condition100%3/3
exists $self->{"dead_links"} and not $self->{"pod_sections"}{$classname}
!ll&&!rl&&r
623021
MC/DC100%2/2
exists $self->{"dead_links"} and not $self->{"pod_sections"}{$classname}
exists $self->{"dead_links"} not $self->{"pod_sections"}{$classname}
Truth table100%3/3
A and not(B)
A= exists $self->{"dead_links"}B= not $self->{"pod_sections"}{$classname}
ABresult
0X0
100
111
938  
939 $src ||=
940 21 ▶ $INC{ $self->_any_to_pm_filename($classname) } ||
Condition50%4/8
$src ||= $INC{$self->_any_to_pm_filename($classname)} || $self->_any_to_real_file($classname, 1, 1) || (return 0)
l!l&&r!l&&!r
2010
$INC{$self->_any_to_pm_filename($classname)} || $self->_any_to_real_file($classname, 1, 1) || (return 0)
l!l
01
$INC{$self->_any_to_pm_filename($classname)} or $self->_any_to_real_file($classname, 1, 1)
l!l&&r!l&&!r
001
MC/DC0%0/3
$src ||= $INC{$self->_any_to_pm_filename($classname)} || $self->_any_to_real_file($classname, 1, 1) || (return 0)
$src $INC{$self->_any_to_pm_filename($classname)} $self->_any_to_real_file($classname, 1, 1)
Truth table0%0/4
A ||= B or C
A= $srcB= $INC{$self->_any_to_pm_filename($classname)}C= $self->_any_to_real_file($classname, 1, 1)
ABCresult
1XX1
01X1
0011
0000
941 $self->_any_to_real_file($classname, 1, 1) ||
942 return 0
943 ;
944  
945 20 my $hash = $self->{pod_sections}{$classname} = {};
946  
947 20 my $p = Pod::POM->new;
948 20 ▶ my $pom = $p->parse_file("$src") || die $p->error(); # again, Pod::POM has issues with Path::Class objects
Condition50%1/2
$p->parse_file("$src") || die($p->error)
l!l
200
MC/DC0%0/1
$p->parse_file("$src") || die($p->error)
$p->parse_file("$src")
Truth table50%1/2
A
A= $p->parse_file("$src")
Aresult
11
00
949 20 $self->_find_pod_headers($pom, $hash);
950  
951 20 ▶ if ($DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Pod::Inherit::DEBUG) 0 20 20
952 0 print " Found ".scalar(keys %$hash)." POD sections in $classname:\n";
953 0 print " ".join(', ', keys %$hash)."\n";
954 }
955  
956 20 return 1;
957 }
958  
959 73 ▶sub _find_pod_headers {
Subroutine _find_pod_headers: called CC=3 SCAR=11.0
960 73 my ($self, $top, $hash) = @_;
961  
962 73 ▶ $hash->{ $top->title->present('Pod::POM::View::TextStrip') } = 1 if ($top->type =~ /head/i);
Branch: 1 branch
BranchTrueFalseTotal
if $top->type =~ /head/i 23 50 73
963 73 foreach my $item ($top->content) {
964 53 $self->_find_pod_headers($item, $hash);
965 }
966 }
967  
968 81 ▶sub _is_ours {
Subroutine _is_ours: called CC=4 SCAR=14.0
969 81 my ($self, $outfn) = @_;
970  
971 # If it already exists, make sure it's one of ours
972 81 ▶ if (-e $outfn) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $outfn) 1 80 81
973 1 ▶ open my $outfh, '<', $outfn
Branch: 1 branch
BranchTrueFalseTotal
open my $outfh, "<", $outfn or die "Can't open pre-existing $outfn for reading: $!" 1 0 1
974 or die "Can't open pre-existing $outfn for reading: $!";
975 # FIXME: Should probably check past the first line for this, in case something else placed it's autogenerated marker before ours.
976 1 ▶ if (<$outfh> ne "=for comment POD_DERIVED_INDEX_GENERATED\n") {
Branch: 1 branch
BranchTrueFalseTotal
if (readline $outfh ne "=for comment POD_DERIVED_INDEX_GENERATED\n") 1 0 1
977 1 warn "$outfn already exists, and it doesn't look like we generated it. Skipping this file";
978 1 return 0;
979 }
980 # print "Output file already exists, but seems to be one of ours, overwriting it\n";
981 }
982  
983 80 return 1;
984 }
985  
986  
987 39 ▶sub _get_inherit_header {
Subroutine _get_inherit_header: called CC=1 SCAR=0.0
988 39 my ($self, $classname, $src) = @_;
989  
990 # Always give source paths as unix, so the tests don't need to
991 # vary depending on what OS the user is running on. This may be
992 # construed as a bug. If you care, patches are welcome, if they
993 # fix the tests, too.
994 39 $src = Path::Class::File->new($src)->as_foreign('Unix');
995  
996 39 return <<__END_HEADER__;
997 =for comment POD_DERIVED_INDEX_GENERATED
998 The following documentation is automatically generated. Please do not edit
999 this file, but rather the original, inline with $classname
1000 at $src
1001 (on the system that originally ran this).
1002 If you do edit this file, and don't want your changes to be removed, make
1003 sure you change the first line.
1004  
1005 =cut
1006  
1007 __END_HEADER__
1008  
1009 }
1010  
1011 6 1;
1012 __END__
↑ Summary