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