blib/lib/Dist/Zilla/Plugin/PodPurler.pm

filter: Statementstmt 45.5% 36 / 79 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 57.8% 11 / 19 Podpod 0.0% 0 / 2 totaltotal 34.3% 47 / 137 CC 18 SCAR 37.9
CC
18
Cov
32%
munge_perl_string
132.0
munge_file
20.0
__ANON__
6.0
CRAP 44.3
↑ Summary
1 package Dist::Zilla::Plugin::PodPurler 0.094;
2 # ABSTRACT: like PodWeaver, but more erratic and amateurish
3  
4 1 ▶use v5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Moose::Autobox 0.08;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use List::MoreUtils qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 with 'Dist::Zilla::Role::FileMunger';
9  
10 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Pod::Elemental 0.092930;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Pod::Elemental::Selectors -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Pod::Elemental::Transformer::Pod5;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Pod::Elemental::Transformer::Nester;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Pod::Elemental::Transformer::Gatherer;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 #pod =head1 WARNING
19 #pod
20 #pod This library has been superceded by L<Pod::Weaver> and
21 #pod L<Dist::Zilla::Plugin::PodWeaver>. It is unlikely to be updated again unless
22 #pod there are serious security problems (!?) or someone gives me some money.
23 #pod
24 #pod =head1 DESCRIPTION
25 #pod
26 #pod PodPurler ress, which rips apart your kinda-POD and reconstructs it as boring
27 #pod old real POD.
28 #pod
29 #pod =cut
30  
31 0 ▶sub munge_file {
Subroutine munge_file: not called CC=4 SCAR=30.0
Pod undocumented
32 0 my ($self, $file) = @_;
33  
34 0 ▶ return $self->munge_pod($file)
Branch: 1 branch
BranchTrueFalseTotal
if $file->name =~ /\.(?:pm|pod)$/iu and !($file->name =~ m[/]u) || $file->name =~ m[^lib/]u 0 0 0
Condition0%0/6
$file->name =~ /\.(?:pm|pod)$/iu and !($file->name =~ m[/]u) || $file->name =~ m[^lib/]u
!ll&&!rl&&r
000
not $file->name =~ m[/]u or $file->name =~ m[^lib/]u
l!l&&r!l&&!r
000
MC/DC0%0/3
$file->name =~ /\.(?:pm|pod)$/iu and !($file->name =~ m[/]u) || $file->name =~ m[^lib/]u
$file->name =~ /\.(?:pm|pod)$/iu not $file->name =~ m[/]u $file->name =~ m[^lib/]u
Truth table0%0/4
A and not(B) or C
A= $file->name =~ /\.(?:pm|pod)$/iuB= not $file->name =~ m[/]uC= $file->name =~ m[^lib/]u
ABCresult
0XX0
1000
11X1
1011
35 if $file->name =~ /\.(?:pm|pod)$/i
36 and ($file->name !~ m{/} or $file->name =~ m{^lib/});
37  
38 0 return;
39 }
40  
41 0 ▶sub munge_perl_string {
Subroutine munge_perl_string: not called CC=11 SCAR=48.8
42 0 my ($self, $doc, $arg) = @_;
43  
44 0 my $document = $doc->{pod};
45 0 Pod::Elemental::Transformer::Pod5->new->transform_node($document);
46  
47 0 my $nester = Pod::Elemental::Transformer::Nester->new({
48 top_selector => s_command([ qw(head1 method attr) ]),
49 content_selectors => [
50 s_flat,
51 s_command( [ qw(head2 head3 head4 over item back) ]),
52 ],
53 });
54  
55 0 $nester->transform_node($document);
56  
57 0 for my $pair (
58 [ method => 'METHODS' ],
59 [ attr => 'ATTRIBUTES' ],
60 ) {
61 0 my $sel = s_command($pair->[0]);
62 0 ▶ if ($document->children->grep($sel)->length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($document->children->grep($sel)->length) 0 0 0
63 0 my $gatherer = Pod::Elemental::Transformer::Gatherer->new({
64 gather_selector => $sel,
65 container => Pod::Elemental::Element::Nested->new({
66 command => 'head1',
67 content => "$pair->[1]\n",
68 }),
69 });
70  
71 0 $gatherer->transform_node($document);
72  
73 0 ▶ $gatherer->container->children->grep($sel)->each_value(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
74 0 $_->command('head2');
75 0 });
76 }
77 }
78  
79 0 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($document->children->grep(sub { s_command("head1", $_) and $_->content eq "VERSION\n"; } )->length) 0 0 0
80 0 ▶ $document->children->grep(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
81 0 ▶ s_command('head1', $_) and $_->content eq "VERSION\n"
Branch: 1 branch
BranchTrueFalseTotal
s_command("head1", $_) and $_->content eq "VERSION\n" 0 0 0
82 })->length
83 ) {
84 0 my $version_section = Pod::Elemental::Element::Nested->new({
85 command => 'head1',
86 content => "VERSION\n",
87 children => [
88 Pod::Elemental::Element::Pod5::Ordinary->new({
89 content => sprintf "version %s\n", $self->zilla->version,
90 }),
91 ],
92 });
93  
94 0 $document->children->unshift($version_section);
95 }
96  
97 0 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($document->children->grep(sub { s_command("head1", $_) and $_->content eq "NAME\n"; } )->length) 0 0 0
98 0 ▶ $document->children->grep(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
99 0 ▶ s_command('head1', $_) and $_->content eq "NAME\n"
Branch: 1 branch
BranchTrueFalseTotal
s_command("head1", $_) and $_->content eq "NAME\n" 0 0 0
100 })->length
101 ) {
102 Carp::croak "couldn't find package declaration in " . $arg->{filename}
103 0 ▶ unless my $pkg_node = $doc->{ppi}->find_first('PPI::Statement::Package');
Branch: 1 branch
BranchTrueFalseTotal
unless my $pkg_node = $doc->{"ppi"}->find_first("PPI::Statement::Package") 0 0 0
104  
105 0 my $package = $pkg_node->namespace;
106  
107 $self->log("couldn't find abstract in " . $arg->{filename})
108 0 ▶ unless my ($abstract) = $doc->{ppi} =~ /^\s*#+\s*ABSTRACT:\s*(.+)$/m;
Branch: 1 branch
BranchTrueFalseTotal
unless my($abstract) = $doc->{"ppi"} =~ /^\s*#+\s*ABSTRACT:\s*(.+)$/mu 0 0 0
109  
110 0 my $name = $package;
111 0 ▶ $name .= " - $abstract" if $abstract;
Branch: 1 branch
BranchTrueFalseTotal
if $abstract 0 0 0
112  
113 0 my $name_section = Pod::Elemental::Element::Nested->new({
114 command => 'head1',
115 content => "NAME\n",
116 children => [
117 Pod::Elemental::Element::Pod5::Ordinary->new({
118 content => "$name\n",
119 }),
120 ],
121 });
122  
123 0 $document->children->unshift($name_section);
124 }
125  
126 0 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($document->children->grep(sub { s_command("head1", $_) and $_->content =~ /\AAUTHORS?\n\z/u; } )->length) 0 0 0
127 0 ▶ $document->children->grep(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
128 0 ▶ s_command('head1', $_) and $_->content =~ /\AAUTHORS?\n\z/
Branch: 1 branch
BranchTrueFalseTotal
s_command("head1", $_) and $_->content =~ /\AAUTHORS?\n\z/u 0 0 0
129 })->length
130 ) {
131 0 my @authors = $self->zilla->authors->flatten;
132 0 ▶ my $name = @authors > 1 ? 'AUTHORS' : 'AUTHOR';
Branch: 1 branch
BranchTrueFalseTotal
@authors > 1 ? : 0 0 0
133  
134 0 my $author_section = Pod::Elemental::Element::Nested->new({
135 command => 'head1',
136 content => "$name\n",
137 children => [
138 Pod::Elemental::Element::Pod5::Ordinary->new({
139 content => join("\n", @authors) . "\n"
140 }),
141 ],
142 });
143  
144 0 $document->children->push($author_section);
145 }
146  
147 0 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($document->children->grep(sub { s_command("head1", $_) and $_->content =~ /\A(?:COPYRIGHT|LICENSE)\n\z/u; } )->length) 0 0 0
148 0 ▶ $document->children->grep(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
149 0 ▶ s_command('head1', $_) and $_->content =~ /\A(?:COPYRIGHT|LICENSE)\n\z/
Branch: 1 branch
BranchTrueFalseTotal
s_command("head1", $_) and $_->content =~ /\A(?:COPYRIGHT|LICENSE)\n\z/u 0 0 0
150 })->length
151 ) {
152 0 my $legal_section = Pod::Elemental::Element::Nested->new({
153 command => 'head1',
154 content => "COPYRIGHT AND LICENSE\n",
155 children => [
156 Pod::Elemental::Element::Pod5::Ordinary->new({
157 content => $self->zilla->license->notice
158 }),
159 ],
160 });
161  
162 0 $document->children->push($legal_section);
163 }
164  
165 return {
166 pod => $document,
167 ppi => $doc->{ppi},
168 0 };
169 }
170  
171 0 ▶sub munge_pod {
Subroutine munge_pod: not called CC=1 SCAR=6.9
Pod undocumented
172 0 my ($self, $file) = @_;
173  
174 0 my $content = $file->content;
175 0 my $new_content = $self->munge_perl_string(
176 $content,
177 {
178 filename => $file->name,
179 },
180 );
181  
182 0 $file->content($new_content);
183 }
184  
185 1 with 'Pod::Elemental::PerlMunger';
186  
187 1 __PACKAGE__->meta->make_immutable;
188 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
189 1 1;
190  
191 __END__
↑ Summary