Enbld/Definition/Perl.pm untested

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 95 SCAR 40.3
CC
7
Cov
0%
evaluate_version
20.0
parse_version_list
6.0
set_argument
6.0
CRAP 56.0
1 package Enbld::Definition::Perl;
2  
3 use strict;
4 use warnings;
5  
6 use version;
7  
8 use parent qw/Enbld::Definition/;
9  
10 require Enbld::Feature;
11  
12 sub initialize {
13 my $self = shift;
14  
15 $self->SUPER::initialize;
16  
17 $self->{defined}{ArchiveName} = 'perl';
18 $self->{defined}{WebSite} = 'http://www.perl.org';
19 $self->{defined}{VersionForm} = '5\.\d{1,2}\.\d{1,2}';
20 $self->{defined}{DistName} = 'TMTOWTDI';
21 $self->{defined}{AllowedCondition} = 'development';
22 $self->{defined}{DownloadSite} = 'http://www.cpan.org/src/5.0/';
23 $self->{defined}{Version} = \&evaluate_version;
24 $self->{defined}{Prefix} = '-Dprefix=';
25 $self->{defined}{AdditionalArgument} = \&set_argument;
26  
27 $self->{defined}{TestAction} = 'test';
28  
29 $self->{defined}{CommandConfigure} = 'sh Configure -de';
30  
31 return $self;
32 }
33  
34 sub evaluate_version {
35 my $attributes = shift;
36  
37 my $list = $attributes->VersionList;
38 my ( $stable, $development ) = parse_version_list( $list );
39  
40 my $condition = $attributes->VersionCondition;
41 return $stable if ( $condition eq 'latest' );
42 return $development if ( $condition eq 'development' );
43 return $condition if ( grep { $condition eq $_ } @{ $list} );
44  
45 require Enbld::Error;
46 die( Enbld::Error->new(
47 "Invalid Version Condition:$condition, ".
48 "please check install condition"
49 ));
50 }
51  
52 sub parse_version_list {
53 my $list = shift;
54  
55 my @stable;
56 my @development;
57  
58 foreach my $version ( @{ $list } ) {
59 my @frag = split( /\./, $version );
60  
61 if ( $frag[1] % 2 == 0 ) {
62 push @stable, $version;
63 } else {
64 push @development, $version;
65 }
66 }
67  
68 my @stable_sorted = sort {
69 version->declare( $a ) cmp version->declare( $b )
70 } @stable;
71  
72 my @development_sorted = sort {
73 version->declare( $a ) cmp version->declare( $b )
74 } @development;
75  
76 return ( $stable_sorted[-1], $development_sorted[-1] );
77 }
78  
79 sub set_argument {
80 my $attributes = shift;
81  
82 my $argument = " ";
83  
84 unless ( _is_stable( $attributes ) ) {
85 $argument .= '-Dusedevel';
86 }
87  
88 return $argument;
89 }
90  
91 sub _is_stable {
92 my $attributes = shift;
93  
94 my $version = $attributes->Version;
95  
96 my @frag = split( /\./, $version );
97  
98 if ( $frag[1] % 2 == 0 ) {
99 return $version;
100 }
101  
102 return;
103 }
104  
105 1;
106  
107 =pod
108  
109 =head1 NAME
110  
111 Enbld::Definition::Perl - definition module for The Perl Programming Language
112  
113 =head1 INSTALL DEVELOPMENT VERSION
114  
115 Definition module for Perl supports installation for development version of perl.Set attribute 'VersionCondition' to 'development', install latest development version of perl(e.g. 5.19.1).
116  
117 target 'perl' => {
118 version 'development';
119 # -> $attributes->add( 'VersionCondition', 'development' );
120 };
121  
122 # -> install odd numbers version(e.g. 5.19.1)
123  
124  
125 =head1 INSTALL MODULES
126  
127 Definition module for Perl supports installation for CPAN modules.
128  
129 target 'perl' => {
130 version 'latest';
131 modules => {
132 'Carton' => 0, # -> install Carton
133 };
134 };
135  
136 =head1 SEE ALSO
137  
138 L<The Perl Programming Language|http://www.perl.org>
139  
140 L<Enbld::Definition>
141  
142 =head1 COPYRIGHT
143  
144 copyright 2013- Magnolia C<< <magnolia.k@me.com> >>.
145  
146 =head1 LICENSE
147  
148 This is free software; you can redistribute it and/or modify it under
149 the same terms as the Perl 5 programming language system itself.
150  
151 =cut