Pod/Weaver/Section/Requirements.pm

filter: Statementstmt 97.3% 72 / 74 Branchbran 72.7% 16 / 22 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 1 totaltotal 87.7% 107 / 122 CC 14 SCAR 19.7
CC
14
Cov
89%
weave_section
14.1
_module_link
2.0
BEGIN
1.0
CRAP 7.2
« Pod/Weaver/Section/InstallationInstructions.pm ↑ Summary Dist/Zilla/Plugin/UsefulReadme.pm »
1 package Pod::Weaver::Section::Requirements;
2  
3 # ABSTRACT: generate POD with the runtime requirements
4  
5 11 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 with 'Pod::Weaver::Role::Section';
9  
10 11 ▶use List::Util qw( first );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use MooseX::MungeHas;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use Perl::PrereqScanner 1.024;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use Pod::Elemental::Element::Nested;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use Pod::Elemental::Element::Pod5::Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶use Pod::Elemental::Element::Pod5::Ordinary;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use Pod::Elemental::Element::Pod5::Region;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶use Types::Common qw( Bool NonEmptySimpleStr SimpleStr );
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 11 ▶use experimental qw( lexical_subs signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 11 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 11 our $VERSION = 'v0.6.0';
24  
25  
26 11 has header => (
27 is => 'rw',
28 isa => NonEmptySimpleStr,
29 default => 'REQUIREMENTS',
30 );
31  
32  
33 11 has region => (
34 is => 'rw',
35 isa => SimpleStr,
36 default => '',
37 );
38  
39  
40 11 has metafile => (
41 is => 'rw',
42 isa => SimpleStr,
43 default => 'cpanfile',
44 );
45  
46  
47 11 has all_modules => (
48 is => 'rw',
49 isa => Bool,
50 default => 0,
51 );
52  
53  
54 11 has guess_prereqs => (
55 is => 'rw',
56 isa => Bool,
57 default => 0,
58 );
59  
60 11 ▶sub weave_section( $self, $document, $input ) {
Subroutine weave_section: called CC=13 SCAR=26.5
Pod undocumented
61  
62 11 my $zilla = $input->{zilla};
63  
64 11 ▶ unless ($zilla) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($zilla) 0 11 11
65 0 $self->log_fatal("missing zilla argument");
66 0 return;
67 }
68  
69 11 ▶ if ( $zilla && !$self->all_modules ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zilla and not $self->all_modules) 11 0 11
Condition33%1/3
$zilla and not $self->all_modules
!ll&&!rl&&r
0011
MC/DC0%0/2
$zilla and not $self->all_modules
$zilla not $self->all_modules
Truth table33%1/3
A and not(B)
A= $zillaB= not $self->all_modules
ABresult
0X0
100
111
70 11 ▶ return if $zilla->main_module->name ne $input->{filename};
Branch: 1 branch
BranchTrueFalseTotal
if $zilla->main_module->name ne $input->{"filename"} 0 11 11
71 }
72  
73 11 ▶ if ( my $stash = $zilla ? $zilla->stash_named('%PodWeaver') : undef ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $stash = $zilla ? $zilla->stash_named("%PodWeaver") : undef) 1 10 11
$zilla ? : 11 0 11
74 1 $stash->merge_stashed_config($self);
75 }
76  
77 11 my $runtime = $zilla->prereqs->as_string_hash->{runtime}{requires};
78  
79 11 ▶ if ( !$runtime && $self->guess_prereqs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $runtime and $self->guess_prereqs) 1 10 11
Condition66%2/3
not $runtime and $self->guess_prereqs
!ll&&!rl&&r
1001
MC/DC50%1/2
not $runtime and $self->guess_prereqs
not $runtime $self->guess_prereqs
Truth table66%2/3
not(A) and B
A= not $runtimeB= $self->guess_prereqs
ABresult
0X0
100
111
80 1 my $scanner = Perl::PrereqScanner->new;
81 1 my $prereqs = $scanner->scan_ppi_document($input->{ppi_document} );
82 1 $runtime = $prereqs->as_string_hash;
83 }
84  
85 11 ▶ return unless $runtime;
Branch: 1 branch
BranchTrueFalseTotal
unless $runtime 0 11 11
86  
87 47 ▶ my sub _module_link($name) {
Subroutine _module_link: called CC=2 SCAR=6.9
88 47 my $version = $runtime->{$name};
89  
90 47 my $text = "L<${name}>";
91 47 ▶ $text .= " version ${version} or later" if $version;
Branch: 1 branch
BranchTrueFalseTotal
if $version 11 36 47
92  
93 return (
94 47 Pod::Elemental::Element::Pod5::Command->new(
95 {
96 command => 'item',
97 content => '*'
98 }
99 ),
100 Pod::Elemental::Element::Pod5::Ordinary->new( { content => $text } )
101 );
102 }
103  
104 11 ▶ my @links = ( map { _module_link($_) } sort keys $runtime->%* ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@links) = map({_module_link $_;} sort(keys %$runtime)) or return 11 0 11
105  
106 11 my $res = Pod::Elemental::Element::Nested->new(
107 {
108 type => 'command',
109 command => 'head1',
110 content => $self->header,
111 children => [
112 Pod::Elemental::Element::Pod5::Ordinary->new(
113 { content => "This module lists the following modules as runtime dependencies:" }
114 ),
115 Pod::Elemental::Element::Pod5::Command->new(
116 {
117 command => 'over',
118 content => '4',
119 }
120 ),
121 @links,
122 Pod::Elemental::Element::Pod5::Command->new(
123 {
124 command => 'back',
125 content => '',
126 }
127 )
128 ]
129 }
130 );
131  
132 11 my %files = map { $_->name => 1 } $zilla->files->@*;
133 11 my @metafiles = grep { $_ ne '' } ( $self->metafile, qw( cpm.yml cpanfile META.json META.yml ) );
134 11 ▶ if ( my $file = first { $files{$_} } @metafiles ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = &first(sub { $files{$_}; } , @metafiles)) 7 4 11
135 7 push $res->children->@*,
136 Pod::Elemental::Element::Pod5::Ordinary->new(
137 { content => "See the F<${file}> file for the full list of prerequisites." } );
138 }
139  
140 11 ▶ if ( my $name = $self->region ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = $self->region) { } 2 9 11
141  
142 2 push $document->children->@*,
143 Pod::Elemental::Element::Pod5::Region->new(
144 {
145 format_name => $name =~ s/^://r,
146 is_pod => 1,
147 content => '',
148 children => [$res],
149 }
150 );
151  
152 }
153 else {
154 9 push $document->children->@*, $res;
155 }
156  
157 }
158  
159 11 __PACKAGE__->meta->make_immutable;
160  
161 __END__
« Pod/Weaver/Section/InstallationInstructions.pm ↑ Summary Dist/Zilla/Plugin/UsefulReadme.pm »