Badges.pm

filter: Statementstmt 89.7% 70 / 78 Branchbran 43.7% 7 / 16 Conditioncond 50.0% 6 / 12 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 82.3% 14 / 17 Podpod 0.0% 0 / 3 totaltotal 73.6% 98 / 133 CC 14 SCAR 19.1
CC
14
Cov
78%
weave_section
13.3
main_module
12.0
__ANON__
2.0
CRAP 6.8
↑ Summary Badges/Utils.pm »
1 3 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Pod::Weaver::Section::Badges;
6  
7 # ABSTRACT: Add (or append) a section with badges
8 3 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9 3 our $VERSION = '0.0402';
10  
11 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use MooseX::AttributeDocumented;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use PerlX::Maybe qw/provided/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Types::Standard -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Pod::Weaver::Section::Badges::PluginSearcher;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 with qw/
18 Pod::Weaver::Role::Section
19 Pod::Weaver::Role::AddTextToSection
20 Pod::Weaver::Section::Badges::Utils
21 /;
22  
23 4 ▶sub mvp_multivalue_args { qw/badge/ }
Subroutine mvp_multivalue_args: called CC=1 SCAR=0.0
Pod undocumented
24  
25 3 has '+weaver' => (
26 is => 'ro',
27 documentation_order => 0,
28 traits => ['Documented'],
29 );
30 3 has '+logger' => (
31 is => 'ro',
32 traits => ['Documented'],
33 documentation_order => 0,
34 );
35 3 has '+plugin_name' => (
36 is => 'ro',
37 documentation_order => 0,
38 traits => ['Documented'],
39 );
40  
41 has badge => (
42 is => 'ro',
43 isa => ArrayRef[Str],
44 traits => ['Array'],
45 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 3 handles => {
47 all_badges => 'elements',
48 find_badge => 'first',
49 count_badges => 'count',
50 },
51 documentation => q{The name of the wanted badge, lowercased. Repeat for multiple badges. The name is everything after 'Badge::Depot::Plugin::'.},
52 documentation_default => '[]',
53 );
54 3 has section => (
55 is => 'ro',
56 isa => Str,
57 default => 'NAME',
58 documentation => q{The section of pod to add the badges to, identified by its heading. The section will be created if it doesn't already exist.},
59 );
60 3 has formats => (
61 is => 'ro',
62 isa => ArrayRef[Enum[qw/html markdown/]],
63 traits => ['Array'],
64 required => 1,
65 handles => {
66 all_formats => 'elements',
67 find_format => 'first',
68 has_formats => 'count',
69 },
70 documentation => q{The formats to render the badges for. Comma separated list, not multiple rows.},
71 documentation_default => '[]',
72 );
73 3 has skip_markdown_if_html => (
74 is => 'ro',
75 isa => Bool,
76 default => 1,
77 documentation => q{Some markdown renderers also renders '=begin html' blocks, which makes it unnecessary to set both html and markdown as output formats. Set this to a false value to produce both blocks.},
78 );
79  
80 has badge_args => (
81 is => 'ro',
82 isa => HashRef[Str],
83 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 3 traits => ['Hash'],
85 handles => {
86 badge_args_kv => 'kv',
87 },
88 documentation_order => 0,
89 );
90 has plugin_searcher => (
91 is => 'ro',
92 isa => Any,
93 init_arg => undef,
94 4 ▶ default => sub { Pod::Weaver::Section::Badges::PluginSearcher->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
95 3 documentation_order => 0,
96 );
97 3 has main_module_only => (
98 is => 'ro',
99 isa => Bool,
100 default => 1,
101 documentation => 'If true, the badges will only be inserted in the main module (as defined by Dist::Zilla). If false, they will be included in all modules.',
102 );
103  
104  
105 4 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
106 4 my $next = shift;
107 4 my $class = shift;
108 4 my $args = shift;
109 4 ▶ $args->{'formats'} = exists $args->{'formats'} ? [ split /, ?/ => $args->{'formats'} ] : [];
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'formats'} ? : 4 0 4
110 4 $args->{'badge_args'} = { map { $_ => delete $args->{ $_ } } grep { /^-/ } keys %$args };
111  
112 4 $class->$next($args);
113 3 };
114  
115 0 ▶sub main_module {
Subroutine main_module: not called CC=3 SCAR=24.8
Pod undocumented
116 0 my $self = shift;
117 0 my $input = shift;
118  
119 # Use the main_module as defined by Dist::Zilla if it is available
120 0 ▶ return $input->{'zilla'}->main_module->name if exists $input->{'zilla'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $input->{"zilla"} 0 0 0
121  
122 # Taken from Dist::Zilla
123 # If your distribution is Foo-Bar, and lib/Foo/Bar.pm exists, that's the main_module.
124 0 (my $guess = 'lib/' . $input->{'meta'}{'name'} . '.pm') =~ s{-}{/}g;
125 0 ▶ return -e $guess ? $guess : undef;
Branch: 1 branch
BranchTrueFalseTotal
-e $guess ? : 0 0 0
126 }
127  
128 4 ▶sub weave_section {
Subroutine weave_section: called CC=11 SCAR=25.9
Pod undocumented
129 4 my $self = shift;
130 4 my $document = shift;
131 4 my $input = shift;
132  
133 4 ▶ return if $self->main_module_only && $input->{'filename'} ne $self->main_module($input);
Branch: 1 branch
BranchTrueFalseTotal
if $self->main_module_only and $input->{"filename"} ne $self->main_module($input) 0 4 4
Condition33%1/3
$self->main_module_only and $input->{"filename"} ne $self->main_module($input)
!ll&&!rl&&r
400
MC/DC0%0/2
$self->main_module_only and $input->{"filename"} ne $self->main_module($input)
$self->main_module_only $input->{"filename"} ne $self->main_module($input)
Truth table33%1/3
A and B
A= $self->main_module_onlyB= $input->{"filename"} ne $self->main_module($input)
ABresult
0X0
100
111
134  
135 my $badges_args = {
136 4 ▶ provided ref $input eq 'HASH' && exists $input->{'zilla'}, zilla => $input->{'zilla'},
Condition33%1/3
ref $input eq 'HASH' && exists $input->{'zilla'}
!ll&&!rl&&r
004
MC/DC0%0/2
ref $input eq 'HASH' && exists $input->{'zilla'}
ref $input eq 'HASH' exists $input->{'zilla'}
Truth table33%1/3
A && B
A= ref $input eq 'HASH'B= exists $input->{'zilla'}
ABresult
0X0
100
111
137 };
138 4 my $badge_objects = $self->create_badges($badges_args);
139 4 ▶ return if !scalar @$badge_objects;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$badge_objects 0 4 4
140  
141 4 ▶ if(!$self->has_formats) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_formats) 0 4 4
142 0 $self->log(['!!! No formats defined in weaver.ini, no badges to create.']);
143 }
144  
145 4 my $formats = [
146 {
147 name => 'html',
148 before => '<p>',
149 after => '</p>',
150 },
151 {
152 name => 'markdown',
153 before => undef,
154 after => undef,
155 }
156 ];
157  
158 4 my @output = ();
159 FORMAT:
160 4 foreach my $format (@$formats) {
161 # Optionally skip markdown if we also prints to html
162 8 ▶ next FORMAT if $format->{'name'} eq 'markdown' && $self->find_format(sub { $_ eq 'html'}) && $self->skip_markdown_if_html;
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
if $format->{"name"} eq "markdown" and $self->find_format(sub { $_ eq "html"; } ) and $self->skip_markdown_if_html 4 4 8
Condition66%4/6
$format->{"name"} eq "markdown" and $self->find_format(sub { $_ eq "html"; } ) and $self->skip_markdown_if_html
!ll&&!rl&&r
404
$format->{"name"} eq "markdown" and $self->find_format(sub { $_ eq "html"; } )
!ll&&!rl&&r
404
MC/DC33%1/3
$format->{"name"} eq "markdown" and $self->find_format(sub { $_ eq "html"; } ) and $self->skip_markdown_if_html
$format->{"name"} eq "markdown" $self->find_format(sub { $_ eq "html"; } ) $self->skip_markdown_if_html
Truth table50%2/4
A and B and C
A= $format->{"name"} eq "markdown"B= $self->find_format(sub { $_ eq "html"; } )C= $self->skip_markdown_if_html
ABCresult
0XX0
10X0
1100
1111
163 4 push @output => @{ $self->render_badges($format, $badge_objects) };
164 }
165  
166 4 ▶ if(scalar @output) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @output) 4 0 4
167 4 my $output = join "\n" => '', @output, '';
168  
169 4 $self->add_text_to_section($document, $output, $self->section);
170 }
171 }
172  
173 3 __PACKAGE__->meta->make_immutable;
174  
175 3 1;
176  
177 __END__
↑ Summary Badges/Utils.pm »