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

filter: Statementstmt 98.4% 63 / 64 Branchbran 75.0% 6 / 8 Conditioncond 66.6% 8 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 93.7% 15 / 16 Podpod 0.0% 0 / 3 totaltotal 82.8% 92 / 111 CC 11 SCAR 10.2
CC
11
Cov
92%
__ANON__
5.0
prune_files
4.1
gather_files
4.1
CRAP 2.8
↑ Summary
1 package Dist::Zilla::Plugin::CodeOfConduct;
2  
3 2 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: add a Code of Conduct to a distribution
6  
7 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 with qw( Dist::Zilla::Role::FileGatherer Dist::Zilla::Role::PrereqSource Dist::Zilla::Role::FilePruner );
9  
10 2 ▶use Dist::Zilla::File::InMemory;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Dist::Zilla::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Email::Address 1.910;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use MooseX::Types::Common::String qw( NonEmptyStr );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use MooseX::Types::Moose qw( HashRef );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use MooseX::Types::Perl qw( StrictVersionStr );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Software::Policy::CodeOfConduct v0.4.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 ▶use experimental qw( postderef signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 2 our $VERSION = 'v0.1.2';
23  
24  
25  
26 2 has version => (
27 is => 'ro',
28 isa => StrictVersionStr,
29 default => 'v0.4.0',
30 );
31  
32  
33 2 has filename => (
34 is => 'ro',
35 isa => NonEmptyStr,
36 default => 'CODE_OF_CONDUCT.md',
37 );
38  
39 has _policy_args => (
40 is => 'ro',
41 isa => HashRef,
42 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 2 );
44  
45 2 ▶around plugin_from_config => sub( $orig, $class, $name, $args, $section ) {
Subroutine __ANON__: called CC=5 SCAR=16.1
46 2 my %module_args;
47  
48 2 for my $key ( keys $args->%* ) {
49 7 ▶ if ( $key =~ s/^-// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ s/^-//u) { } 1 6 7
50 1 ▶ die "$key cannot be set" if $key eq "_policy_args";
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "_policy_args" 0 1 1
51 1 $module_args{$key} = $args->{"-$key"};
52 }
53 else {
54 6 $module_args{_policy_args}{$key} = $args->{$key};
55 }
56 }
57  
58 2 ▶ $module_args{filename} = $module_args{_policy_args}{filename} if $module_args{_policy_args}{filename};
Branch: 1 branch
BranchTrueFalseTotal
if $module_args{"_policy_args"}{"filename"} 1 1 2
59  
60 2 return $class->$orig( $name, \%module_args, $section );
61 2 };
62  
63 2 ▶sub gather_files($self) {
Subroutine gather_files: called CC=4 SCAR=14.0
Pod undocumented
64  
65 2 my $zilla = $self->zilla;
66  
67 2 my %args = $self->_policy_args->%*;
68  
69 2 my ($author) = Email::Address->parse( $zilla->distmeta->{author}[0] );
70  
71 2 ▶ $args{name} //= $zilla->distmeta->{name};
Condition66%2/3
$args{"name"} //= $zilla->distmeta->{"name"}
l!l&&r!l&&!r
110
MC/DC0%0/2
$args{"name"} //= $zilla->distmeta->{"name"}
$args{"name"} $zilla->distmeta->{"name"}
Truth table66%2/3
A //= B
A= $args{"name"}B= $zilla->distmeta->{"name"}
ABresult
1X1
011
000
72 2 ▶ $args{contact} //= $author->address;
Condition66%2/3
$args{"contact"} //= $author->address
l!l&&r!l&&!r
110
MC/DC0%0/2
$args{"contact"} //= $author->address
$args{"contact"} $author->address
Truth table66%2/3
A //= B
A= $args{"contact"}B= $author->address
ABresult
1X1
011
000
73 2 ▶ $args{filename} //= $self->filename;
Condition66%2/3
$args{"filename"} //= $self->filename
l!l&&r!l&&!r
110
MC/DC0%0/2
$args{"filename"} //= $self->filename
$args{"filename"} $self->filename
Truth table66%2/3
A //= B
A= $args{"filename"}B= $self->filename
ABresult
1X1
011
000
74  
75 2 my $policy = Software::Policy::CodeOfConduct->new(%args);
76  
77 2 $self->add_file(
78 Dist::Zilla::File::InMemory->new(
79 name => $policy->filename,
80 content => $policy->fulltext,
81 )
82 );
83  
84 2 return;
85 }
86  
87 2 ▶sub register_prereqs($self) {
Subroutine register_prereqs: called CC=1 SCAR=0.0
Pod undocumented
88 2 $self->zilla->register_prereqs( { phase => 'develop' }, "Software::Policy::CodeOfConduct" => $self->version );
89 2 return;
90 }
91  
92 2 ▶sub prune_files($self) {
Subroutine prune_files: called CC=4 SCAR=14.2
Pod undocumented
93 2 my @files = @{ $self->zilla->files };
94 2 my $filename = $self->filename;
95 2 for my $file (@files) {
96 4 ▶ $self->zilla->prune_file($file) if $file->name eq $filename && $file->added_by !~ __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if $file->name eq $filename and not $file->added_by =~ /Dist::Zilla::Plugin::CodeOfConduct/u 0 4 4
Condition66%2/3
$file->name eq $filename and not $file->added_by =~ /Dist::Zilla::Plugin::CodeOfConduct/u
!ll&&!rl&&r
220
MC/DC0%0/2
$file->name eq $filename and not $file->added_by =~ /Dist::Zilla::Plugin::CodeOfConduct/u
$file->name eq $filename not $file->added_by =~ /Dist::Zilla::Plugin::CodeOfConduct/u
Truth table66%2/3
A and not(B)
A= $file->name eq $filenameB= not $file->added_by =~ /Dist::Zilla::Plugin::CodeOfConduct/u
ABresult
0X0
100
111
97 }
98 }
99  
100  
101  
102 2 __PACKAGE__->meta->make_immutable;
103  
104 __END__
↑ Summary