script/podify.pl

filter: Statementstmt 79.0% 79 / 100 Branchbran 73.0% 38 / 52 Conditioncond 56.2% 18 / 32 MC/DCmcdc 38.8% 7 / 18 Subroutinesub 84.6% 11 / 13 Podpod n/a totaltotal 71.1% 153 / 215 CC 45 SCAR 24.4
CC
45
Cov
73%
check_pod
20.0
__ANON__
20.0
parse
17.5
CRAP 11.5
↑ Summary blib/lib/App/podify.pm »
1 #!/usr/bin/env perl
2 4 ▶use Applify;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 4 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use if -e '.ship.conf', lib => 'lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 option bool => i => 'Replace source', 0;
10 4 option bool => recursive => 'Recurse into directories in source list',
11 0, (alias => 'r');
12 4 option str => eopm => 'End of perl module marker', '^1;';
13  
14 4 documentation 'App::podify';
15  
16 0 ▶sub check_pod {
Subroutine check_pod: not called CC=4 SCAR=30.0
17 0 my $self = shift;
18  
19 0 for my $section (qw(attrs subs)) {
20 0 ▶ for my $name (keys %{$self->{$section} || {}}) {
Condition0%0/2
$self->{$section} || {}
l!l
00
MC/DC0%0/1
$self->{$section} || {}
$self->{$section}
Truth table0%0/2
A
A= $self->{$section}
Aresult
11
00
21 0 warn "Missing $section in pod: $name\n";
22 }
23 }
24  
25 0 return $self;
26 }
27  
28 2 ▶sub find_files {
Subroutine find_files: called CC=1 SCAR=0.0
29 2 my ($self, $path) = @_;
30 2 my @files;
31  
32 File::Find::find(
33 {
34 no_chdir => 1,
35 19 ▶ wanted => sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
36 19 ▶ $File::Find::prune = 1 if -d $File::Find::name and !$self->recursive;
Branch: 1 branch
BranchTrueFalseTotal
if -d $File::Find::name and not $self->recursive 2 17 19
Condition100%3/3
-d $File::Find::name and not $self->recursive
!ll&&!rl&&r
1522
MC/DC100%2/2
-d $File::Find::name and not $self->recursive
-d $File::Find::name not $self->recursive
Truth table100%3/3
A and not(B)
A= -d $File::Find::nameB= not $self->recursive
ABresult
0X0
100
111
37 19 ▶ $File::Find::prune = 0 if $File::Find::name eq $path;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Find::name eq $path 2 17 19
38 19 ▶ return if $File::Find::prune;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Find::prune 1 18 19
39 18 ▶ push @files, $File::Find::name if $File::Find::name =~ m/[.] pm \z/msx;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Find::name =~ /[.] pm \z/msx 5 13 18
40 }
41 },
42 2 $path
43 );
44  
45 2 return sort { length $a <=> length $b } @files;
46 }
47  
48 3 ▶sub generate {
Subroutine generate: called CC=8 SCAR=21.6
49 3 my ($self, $OUT) = @_;
50  
51 3 ▶ $self->{pod} = $self->pod_template unless @{$self->{pod}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"pod"};} 1 2 3
52  
53 3 ▶ if ($self->i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->i) { } 0 3 3
elsif (not $OUT) { } 0 3 3
54 0 ▶ open $OUT, '>', $self->{perl_module} or die "Write $self->{perl_module}: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $OUT, ">", $self->{"perl_module"} or die qq[Write $self->{"perl_module"}: $!\n] 0 0 0
55 }
56 elsif (!$OUT) {
57 0 $OUT = \*STDOUT;
58 }
59  
60 3 my $code = join '', @{$self->{code}};
61 3 $code =~ s!\n\n\n!\n\n!g;
62 3 $code =~ s!\n+use!\nuse!s;
63 3 $code =~ s!\n+$!\n\n!;
64  
65 3 print $OUT "${code}1;\n\n";
66 3 ▶ print $OUT "=encoding utf8\n\n" unless $self->{pod_has_encoding};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"pod_has_encoding"} 3 0 3
67 3 print $OUT $_ for grep { !/^=cut/ } @{$self->{pod}};
68 3 print $OUT "=cut\n";
69 3 ▶ print $OUT "\n" . join '', @{$self->{data}} if @{$self->{data}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"data"};} 1 2 3
70 }
71  
72 3 ▶sub init {
Subroutine init: called CC=3 SCAR=11.0
73 3 my $self = shift;
74 3 $self->{$_} = [] for qw(code data pod);
75 3 $self->{$_} = {} for qw(attrs subs);
76 3 $self;
77 }
78  
79 3 ▶sub parse {
Subroutine parse: called CC=17 SCAR=28.6
80 3 my $self = shift;
81 3 my $eopm = $self->eopm;
82 3 my %has;
83  
84 3 ▶ open my $IN, '<', $self->{perl_module} or die "Read $self->{perl_module}: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $IN, "<", $self->{"perl_module"} or die qq[Read $self->{"perl_module"}: $!\n] 3 0 3
85 3 $eopm = qr{$eopm};
86  
87 3 ▶ while (<$IN>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $IN)) 106 3 109
88 106 my $pod;
89 106 ▶ next if /^=encoding\s/;
Branch: 1 branch
BranchTrueFalseTotal
if /^=encoding\s/ 1 105 106
90 105 ▶ $self->{attrs}{$1} = $1 if /^has\s+([a-z]\w*)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^has\s+([a-z]\w*)/ 2 103 105
91 105 ▶ $self->{subs}{$1} = $1 if /^sub\s+([a-z]\w*)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^sub\s+([a-z]\w*)/ 3 102 105
92 105 ▶ $self->{documented}{$1} = $1 if /^=head2\s([a-z]\w*)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^=head2\s([a-z]\w*)/ 2 103 105
93 105 ▶ $self->{module_name} ||= $1 if /^package\s+([^\s;]+)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^package\s+([^\s;]+)/ 3 102 105
Condition33%1/3
$self->{"module_name"} ||= $1
l!l&&r!l&&!r
030
MC/DC0%0/2
$self->{"module_name"} ||= $1
$self->{"module_name"} $1
Truth table33%1/3
A ||= B
A= $self->{"module_name"}B= $1
ABresult
1X1
011
000
94 105 ▶ $self->{module_version} ||= $1 if /^VERSION.*([\d\.]+)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^VERSION.*([\d\.]+)/ 0 105 105
Condition0%0/3
$self->{"module_version"} ||= $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"module_version"} ||= $1
$self->{"module_version"} $1
Truth table0%0/3
A ||= B
A= $self->{"module_version"}B= $1
ABresult
1X1
011
000
95 105 ▶ $pod = push @{$self->{pod}}, $_ if /^=head/ .. /=cut/;
Branch: 1 branch
BranchTrueFalseTotal
if /^=head/ .. /=cut/ 61 44 105
96 105 ▶ push @{$self->{data}}, $_ if @{$self->{data}} or /^__DATA__$/;
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"data"};} or /^__DATA__$/ 2 103 105
Condition100%3/3
@{$self->{"data"};} or /^__DATA__$/
l!l&&r!l&&!r
11103
MC/DC100%2/2
@{$self->{"data"};} or /^__DATA__$/
@{$self->{"data"};} /^__DATA__$/
Truth table100%3/3
A or B
A= @{$self->{"data"};}B= /^__DATA__$/
ABresult
1X1
011
000
97 105 ▶ push @{$self->{code}}, $_ unless @{$self->{data}} or $pod or $_ =~ $eopm;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"data"};} or $pod or $_ =~ /$eopm/ 39 66 105
Condition100%6/6
@{$self->{"data"};} or $pod or $_ =~ /$eopm/
l!l&&r!l&&!r
63339
@{$self->{"data"};} or $pod
l!l&&r!l&&!r
26142
MC/DC100%3/3
@{$self->{"data"};} or $pod or $_ =~ /$eopm/
@{$self->{"data"};} $pod $_ =~ /$eopm/
Truth table100%4/4
A or B or C
A= @{$self->{"data"};}B= $podC= $_ =~ /$eopm/
ABCresult
1XX1
01X1
0011
0000
98 }
99  
100 3 return $self;
101 }
102  
103 1 ▶sub pod_template {
Subroutine pod_template: called CC=7 SCAR=23.2
104 1 my $self = shift;
105  
106 return [
107 sprintf("=head1 NAME\n\n%s - TODO\n\n", $self->{module_name} || 'Unknown'),
108 $self->{module_version} ? printf("=head1 VERSION\n\n$%s\n\n", $self->{module_version}) : (),
109 sprintf("=head1 SYNOPSIS\n\nTODO\n\n"),
110 sprintf("=head1 DESCRIPTION\n\nTODO\n\n"),
111 sprintf("=head1 ATTRIBUTES\n\n"),
112 1 ▶ map({ sprintf "=head2 %s\n\n", delete $self->{attrs}{$_} } sort keys %{$self->{attrs} || {}}),
Condition50%1/2
$self->{'attrs'} || {}
l!l
10
MC/DC0%0/1
$self->{'attrs'} || {}
$self->{'attrs'}
Truth table50%1/2
A
A= $self->{'attrs'}
Aresult
11
00
113 sprintf("=head1 METHODS\n\n"),
114 1 ▶ map({ sprintf "=head2 %s\n\n", delete $self->{subs}{$_} } sort keys %{$self->{subs} || {}}),
Condition37%3/8
$self->{'subs'} || {}
l!l
10
$ENV{'PODIFY_AUTHOR'} || (getpwuid $<)[6] || (getpwuid $<)[0]
l!l&&r!l&&!r
100
$ENV{"PODIFY_AUTHOR"} or (getpwuid $<)[6]
l!l&&r!l&&!r
100
MC/DC0%0/1
$self->{'subs'} || {}
$self->{'subs'}
MC/DC0%0/3
$ENV{'PODIFY_AUTHOR'} || (getpwuid $<)[6] || (getpwuid $<)[0]
$ENV{"PODIFY_AUTHOR"} (getpwuid $<)[6] (getpwuid $<)[0]
Truth table50%1/2
A
A= $self->{'subs'}
Aresult
11
00
Truth table25%1/4
A or B || C
A= $ENV{"PODIFY_AUTHOR"}B= (getpwuid $<)[6]C= (getpwuid $<)[0]
ABCresult
1XX1
01X1
0011
0000
115 1 ▶ sprintf("=head1 AUTHOR\n\n%s\n\n", $ENV{PODIFY_AUTHOR} || (getpwuid $<)[6] || (getpwuid $<)[0]),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'module_version'} ? : 0 1 1
Condition50%1/2
$self->{'module_name'} || 'Unknown'
l!l
10
MC/DC0%0/1
$self->{'module_name'} || 'Unknown'
$self->{'module_name'}
Truth table50%1/2
A
A= $self->{'module_name'}
Aresult
11
00
116 sprintf("=head1 COPYRIGHT AND LICENSE\n\nTODO\n\n"),
117 sprintf("=head1 SEE ALSO\n\nTODO\n\n"),
118 ];
119 }
120  
121 3 ▶sub post_process {
Subroutine post_process: called CC=3 SCAR=11.0
122 3 my $self = shift;
123 3 ▶ delete $self->{attrs}{$_} or delete $self->{subs}{$_} for keys %{$self->{documented}};
Branch: 1 branch
BranchTrueFalseTotal
delete $self->{"attrs"}{$_} or delete $self->{"subs"}{$_} 1 1 2
124 }
125  
126 0 ▶app {
Subroutine __ANON__: not called CC=4 SCAR=30.0
127 0 my ($self, @paths) = @_;
128  
129 0 ▶ unless (@paths) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@paths) 0 0 0
130 0 die $self->_script->print_help, "No input files specified.\n";
131 }
132  
133 0 ▶ while (my $path = File::Spec->canonpath(shift @paths)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path = "File::Spec"->canonpath(shift @paths)) 0 0 0
134 0 ▶ if (-d $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $path) { } 0 0 0
135 0 push @paths, $self->find_files($path);
136 }
137 else {
138 0 $self->init;
139 0 $self->{perl_module} = $path;
140 0 $self->parse;
141 0 $self->post_process;
142 0 $self->generate;
143 0 $self->check_pod;
144 }
145 }
146  
147 0 return 0;
148 4 };
↑ Summary blib/lib/App/podify.pm »