blib/lib/Dist/Zilla/Plugin/AutoVersion/Relative.pm

filter: Statementstmt 84.5% 71 / 84 Branchbran 33.3% 2 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 16 / 20 Podpod 100% 1 / 1 totaltotal 81.0% 90 / 111 CC 3 SCAR 5.2
CC
3
Cov
81%
__ANON__
6.0
_build__release_time
2.1
__ANON__
2.0
CRAP 1.7
↑ Summary
1 2 ▶use 5.006; # our
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Dist::Zilla::Plugin::AutoVersion::Relative;
6  
7 2 our $VERSION = '1.001001';
8  
9 # ABSTRACT: Time-Relative versioning
10  
11 2 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 2 ▶use Moose 1.09 qw( has around with );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use MooseX::Types::Moose qw( Int Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use MooseX::Types::DateTime qw( TimeZone Duration Now );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use MooseX::StrictConstructor 0.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use Const::Fast qw( const );
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 const my $MONTHS_IN_YEAR => 12;
21  
22 2 const my $DAYS_IN_MONTH => 31; # This is assumed, makes our years square.
23  
24 2 with( 'Dist::Zilla::Role::VersionProvider', 'Dist::Zilla::Role::TextTemplate' );
25  
26 2 ▶use DateTime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45 2 has major => ( isa => Int, is => 'ro', default => 1 );
46 2 has minor => ( isa => Int, is => 'ro', default => 1 );
47 2 has format => ( ## no critic (RequireInterpolationOfMetachars)
48 isa => Str,
49 is => 'ro',
50 default => q|{{ sprintf('%d.%02d%04d%02d', $major, $minor, days, hours) }}|,
51 );
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83 2 has year => ( isa => Int, is => 'ro', default => 2000 );
84 2 has month => ( isa => Int, is => 'ro', default => 1 );
85 2 has day => ( isa => Int, is => 'ro', default => 1 );
86 2 has hour => ( isa => Int, is => 'ro', default => 0 );
87 2 has minute => ( isa => Int, is => 'ro', default => 0 );
88 2 has second => ( isa => Int, is => 'ro', default => 0 );
89 2 has time_zone => ( isa => TimeZone, coerce => 1, is => 'ro', predicate => 'has_time_zone' );
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105 2 has '_release_time' => ( isa => 'DateTime', coerce => 1, is => 'ro', lazy_build => 1 );
106 2 has '_current_time' => ( isa => 'DateTime', coerce => 1, is => 'ro', lazy_build => 1 );
107 2 has 'relative' => ( isa => Duration, coerce => 1, is => 'ro', lazy_build => 1 );
108  
109 2 ▶if ( __PACKAGE__->can('dump_config') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (__PACKAGE__->can("dump_config")) 2 0 2
110 0 ▶ around dump_config => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
111 0 my ( $orig, $self, @args ) = @_;
112 0 my $config = $self->$orig(@args);
113 0 my $localconf = $config->{ +__PACKAGE__ } = {};
114  
115 0 $localconf->{major} = $self->major;
116 0 $localconf->{minor} = $self->minor;
117 0 $localconf->{format} = $self->format;
118 $localconf->{relative_to} = {
119 0 year => $self->year,
120 month => $self->month,
121 day => $self->day,
122 hour => $self->hour,
123 minute => $self->minute,
124 second => $self->second,
125 time_zone => q{} . $self->time_zone->name,
126 };
127  
128 0 ▶ $localconf->{ q[$] . __PACKAGE__ . '::VERSION' } = $VERSION
Branch: 1 branch
BranchTrueFalseTotal
unless __PACKAGE__ eq ref $self 0 0 0
129 unless __PACKAGE__ eq ref $self;
130  
131 0 return $config;
132  
133 2 };
134 }
135  
136  
137  
138  
139  
140 5 ▶sub _build__release_time {
Subroutine _build__release_time: called CC=2 SCAR=7.2
141 5 my $self = shift;
142 5 ▶ return DateTime->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->has_time_zone ? : 0 5 5
143 year => $self->year,
144 month => $self->month,
145 day => $self->day,
146 hour => $self->hour,
147 minute => $self->minute,
148 second => $self->second,
149 ( ( $self->has_time_zone ) ? ( time_zone => $self->time_zone ) : () ),
150 );
151 }
152  
153  
154  
155  
156  
157 4 ▶sub _build__current_time {
Subroutine _build__current_time: called CC=1 SCAR=0.0
158 4 return DateTime->now;
159 }
160  
161  
162  
163  
164  
165 5 ▶sub _build_relative {
Subroutine _build_relative: called CC=1 SCAR=0.0
166 5 my $self = shift;
167 5 my $x = $self->_current_time->subtract_datetime( $self->_release_time );
168 5 return $x;
169 }
170  
171  
172  
173  
174  
175  
176  
177 {
178 2 my $av_track = 0;
179  
180 5 ▶ sub provide_version {
Subroutine provide_version: called CC=1 SCAR=0.3
Pod documented
181 5 my ($self) = @_;
182 5 $av_track++;
183  
184 5 my ( $y, $m, $d, $h, undef, undef ) = $self->relative->in_units( 'years', 'months', 'days', 'hours', 'minutes', 'seconds' );
185  
186 0 ▶ my ($days_square) = sub() {
Subroutine __ANON__: not called CC=1 SCAR=6.9
187 0 ( ( ( ( $y * $MONTHS_IN_YEAR ) + $m ) * $DAYS_IN_MONTH ) + $d );
188 5 };
189 5 ▶ my ($days_accurate) = sub() {
Subroutine __ANON__: called CC=1 SCAR=0.0
190 5 $self->_current_time->delta_days( $self->_release_time )->in_units('days');
191 5 };
192  
193 my $tokens = {
194 major => \( $self->major ),
195 minor => \( $self->minor ),
196 relative => \( $self->relative ),
197 0 ▶ cldr => sub($) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
198 0 my ($format) = shift;
199 0 $self->_current_time->format_cldr($format);
200 },
201 days => $days_accurate,
202 days_square => $days_square,
203 days_accurate => $days_accurate,
204 0 ▶ hours => sub() { $h },
Subroutine __ANON__: not called CC=1 SCAR=6.9
205 5 };
206  
207 5 my $version = $self->fill_in_string( $self->format, $tokens, { 'package' => "AutoVersion::_${av_track}_", }, );
208 5 return $version;
209 }
210 }
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
266 2 __PACKAGE__->meta->make_immutable;
267  
268 2 1;
269  
270 __END__
↑ Summary