File Coverage

blib/lib/ExtUtils/ModuleMaker/Initializers.pm
Criterion Covered Total %
statement 55 55 100.0
branch 19 20 95.0
condition 7 9 77.7
subroutine 9 9 100.0
pod 5 5 100.0
total 95 98 96.9


line stmt bran cond sub pod time code
1             package ExtUtils::ModuleMaker::Initializers;
2 18     18   104 use strict;
  18         27  
  18         364  
3 18     18   62 use warnings;
  18         26  
  18         564  
4             our $VERSION = "0.63";
5 18         1216 use ExtUtils::ModuleMaker::Licenses::Standard qw(
6             Get_Standard_License
7             Verify_Standard_License
8 18     18   19311 );
  18         48  
9 18         12075 use ExtUtils::ModuleMaker::Licenses::Local qw(
10             Get_Local_License
11             Verify_Local_License
12 18     18   7346 );
  18         40  
13              
14             =head1 NAME
15              
16             ExtUtils::ModuleMaker::Initializers - Methods used within C and C
17              
18             =head1 DESCRIPTION
19              
20             The methods described below are 'quasi-private' methods which are called by
21             certain publicly available methods of ExtUtils::ModuleMaker and
22             ExtUtils::ModuleMaker::Interactive. They are 'quasi-private' in the sense
23             that they are not intended to be called by the everyday user of
24             ExtUtils::ModuleMaker. Nothing prevents a user from calling these
25             methods, but they are documented here primarily so that users
26             writing plug-ins for ExtUtils::ModuleMaker will know what methods
27             need to be subclassed. I
28             names and functionality may change in future versions of
29             ExtUtils::ModuleMaker.>
30              
31             The methods below are called in C but not in
32             that same package's C. For methods called in
33             C, please see ExtUtils::ModuleMaker::StandardText. Some of
34             the methods below are also called within methods in
35             ExtUtils::ModuleMaker::Interactive.
36              
37             Subclassers: At ExtUtils::ModuleMaker's current state of development, it is
38             recommended that you I subclass these methods but instead focus your
39             efforts on subclassing the methods in ExtUtils::ModuleMaker::StandardText.
40             The latter package's methods focus more closely on the structure and content
41             of the files built by ExtUtils::ModuleMaker.
42              
43             Happy subclassing!
44              
45             =head1 METHODS
46              
47             =head2 Methods Called within C
48              
49             =head3 C
50              
51             Usage : $self->set_author_composite() within new() and
52             Interactive::Main_Menu()
53             Purpose : Sets $self key COMPOSITE by composing it from $self keys AUTHOR,
54             CPANID, ORGANIZATION, EMAIL and WEBSITE
55             Returns : n/a
56             Argument : n/a
57             Comment :
58              
59             =cut
60              
61             sub set_author_composite {
62 99     99 1 152 my $self = shift;
63              
64 99         157 my ($cpan_message, $org, $web, $composite);
65 99 100       264 $cpan_message = "CPAN ID: $self->{CPANID}" if $self->{CPANID};
66 99 100       205 $org = $self->{ORGANIZATION} if $self->{ORGANIZATION};
67 99 100       209 $web = $self->{WEBSITE} if $self->{WEBSITE};
68             my @data = (
69             $self->{AUTHOR},
70             $cpan_message,
71             $org,
72             $self->{EMAIL},
73 99         248 $web,
74             );
75 99         186 $composite = " $data[0]";
76 99         269 for my $el (@data[1..$#data]) {
77 396 100       794 $composite .= "\n $el" if defined $el;
78             }
79 99         278 $self->{COMPOSITE} = $composite;
80             }
81              
82             =head3 C
83              
84             Usage : $self->set_file_composite() within new()
85             Purpose : Sets $self key COMPOSITE by composing it from $self key NAME
86             Returns : n/a
87             Argument : n/a
88             Comment :
89              
90             =cut
91              
92             sub set_file_composite {
93 90     90 1 141 my $self = shift;
94              
95 90         296 my @layers = split( /::/, $self->{NAME} );
96 90         158 my $file = pop(@layers);
97 90         158 $file .= '.pm';
98 90         203 my $dir = join( '/', 'lib', @layers );
99 90         299 $self->{FILE} = join( '/', $dir, $file );
100             }
101              
102             =head3 C
103              
104             Usage : $self->set_dates() within new()
105             Purpose : Sets 3 keys in $self: year, timestamp and COPYRIGHT_YEAR
106             Returns : n/a
107             Argument : n/a
108             Comment :
109              
110             =cut
111              
112             sub set_dates {
113 99     99 1 147 my $self = shift;
114 99         2228 $self->{year} = (localtime)[5] + 1900;
115 99         1495 $self->{timestamp} = scalar localtime;
116 99   66     642 $self->{COPYRIGHT_YEAR} ||= $self->{year};
117             }
118              
119             =head3 C
120              
121             Usage : $self->validate_values() within complete_build() and
122             Interactive::Main_Menu()
123             Purpose : Verify module values are valid and complete.
124             Returns : Error message if there is a problem
125             Argument : n/a
126             Throws : Will die with a death_message if errors and not interactive.
127             Comment : References many $self keys
128              
129             =cut
130              
131             sub validate_values {
132 99     99 1 156 my $self = shift;
133              
134             # Key: short-hand name for error condition
135             # Value: anonymous array holding:
136             # [0]: error message
137             # [1]: condition which will generate error message if evals true
138             my %error_msg = (
139             NAME_REQ => [
140             q{NAME is required},
141 99         268 eval { ! $self->{NAME}; },
142             ],
143             NAME_ILLEGAL => [
144             q{Module NAME contains illegal characters},
145 99 100       745 eval { $self->{NAME} and $self->{NAME} !~ m/^[\w:]+$/; },
146             ],
147             ABSTRACT => [
148             q{ABSTRACTs are limited to 44 characters},
149 99         310 eval { length( $self->{ABSTRACT} ) > 44; },
150             ],
151             CPANID => [
152             q{CPAN IDs are 3-9 characters},
153 99 100       585 eval { $self->{CPANID} and $self->{CPANID} !~ m/^\w{3,9}$/; },
154             ],
155             EMAIL => [
156             q{EMAIL addresses need to have an at sign},
157 99         387 eval { $self->{EMAIL} !~ m/.*\@.*/; },
158             ],
159             WEBSITE => [
160             q{WEBSITEs should start with an "http:" or "https:"},
161 99 100       660 eval { $self->{WEBSITE} and $self->{WEBSITE} !~ m{https?://.*}; },
162             ],
163             LICENSE => [
164             q{LICENSE is not recognized},
165 99         157 eval { ! (
166             Verify_Local_License($self->{LICENSE})
167             ||
168             Verify_Standard_License($self->{LICENSE})
169 99   100     356 ); },
170             ],
171             );
172              
173             # Errors should be checked in the following order
174 99         314 my @msgs_ordered = qw(
175             NAME_REQ
176             NAME_ILLEGAL
177             ABSTRACT
178             CPANID
179             EMAIL
180             WEBSITE
181             LICENSE
182             );
183              
184 99         140 my @errors;
185              
186 99         173 foreach my $attr ( @msgs_ordered ) {
187             push @errors, $error_msg{$attr}[0]
188 693 100       1141 if $error_msg{$attr}[1];
189             }
190            
191 99 100       447 return 1 unless @errors;
192 9         22 $self->death_message(\@errors);
193             }
194              
195             =head3 C
196              
197             Usage : $self->initialize_license() within new() and
198             Interactive::License_Menu
199             Purpose : Gets appropriate license and, where necessary, fills in 'blanks'
200             with information such as COPYRIGHT_YEAR, AUTHOR and
201             ORGANIZATION; sets $self keys LICENSE and LicenseParts
202             Returns : n/a
203             Argument : n/a
204             Comment :
205              
206             =cut
207              
208             sub initialize_license {
209 90     90 1 136 my $self = shift;
210              
211 90         190 $self->{LICENSE} = lc( $self->{LICENSE} );
212              
213             my $license_function = Get_Local_License( $self->{LICENSE} )
214 90   66     303 || Get_Standard_License( $self->{LICENSE} );
215              
216 90 50       242 if ( ref($license_function) eq 'CODE' ) {
217 90         214 $self->{LicenseParts} = $license_function->();
218              
219             $self->{LicenseParts}{LICENSETEXT} =~
220 90         3590 s/###year###/$self->{COPYRIGHT_YEAR}/ig;
221             $self->{LicenseParts}{LICENSETEXT} =~
222 90         3466 s/###owner###/$self->{AUTHOR}/ig;
223             $self->{LicenseParts}{LICENSETEXT} =~
224 90         3527 s/###organization###/$self->{ORGANIZATION}/ig;
225             }
226              
227             }
228              
229             =head1 SEE ALSO
230              
231             F.
232              
233             =cut
234              
235             1;
236              
237