File Coverage

blib/lib/Dist/Zilla/Plugin/AutoVersion.pm
Criterion Covered Total %
statement 24 24 100.0
branch 2 2 100.0
condition 1 3 33.3
subroutine 5 5 100.0
pod 0 1 0.0
total 32 35 91.4


line stmt bran cond sub pod time code
1             # ABSTRACT: take care of numbering versions so you don't have to
2              
3             use Moose;
4 2     2   2102 with(
  2         6  
  2         16  
5             'Dist::Zilla::Role::VersionProvider',
6             'Dist::Zilla::Role::TextTemplate',
7             );
8              
9             use Dist::Zilla::Pragmas;
10 2     2   14281  
  2         4  
  2         22  
11             use namespace::autoclean;
12 2     2   29  
  2         6  
  2         19  
13             #pod =head1 DESCRIPTION
14             #pod
15             #pod This plugin automatically produces a version string, generally based on the
16             #pod current time. By default, it will be in the format: 1.yyDDDn
17             #pod
18             #pod =cut
19              
20             #pod =attr major
21             #pod
22             #pod The C<major> attribute is just an integer that is meant to store the major
23             #pod version number. If no value is specified in configuration, it will default to
24             #pod 1.
25             #pod
26             #pod This attribute's value can be referred to in the autoversion format template.
27             #pod
28             #pod =cut
29              
30             has major => (
31             is => 'ro',
32             isa => 'Int',
33             required => 1,
34             default => 1,
35             );
36              
37             #pod =attr format
38             #pod
39             #pod The format is a L<Text::Template> string that will be rendered to form the
40             #pod version. It is meant to access to one variable, C<$major>, and one subroutine,
41             #pod C<cldr>, which will format the current time (in GMT) using CLDR patterns (for
42             #pod which consult the L<DateTime> documentation).
43             #pod
44             #pod The default value is:
45             #pod
46             #pod {{ $major }}.{{ cldr('yyDDD') }}
47             #pod {{ sprintf('%01u', ($ENV{N} || 0)) }}
48             #pod {{$ENV{DEV} ? (sprintf '_%03u', $ENV{DEV}) : ''}}
49             #pod
50             #pod =cut
51              
52             has time_zone => (
53             is => 'ro',
54             isa => 'Str',
55             required => 1,
56             default => 'GMT',
57             );
58              
59             has format => (
60             is => 'ro',
61             isa => 'Str',
62             required => 1,
63             default => q<{{ $major }}.{{ cldr('yyDDD') }}>
64             . q<{{ sprintf('%01u', ($ENV{N} || 0)) }}>
65             . q<{{$ENV{DEV} ? (sprintf '_%03u', $ENV{DEV}) : ''}}>
66             );
67              
68             my ($self) = @_;
69              
70 3     3 0 9 if (exists $ENV{V}) {
71             $self->log_debug([ 'providing version %s', $ENV{V} ]);
72 3 100       13 return $ENV{V};
73 1         9 }
74 1         30  
75             # TODO declare this as a 'develop' prereq as we want it in
76             # `dzil listdeps --author`
77             require DateTime;
78             DateTime->VERSION('0.44'); # CLDR fixes
79 2         1846  
80 2         371866 my $now;
81              
82 2         8 my $version = $self->fill_in_string(
83             $self->format,
84             {
85             major => \( $self->major ),
86             cldr => sub {
87             $now ||= do {
88             require DateTime;
89 1   33 1   587 DateTime->VERSION('0.44'); # CLDR fixes
90 1         6 DateTime->now(time_zone => $self->time_zone);
91 1         13 };
92 1         43 $now->format_cldr($_[0])
93             },
94 1         1007 },
95             );
96              
97 2         81 $self->log_debug([ 'providing version %s', $version ]);
98              
99 2         28 return $version;
100             }
101 2         206  
102             __PACKAGE__->meta->make_immutable;
103             1;
104              
105             #pod =head1 SEE ALSO
106             #pod
107             #pod Core Dist::Zilla plugins:
108             #pod L<PkgVersion|Dist::Zilla::Plugin::PkgVersion>,
109             #pod L<PodVersion|Dist::Zilla::Plugin::PodVersion>,
110             #pod L<NextRelease|Dist::Zilla::Plugin::NextRelease>.
111             #pod
112             #pod Dist::Zilla roles:
113             #pod L<VersionProvider|Dist::Zilla::Role::VersionProvider>,
114             #pod L<TextTemplate|Dist::Zilla::Role::TextTemplate>.
115             #pod
116             #pod =cut
117              
118              
119             =pod
120              
121             =encoding UTF-8
122              
123             =head1 NAME
124              
125             Dist::Zilla::Plugin::AutoVersion - take care of numbering versions so you don't have to
126              
127             =head1 VERSION
128              
129             version 6.028
130              
131             =head1 DESCRIPTION
132              
133             This plugin automatically produces a version string, generally based on the
134             current time. By default, it will be in the format: 1.yyDDDn
135              
136             =head1 PERL VERSION
137              
138             This module should work on any version of perl still receiving updates from
139             the Perl 5 Porters. This means it should work on any version of perl released
140             in the last two to three years. (That is, if the most recently released
141             version is v5.40, then this module should work on both v5.40 and v5.38.)
142              
143             Although it may work on older versions of perl, no guarantee is made that the
144             minimum required version will not be increased. The version may be increased
145             for any reason, and there is no promise that patches will be accepted to lower
146             the minimum required perl.
147              
148             =head1 ATTRIBUTES
149              
150             =head2 major
151              
152             The C<major> attribute is just an integer that is meant to store the major
153             version number. If no value is specified in configuration, it will default to
154             1.
155              
156             This attribute's value can be referred to in the autoversion format template.
157              
158             =head2 format
159              
160             The format is a L<Text::Template> string that will be rendered to form the
161             version. It is meant to access to one variable, C<$major>, and one subroutine,
162             C<cldr>, which will format the current time (in GMT) using CLDR patterns (for
163             which consult the L<DateTime> documentation).
164              
165             The default value is:
166              
167             {{ $major }}.{{ cldr('yyDDD') }}
168             {{ sprintf('%01u', ($ENV{N} || 0)) }}
169             {{$ENV{DEV} ? (sprintf '_%03u', $ENV{DEV}) : ''}}
170              
171             =head1 SEE ALSO
172              
173             Core Dist::Zilla plugins:
174             L<PkgVersion|Dist::Zilla::Plugin::PkgVersion>,
175             L<PodVersion|Dist::Zilla::Plugin::PodVersion>,
176             L<NextRelease|Dist::Zilla::Plugin::NextRelease>.
177              
178             Dist::Zilla roles:
179             L<VersionProvider|Dist::Zilla::Role::VersionProvider>,
180             L<TextTemplate|Dist::Zilla::Role::TextTemplate>.
181              
182             =head1 AUTHOR
183              
184             Ricardo SIGNES 😏 <cpan@semiotic.systems>
185              
186             =head1 COPYRIGHT AND LICENSE
187              
188             This software is copyright (c) 2022 by Ricardo SIGNES.
189              
190             This is free software; you can redistribute it and/or modify it under
191             the same terms as the Perl 5 programming language system itself.
192              
193             =cut