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

filter: Statementstmt 42.4% 28 / 66 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 3 totaltotal 29.4% 33 / 112 CC 15 SCAR 51.0
CC
15
Cov
29%
before_build
240.0
mvp_aliases
2.0
mvp_multivalue_args
2.0
CRAP 164.0
↑ Summary
1 package Dist::Zilla::Plugin::CopyrightYearFromGit;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 with (
11 'Dist::Zilla::Role::BeforeBuild',
12 );
13  
14 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
15 1 our $DATE = '2021-08-24'; # DATE
16 1 our $DIST = 'Dist-Zilla-Plugin-CopyrightYearFromGit'; # DIST
17 1 our $VERSION = '0.009'; # VERSION
18  
19 1 has min_year => (is => 'rw');
20 1 has release_tag_regex => (is => 'rw');
21 1 has author_name_regex => (is => 'rw');
22 1 has author_email_regex => (is => 'rw');
23 1 has exclude_year => (is => 'rw');
24 1 has include_year => (is => 'rw');
25 1 has continuous_year => (is => 'rw');
26  
27 0 ▶sub mvp_aliases { return { regex => 'release_tag_regex' } }
Subroutine mvp_aliases: not called CC=1 SCAR=6.9
Pod undocumented
28  
29 0 ▶sub mvp_multivalue_args { qw(exclude_year include_year) }
Subroutine mvp_multivalue_args: not called CC=1 SCAR=6.9
Pod undocumented
30  
31 0 ▶sub before_build {
Subroutine before_build: not called CC=15 SCAR=54.8
Pod undocumented
32 0 require Release::Util::Git;
33 0 my $self = shift;
34  
35 0 my @lgry_args;
36 0 ▶ push @lgry_args, defined $self->release_tag_regex ?
Branch: 1 branch
BranchTrueFalseTotal
defined $self->release_tag_regex ? : 0 0 0
37 (release_tag_regex => $self->release_tag_regex) : ();
38 0 ▶ push @lgry_args, defined $self->author_name_regex ?
Branch: 1 branch
BranchTrueFalseTotal
defined $self->author_name_regex ? : 0 0 0
39 (author_name_regex => $self->author_name_regex) : ();
40 0 ▶ push @lgry_args, defined $self->author_email_regex ?
Branch: 1 branch
BranchTrueFalseTotal
defined $self->author_email_regex ? : 0 0 0
41 (author_email_regex => $self->author_email_regex) : ();
42  
43 0 my $res = Release::Util::Git::list_git_release_years(@lgry_args);
44 0 ▶ $self->log_fatal(["%s - %s"], $res->[0], $res->[1]) unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
45  
46 0 my $cur_year = (localtime)[5]+1900;
47  
48 0 my $min_year = $self->min_year;
49 0 ▶ $min_year = $cur_year if defined $min_year && $min_year > $cur_year;
Branch: 1 branch
BranchTrueFalseTotal
if defined $min_year and $min_year > $cur_year 0 0 0
Condition0%0/3
defined $min_year and $min_year > $cur_year
!ll&&!rl&&r
000
MC/DC0%0/2
defined $min_year and $min_year > $cur_year
defined $min_year $min_year > $cur_year
Truth table0%0/3
A and B
A= defined $min_yearB= $min_year > $cur_year
ABresult
0X0
100
111
50  
51 0 my @years = @{ $res->[2] };
52 0 ▶ if (!@years || $years[0] < $cur_year) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @years or $years[0] < $cur_year) 0 0 0
Condition0%0/3
not @years or $years[0] < $cur_year
l!l&&r!l&&!r
000
MC/DC0%0/2
not @years or $years[0] < $cur_year
not @years $years[0] < $cur_year
Truth table0%0/3
not(A) or B
A= not @yearsB= $years[0] < $cur_year
ABresult
1X1
011
000
53 0 unshift @years, $cur_year;
54 }
55  
56 # filter by min_year
57 0 ▶ @years = grep { !defined($min_year) || $_ >= $min_year } @years;
Condition0%0/3
!defined($min_year) || $_ >= $min_year
l!l&&r!l&&!r
000
MC/DC0%0/2
!defined($min_year) || $_ >= $min_year
!defined($min_year) $_ >= $min_year
Truth table0%0/3
not(A) || B
A= !defined($min_year)B= $_ >= $min_year
ABresult
1X1
011
000
58  
59 # add include_year
60 0 ▶ push @years, @{ $self->include_year } if $self->include_year;
Branch: 1 branch
BranchTrueFalseTotal
if $self->include_year 0 0 0
61  
62 # filter by exclude_year
63 0 ▶ if ($self->exclude_year) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->exclude_year) 0 0 0
64 0 my @fyears;
65 0 for my $year (@years) {
66 0 ▶ next if grep { $year eq $_ } @{ $self->exclude_year };
Branch: 1 branch
BranchTrueFalseTotal
if grep {$year eq $_;} @{$self->exclude_year;} 0 0 0
67 0 push @years, $year;
68 }
69 0 @years = @fyears;
70 }
71  
72 # make the years continuous
73 0 ▶ if ($self->continuous_year) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->continuous_year) 0 0 0
74 0 my $min = List::Util::min(@years);
75 0 my $max = List::Util::max(@years);
76 0 @years = $min .. $max;
77 }
78  
79 0 my $year = join(", ", sort {$b <=> $a} @years);
80 0 $self->log(["Setting copyright_year to %s", $year]);
81  
82 # dirty, dirty hack
83 0 $self->zilla->_copyright_year;
84 0 $self->zilla->{_copyright_year} = $year;
85 }
86  
87 1 __PACKAGE__->meta->make_immutable;
88 1 1;
89 # ABSTRACT: Set copyright year from git
90  
91 __END__
↑ Summary