File Coverage

blib/lib/Enbld/Definition.pm
Criterion Covered Total %
statement 28 28 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod 2 3 66.6
total 39 40 97.5


line stmt bran cond sub pod time code
1             package Enbld::Definition;
2              
3 3     3   731 use strict;
  3         4  
  3         84  
4 3     3   11 use warnings;
  3         3  
  3         84  
5              
6 3     3   1523 use Module::Load;
  3         2860  
  3         16  
7 3     3   1740 use Module::Load::Conditional qw/can_load/;
  3         58979  
  3         696  
8              
9             require Enbld::Error;
10              
11             sub new {
12 48     48 1 387 my $class = shift;
13 48         67 my $name = shift;
14              
15 48         1308 my $self = {
16             defined => {
17             DefaultArgument => undef,
18             DarwinArgument => undef,
19              
20             AdditionalArgument => undef,
21              
22             AllowedCondition => undef,
23             ArchiveName => undef,
24             CopyFiles => undef,
25             Dependencies => undef,
26             DistName => undef,
27             DownloadSite => undef,
28             Extension => undef,
29             Filename => undef,
30             IndexParserForm => undef,
31             IndexSite => undef,
32             PatchFiles => undef,
33             Prefix => undef,
34             URL => undef,
35             SortedVersionList => undef,
36             Version => undef,
37             VersionList => undef,
38             # VersionCondition => undef,
39             VersionForm => undef,
40             WebSite => undef,
41            
42             TestAction => undef,
43              
44             CommandConfigure => undef,
45             CommandMake => undef,
46             CommandTest => undef,
47             CommandInstall => undef,
48             },
49             };
50              
51 48         207 my $module = 'Enbld::Definition::' . ucfirst( $name );
52              
53 48 100       257 if ( can_load( modules => { $module => undef } ) ) {
54 47         12106 bless $self, $module;
55              
56 47         235 $self->initialize;
57              
58 47         648 return $self;
59             }
60              
61 1         391 die( Enbld::Error->new( "no definition for target '$name'" ));
62             }
63              
64       47 0   sub initialize {
65              
66             # do nothing ... virtual method
67              
68             }
69              
70             sub parse {
71 46     46 1 80 my $self = shift;
72              
73 46         617 require Enbld::Target::AttributeCollector;
74 46         339 my $attributes = Enbld::Target::AttributeCollector->new;
75              
76 46         75 foreach my $attribute ( keys %{ $self->{defined} } ) {
  46         307  
77 1196         2529 $attributes->add( $attribute, $self->{defined}{ $attribute } );
78             }
79              
80 46         218 return $attributes;
81             }
82              
83             1;
84              
85             =pod
86              
87             =head1 NAME
88              
89             Enbld::Definition - stores target software' attributes.
90              
91             =head1 SYNOPSIS
92              
93             require Enbld::Definition;
94              
95             my $attributes = Enbld::Definition->new( 'git' )->parse;
96              
97             $attributes->add( 'VersionCondition', '1.8.5' );
98              
99             $attributes->ArchiveName; # git
100             $attributes->Vesion; # 1.8.5
101             $attributes->URL; # http://git-core.googlecode.com/files/git-1.8.5.tar.gz
102              
103             =head1 DESCRIPTION
104              
105             Enbld::Definition stores target software' attributes.
106              
107             =head1 METHODS
108              
109             =over 2
110              
111             =item new
112              
113             my $def = Enbld::Definition->new( 'git' );
114              
115             Returns a new definition object for target software.
116              
117             The return value is a Enbld::Definition::[target software] object.
118              
119             When the definition module of the target software specified as the argument does not exist, undef is returned.
120              
121             =item parse
122              
123             my $def = Enbld::Definition->new( 'git' );
124             my $attributes = $def->parse;
125             $attributes->ArchiveName; # -> git
126             $attributes->Extension; # -> tar.gz
127              
128             Returns a new attributes collector for target software.
129              
130             The return value is a Enbld::Target::AttributeCollector object.
131              
132             =back
133              
134             =head1 COPYRIGHT
135              
136             copyright 2013- Magnolia C<< >>.
137              
138             =head1 LICENSE
139              
140             This is free software; you can redistribute it and/or modify it under
141             the same terms as the Perl 5 programming language system itself.
142              
143             =cut