| 1 | package Dist::Zilla::Plugin::AutoVersion 6.040; | ||||||||||||||||||||
| 2 | # ABSTRACT: take care of numbering versions so you don't have to | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | with( | |||||||||||||||||||
| 6 | 'Dist::Zilla::Role::VersionProvider', | ||||||||||||||||||||
| 7 | 'Dist::Zilla::Role::TextTemplate', | ||||||||||||||||||||
| 8 | ); | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | ▶ | use Dist::Zilla::Pragmas; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 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 | 2 | 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 | 2 | has time_zone => ( | |||||||||||||||||||
| 54 | is => 'ro', | ||||||||||||||||||||
| 55 | isa => 'Str', | ||||||||||||||||||||
| 56 | required => 1, | ||||||||||||||||||||
| 57 | default => 'GMT', | ||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 2 | 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 | 3 | ▶ | sub provide_version { | ||||||||||||||||||
|
Subroutine
provide_version: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 70 | 3 | my ($self) = @_; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 3 | ▶ | if (exists $ENV{V}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 1 | $self->log_debug([ 'providing version %s', $ENV{V} ]); | |||||||||||||||||||
| 74 | 1 | return $ENV{V}; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | # TODO declare this as a 'develop' prereq as we want it in | ||||||||||||||||||||
| 78 | # `dzil listdeps --author` | ||||||||||||||||||||
| 79 | 2 | require DateTime; | |||||||||||||||||||
| 80 | 2 | DateTime->VERSION('0.44'); # CLDR fixes | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 2 | my $now; | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | my $version = $self->fill_in_string( | ||||||||||||||||||||
| 85 | $self->format, | ||||||||||||||||||||
| 86 | { | ||||||||||||||||||||
| 87 | major => \( $self->major ), | ||||||||||||||||||||
| 88 | 1 | ▶ | cldr => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||
| 89 | 1 | ▶ | $now ||= do { | ||||||||||||||||||
|
Condition33%1/3
$now ||= do {
require DateTime;
"DateTime"->VERSION("0.44");
"DateTime"->now("time_zone", $self->time_zone)
}
MC/DC0%0/2
$now ||= do {
require DateTime;
"DateTime"->VERSION("0.44");
"DateTime"->now("time_zone", $self->time_zone)
}
$now
do {
require DateTime;
"DateTime"->VERSION("0.44");
"DateTime"->now("time_zone", $self->time_zone)
}
Truth table33%1/3
A ||= B
A= $nowB= do {
require DateTime;
"DateTime"->VERSION("0.44");
"DateTime"->now("time_zone", $self->time_zone)
}
| |||||||||||||||||||||
| 90 | 1 | require DateTime; | |||||||||||||||||||
| 91 | 1 | DateTime->VERSION('0.44'); # CLDR fixes | |||||||||||||||||||
| 92 | 1 | DateTime->now(time_zone => $self->time_zone); | |||||||||||||||||||
| 93 | }; | ||||||||||||||||||||
| 94 | 1 | $now->format_cldr($_[0]) | |||||||||||||||||||
| 95 | }, | ||||||||||||||||||||
| 96 | }, | ||||||||||||||||||||
| 97 | 2 | ); | |||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 2 | $self->log_debug([ 'providing version %s', $version ]); | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 2 | return $version; | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 105 | 2 | 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__ | ||||||||||||||||||||