inc/Module/Install/ReadmeFromPod.pm

filter: Statementstmt 16.8% 18 / 107 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 33.3% 5 / 15 Podpod 0.0% 0 / 1 totaltotal 12.5% 23 / 184 CC 27 SCAR 43.3
CC
27
Cov
11%
readme_from
199.9
_readme_htm
30.0
_all_from
20.0
CRAP 76.1
« inc/Module/Install/Makefile.pm ↑ Summary inc/Module/Install/Metadata.pm »
1 #line 1
2 package Module::Install::ReadmeFromPod;
3 2 ▶ 
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use base qw(Module::Install::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 use vars qw($VERSION);
9 2  
10 $VERSION = '0.30';
11  
12 {
13  
14 # these aren't defined until after _require_admin is run, so
15 # define them so prototypes are available during compilation.
16 sub io;
17 sub capture(&;@);
18  
19 #line 28
20  
21 my $done = 0;
22  
23 sub _require_admin {
24  
25 # do this once to avoid redefinition warnings from IO::All
26 return if $done;
27  
28 require IO::All;
29 2 IO::All->import( '-binary' );
30  
31 0 ▶ require Capture::Tiny;
Subroutine _require_admin: not called CC=2 SCAR=17.9
32 Capture::Tiny->import ( 'capture' );
33  
34 0 ▶ return;
Branch: 1 branch
BranchTrueFalseTotal
if $done 0 0 0
35 }
36 0  
37 0 }
38  
39 0 sub readme_from {
40 0 my $self = shift;
41 return unless $self->is_admin;
42 0  
43 _require_admin;
44  
45 # Input file
46 my $in_file = shift || $self->_all_from
47 2 ▶ or die "Can't determine file to make readme_from";
Subroutine readme_from: not called CC=14 SCAR=53.0
Pod undocumented
48 0  
49 0 ▶ # Get optional arguments
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_admin 0 0 0
50 my ($clean, $format, $out_file, $options);
51 0 my $args = shift;
52 if ( ref $args ) {
53 # Arguments are in a hashref
54 0 ▶ if ( ref($args) ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
my $in_file = shift() || $self->_all_from or die "Can't determine file to make readme_from" 0 0 0
Condition0%0/3
shift() || $self->_all_from
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->_all_from
shift() $self->_all_from
Truth table0%0/3
A || B
A= shift()B= $self->_all_from
ABresult
1X1
011
000
55 die "Expected a hashref but got a ".ref($args)."\n";
56 } else {
57 $clean = $args->{'clean'};
58 0 $format = $args->{'format'};
59 0 $out_file = $args->{'output_file'};
60 0 ▶ $options = $args->{'options'};
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args) { } 0 0 0
61 }
62 0 ▶ } else {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args ne 'HASH') { } 0 0 0
63 0 # Arguments are in a list
64 $clean = $args;
65 0 $format = shift;
66 0 $out_file = shift;
67 0 $options = \@_;
68 0 }
69  
70 # Default values;
71 $clean ||= 0;
72 0 $format ||= 'txt';
73 0  
74 0 # Generate README
75 0 print "readme_from $in_file to $format\n";
76 if ($format =~ m/te?xt/) {
77 $out_file = $self->_readme_txt($in_file, $out_file, $options);
78 } elsif ($format =~ m/html?/) {
79 0 ▶ $out_file = $self->_readme_htm($in_file, $out_file, $options);
Condition0%0/2
$clean ||= 0
l!l
00
MC/DC0%0/1
$clean ||= 0
$clean
Truth table0%0/2
A
A= $clean
Aresult
11
00
80 0 ▶ } elsif ($format eq 'man') {
Condition0%0/2
$format ||= "txt"
l!l
00
MC/DC0%0/1
$format ||= "txt"
$format
Truth table0%0/2
A
A= $format
Aresult
11
00
81 $out_file = $self->_readme_man($in_file, $out_file, $options);
82 } elsif ($format eq 'md') {
83 0 $out_file = $self->_readme_md($in_file, $out_file, $options);
84 0 ▶ } elsif ($format eq 'pdf') {
Branch: 5 branches
BranchTrueFalseTotal
if ($format =~ /te?xt/) { } 0 0 0
elsif ($format =~ /html?/) { } 0 0 0
elsif ($format eq 'man') { } 0 0 0
elsif ($format eq 'md') { } 0 0 0
elsif ($format eq 'pdf') { } 0 0 0
85 0 $out_file = $self->_readme_pdf($in_file, $out_file, $options);
86 }
87 0  
88 if ($clean) {
89 0 $self->clean_files($out_file);
90 }
91 0  
92 return 1;
93 0 }
94  
95  
96 0 ▶sub _readme_txt {
Branch: 1 branch
BranchTrueFalseTotal
if ($clean) 0 0 0
97 0 my ($self, $in_file, $out_file, $options) = @_;
98 $out_file ||= 'README';
99 require Pod::Text;
100 0 my $parser = Pod::Text->new( @$options );
101 my $io = io->file($out_file)->open(">");
102 my $out_fh = $io->io_handle;
103 $parser->output_fh( *$out_fh );
104 0 ▶ $parser->parse_file( $in_file );
Subroutine _readme_txt: not called CC=2 SCAR=17.9
105 0 return $out_file;
106 0 ▶}
Condition0%0/2
$out_file ||= "README"
l!l
00
MC/DC0%0/1
$out_file ||= "README"
$out_file
Truth table0%0/2
A
A= $out_file
Aresult
11
00
107 0  
108 0  
109 0 sub _readme_htm {
110 0 my ($self, $in_file, $out_file, $options) = @_;
111 0 $out_file ||= 'README.htm';
112 0 require Pod::Html;
113 0 my ($o) = capture {
114 Pod::Html::pod2html(
115 "--infile=$in_file",
116 "--outfile=-",
117 0 ▶ @$options,
Subroutine _readme_htm: not called CC=5 SCAR=34.0
118 0 );
119 0 ▶ };
Condition0%0/2
$out_file ||= "README.htm"
l!l
00
MC/DC0%0/1
$out_file ||= "README.htm"
$out_file
Truth table0%0/2
A
A= $out_file
Aresult
11
00
120 0 io->file($out_file)->print($o);
121 0 ▶ # Remove temporary files if needed
Subroutine __ANON__: not called CC=1 SCAR=6.9
122 0 for my $file ('pod2htmd.tmp', 'pod2htmi.tmp') {
123 if (-e $file) {
124 unlink $file or warn "Warning: Could not remove file '$file'.\n$!\n";
125 }
126 }
127 0 return $out_file;
128 0 }
129  
130 0  
131 0 ▶sub _readme_man {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file) 0 0 0
132 0 ▶ my ($self, $in_file, $out_file, $options) = @_;
Branch: 1 branch
BranchTrueFalseTotal
unlink $file or warn "Warning: Could not remove file '${file}'.\n$!\n" 0 0 0
133 $out_file ||= 'README.1';
134 require Pod::Man;
135 0 my $parser = Pod::Man->new( @$options );
136 my $io = io->file($out_file)->open(">");
137 my $out_fh = $io->io_handle;
138 $parser->output_fh( *$out_fh );
139 0 ▶ $parser->parse_file( $in_file );
Subroutine _readme_man: not called CC=2 SCAR=17.9
140 0 return $out_file;
141 0 ▶}
Condition0%0/2
$out_file ||= "README.1"
l!l
00
MC/DC0%0/1
$out_file ||= "README.1"
$out_file
Truth table0%0/2
A
A= $out_file
Aresult
11
00
142 0  
143 0  
144 0 sub _readme_pdf {
145 0 my ($self, $in_file, $out_file, $options) = @_;
146 0 $out_file ||= 'README.pdf';
147 0 eval { require App::pod2pdf; }
148 0 or die "Could not generate $out_file because pod2pdf could not be found\n";
149 my $parser = App::pod2pdf->new( @$options );
150 $parser->parse_from_file($in_file);
151 my ($o) = capture { $parser->output };
152 0 ▶ io->file($out_file)->print($o);
Subroutine _readme_pdf: not called CC=3 SCAR=24.8
153 0 return $out_file;
154 0 ▶}
Condition0%0/2
$out_file ||= "README.pdf"
l!l
00
MC/DC0%0/1
$out_file ||= "README.pdf"
$out_file
Truth table0%0/2
A
A= $out_file
Aresult
11
00
155 0 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require App::pod2pdf } } or die "Could not generate $out_file because pod2pdf could not be found\n" 0 0 0
156 sub _readme_md {
157 0 my ($self, $in_file, $out_file, $options) = @_;
158 0 $out_file ||= 'README.md';
159 0 ▶ require Pod::Markdown;
Subroutine __ANON__: not called CC=1 SCAR=6.9
160 0 my $parser = Pod::Markdown->new( @$options );
161 0 my $io = io->file($out_file)->open(">");
162 my $out_fh = $io->io_handle;
163 $parser->output_fh( *$out_fh );
164 0 ▶ $parser->parse_file( $in_file );
Subroutine _readme_md: not called CC=2 SCAR=17.9
165 0 return $out_file;
166 0 ▶}
Condition0%0/2
$out_file ||= "README.md"
l!l
00
MC/DC0%0/1
$out_file ||= "README.md"
$out_file
Truth table0%0/2
A
A= $out_file
Aresult
11
00
167 0  
168 0  
169 0 sub _all_from {
170 0 my $self = shift;
171 0 return unless $self->admin->{extensions};
172 0 my ($metadata) = grep {
173 0 ref($_) eq 'Module::Install::Metadata';
174 } @{$self->admin->{extensions}};
175 return unless $metadata;
176 return $metadata->{values}{all_from} || '';
177 0 ▶}
Subroutine _all_from: not called CC=4 SCAR=30.0
178 0  
179 0 ▶'Readme!';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->admin->{"extensions"} 0 0 0
180  
181 0 __END__
« inc/Module/Install/Makefile.pm ↑ Summary inc/Module/Install/Metadata.pm »