blib/lib/Dist/Zilla/Plugin/ReleaseStatus/FromVersion.pm

filter: Statementstmt 100% 52 / 52 Branchbran 68.7% 11 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 2 totaltotal 87.6% 78 / 89 CC 11 SCAR 9.6
CC
11
Cov
90%
__ANON__
4.6
provide_release_status
4.0
__ANON__
3.1
CRAP 2.6
↑ Summary
1 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Dist::Zilla::Plugin::ReleaseStatus::FromVersion;
6 # ABSTRACT: Set release status from version number patterns
7  
8 1 our $VERSION = '0.001';
9  
10 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Moose::Util::TypeConstraints qw/enum/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 STABLE => 'stable',
16 TESTING => 'testing',
17 UNSTABLE => 'unstable',
18 1 };
19  
20 my %RULES = (
21 15 ▶ none => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
22 1 second_decimal_odd => _odd_digit_checker(2),
23 third_decimal_odd => _odd_digit_checker(3),
24 fourth_decimal_odd => _odd_digit_checker(4),
25 fifth_decimal_odd => _odd_digit_checker(5),
26 sixth_decimal_odd => _odd_digit_checker(6),
27 second_element_odd => _odd_tuple_checker(2),
28 third_element_odd => _odd_tuple_checker(3),
29 fourth_element_odd => _odd_tuple_checker(4),
30 );
31  
32 1 enum VersionMode => [ keys %RULES ];
33  
34 #pod =attr testing
35 #pod
36 #pod Rule for setting status to 'testing'. Must be one of the L</Status Rules>.
37 #pod
38 #pod The default is C<none>.
39 #pod
40 #pod =cut
41  
42 1 has testing => (
43 is => 'ro',
44 isa => 'VersionMode',
45 default => 'none',
46 );
47  
48 #pod =attr unstable
49 #pod
50 #pod Rule for setting status to 'unstable'. Must be one of the L</Status rules>.
51 #pod
52 #pod This setting takes precedence over C<testing>.
53 #pod
54 #pod The default is C<none>.
55 #pod
56 #pod =cut
57  
58 1 has unstable => (
59 is => 'ro',
60 isa => 'VersionMode',
61 default => 'none',
62 );
63  
64 38 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.1
Pod undocumented
65 38 my ($self) = @_;
66 38 for my $type ( TESTING, UNSTABLE ) {
67 76 my $rule = $self->$type;
68 $self->logger->log_fatal("Unknown rule for '$type': $rule")
69 76 ▶ unless $RULES{$rule};
Branch: 1 branch
BranchTrueFalseTotal
unless $RULES{$rule} 0 76 76
70 }
71 }
72  
73 38 ▶sub provide_release_status {
Subroutine provide_release_status: called CC=4 SCAR=13.9
Pod undocumented
74 38 my $self = shift;
75 38 my $version = version->new( $self->zilla->version );
76  
77 38 ▶ $self->logger->log_fatal("Versions with underscore ('$version') are not supported")
Branch: 1 branch
BranchTrueFalseTotal
if $version =~ /_/ 2 36 38
78 if $version =~ /_/;
79  
80 return
81 $RULES{ $self->unstable }->($version) ? UNSTABLE
82 36 ▶ : $RULES{ $self->testing }->($version) ? TESTING
Branch: 2 branches
BranchTrueFalseTotal
$RULES{$self->unstable}($version) ? : 16 20 36
$RULES{$self->testing}($version) ? : 6 14 20
83 : STABLE;
84 }
85  
86 #--------------------------------------------------------------------------#
87 # utility functions
88 #--------------------------------------------------------------------------#
89  
90 5 ▶sub _odd_digit_checker {
Subroutine _odd_digit_checker: called CC=1 SCAR=0.2
91 5 my $pos = shift;
92 21 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=15.2
93 21 my $version = shift;
94 21 ▶ return if $version->is_qv;
Branch: 1 branch
BranchTrueFalseTotal
if $version->is_qv 0 21 21
95 21 my ($fraction) = $version =~ m{\.(\d+)\z};
96 21 ▶ return unless defined($fraction) && length($fraction) >= $pos;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fraction and length $fraction >= $pos 0 21 21
Condition33%1/3
defined $fraction and length $fraction >= $pos
!ll&&!rl&&r
0021
MC/DC0%0/2
defined $fraction and length $fraction >= $pos
defined $fraction length $fraction >= $pos
Truth table33%1/3
A and B
A= defined $fractionB= length $fraction >= $pos
ABresult
0X0
100
111
97 21 return substr( $fraction, $pos - 1, 1 ) % 2;
98 5 };
99 }
100  
101 3 ▶sub _odd_tuple_checker {
Subroutine _odd_tuple_checker: called CC=1 SCAR=0.0
102 3 my $pos = shift;
103 20 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
104 20 my $version = shift;
105 20 ▶ return unless $version->is_qv;
Branch: 1 branch
BranchTrueFalseTotal
unless $version->is_qv 0 20 20
106 20 my $string = $version->normal;
107 20 $string =~ s/^v//;
108 20 my @tuples = split /\./, $string;
109 20 ▶ return ( defined( $tuples[ $pos - 1 ] ) ? ( $tuples[ $pos - 1 ] % 2 ) : 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $tuples[$pos - 1] ? : 20 0 20
110 3 };
111 }
112  
113 1 with 'Dist::Zilla::Role::ReleaseStatusProvider';
114  
115 1 __PACKAGE__->meta->make_immutable;
116  
117 1 1;
118  
119  
120 # vim: ts=4 sts=4 sw=4 et tw=75:
121  
122 __END__
↑ Summary