blib/lib/Build/Daily.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Build::Daily;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 our $VERSION = '0.01';
7  
8 =head1 NAME
9  
10 Build::Daily - module to update daily versions for Module::Build and ExtUtils::MakeMaker
11  
12 =head1 SYNOPSIS
13  
14 perl -MBuild::Daily Build.PL
15 perl -MBuild::Daily Makefile.PL
16
17 # force version append, useful when not building daily but based on ex. SVN revisions
18 perl -MBuild::Daily=version,12345 Build.PL
19 perl -MBuild::Daily=version,12345 Build
20 perl -MBuild::Daily=version,12345 Build distmeta
21 perl -MBuild::Daily=version,12345 Build dist
22  
23 =head1 DESCRIPTION
24  
25 Updates C<$VERSION> string based on current date or forced string. This
26 allows to create daily/commit builds.
27  
28 =head2 FUNCTIONS
29  
30 =cut
31  
32 2 ▶use Module::Build 0.2808;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 0 ▶use Module::Build::ModuleInfo;
Subroutine BEGIN: called CC=1 SCAR=2.6
34 use ExtUtils::MakeMaker;
35 use DateTime;
36  
37 # a references to the original methods
38 my $MODULE_BUILD_NEW;
39 my $EXTUTILS_MM_NEW;
40 BEGIN {
41 $MODULE_BUILD_NEW = \&Module::Build::Base::new;
42 $EXTUTILS_MM_NEW = \&ExtUtils::MakeMaker::new;
43 }
44 our $FORCED_VERSION;
45 our $BUILD_DAILY_VERSION = \&version;
46  
47 =head2 import()
48  
49 use Build::Daily 'version' => '12345';
50  
51 Forces string that will be appended.
52  
53 =cut
54  
55 sub import {
56 my $class = shift;
57 my %args = @_;
58
59 $FORCED_VERSION = $args{'version'};
60 }
61  
62 =head2 version($original_version)
63  
64 For original version returns new version.
65  
66 $original_version.($original_version =~ m/_/ ? '' : '_').$append
67  
68 C<$append> is either YearMonthDay or the forced string.
69  
70 =cut
71  
72 sub version {
73 my $original_version = shift;
74
75 my $append = (
76 defined $FORCED_VERSION
77 ? $FORCED_VERSION
78 : DateTime->now('time_zone' => 'local')->ymd("")
79 );
80
81 return $original_version.($original_version =~ m/_/ ? '' : '_').$append;
82 }
83  
84 no warnings 'redefine';
85  
86 package Module::Build::Base;
87  
88 sub new {
89 my $class = shift;
90 my %args = @_;
91
92 if (defined $args{'dist_version_from'}) {
93 my $info = eval { Module::Build::ModuleInfo->new_from_file($args{'dist_version_from'}) };
94 die 'failed to get VERSION from '.$args{'dist_version_from'}
95 if not defined $info;
96
97 delete $args{'dist_version_from'};
98 $args{'dist_version'} = $info->{'version'}->{'original'};
99 }
100 if (defined $args{'dist_version'}) {
101 $args{'dist_version'} = $BUILD_DAILY_VERSION->($args{'dist_version'});
102 }
103
104 return $MODULE_BUILD_NEW->($class, %args);
105 }
106  
107 package ExtUtils::MakeMaker;
108  
109 sub new {
110 my $class = shift;
111 my $args = shift;
112
113 if (defined $args->{'VERSION_FROM'}) {
114 my $info = eval { Module::Build::ModuleInfo->new_from_file($args->{'VERSION_FROM'}) };
115 die 'failed to get VERSION from '.$args->{'VERSION_FROM'}
116 if not defined $info;
117
118 delete $args->{'VERSION_FROM'};
119 $args->{'VERSION'} = $info->{'version'}->{'original'};
120 }
121 if (defined $args->{'VERSION'}) {
122 $args->{'VERSION'} = $BUILD_DAILY_VERSION->($args->{'VERSION'});
123 }
124
125 return $EXTUTILS_MM_NEW->($class, $args);
126 }
127  
128 'SUPERMAN gesucht';
129  
130  
131  
132 __END__
↑ Summary