summaryrefslogtreecommitdiff
path: root/inc/CheckReleaseType.pm
blob: 6e79958bf21841dc62bec54d4184a92a2b06cc31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package inc::CheckReleaseType;
use Moose;
with 'Dist::Zilla::Role::BeforeRelease';

# this is so I don't accidentally release 2.x<odd>xx without the --trial
# option, which has very nearly happened a few times.

sub before_release
{
    my $self = shift;
    my $version = $self->zilla->version;

    $version =~ m/^\d\.\d{4}$/
        or $self->log_fatal("version $version doesn't seem to conform to the normal specification!");

    my $digit = substr($version, 3, 1);
    if ($self->zilla->is_trial)
    {
        $digit % 2 == 1
            or $self->log_fatal('-TRIAL releases must be numbered 2.x{ODD}xx!');
    }
    else
    {
        $digit % 2 == 0
            or $self->log_fatal('stable releases must be numbered 2.x{EVEN}xx!');

        # Moose::Manual::Support says:
        # 2.x{EVEN}00 must be January, April, July, October only.
        if (substr($version, -2, 2) eq '00')
        {
            # month is 0..11
            my $month = (gmtime(time))[4];
            $month % 3 == 0
                or $self->log_fatal('2.x{EVEN}00 releases can only occur in January, April, July or October!');
        }
    }
}