blib/lib/CPANPLUS/Internals/Constants.pm untested

filter: Statementstmt 0.0% 0 / 428 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 40 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 110 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 635 SCAR 6.9
CC
1
Cov
0%
constants
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package CPANPLUS::Internals::Constants;
2  
3 use strict;
4  
5 use CPANPLUS::Error;
6  
7 use Config;
8 use File::Spec;
9 use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';
10  
11 require Exporter;
12 use vars qw[$VERSION @ISA @EXPORT];
13  
14 use Package::Constants;
15  
16 $VERSION = "0.9912";
17 @ISA = qw[Exporter];
18 @EXPORT = Package::Constants->list( __PACKAGE__ );
19  
20 sub constants { @EXPORT };
21  
22 use constant INSTALLER_BUILD
23 => 'CPANPLUS::Dist::Build';
24 use constant INSTALLER_MM => 'CPANPLUS::Dist::MM';
25 use constant INSTALLER_SAMPLE
26 => 'CPANPLUS::Dist::Sample';
27 use constant INSTALLER_BASE => 'CPANPLUS::Dist::Base';
28 use constant INSTALLER_AUTOBUNDLE
29 => 'CPANPLUS::Dist::Autobundle';
30  
31 use constant SHELL_DEFAULT => 'CPANPLUS::Shell::Default';
32 use constant SHELL_CLASSIC => 'CPANPLUS::Shell::Classic';
33  
34 use constant CONFIG => 'CPANPLUS::Config';
35 use constant CONFIG_USER => 'CPANPLUS::Config::User';
36 use constant CONFIG_SYSTEM => 'CPANPLUS::Config::System';
37 use constant CONFIG_BOXED => 'CPANPLUS::Config::Boxed';
38  
39 use constant DEFAULT_SOURCE_ENGINE
40 => 'CPANPLUS::Internals::Source::Memory';
41  
42 use constant TARGET_INIT => 'init';
43 use constant TARGET_CREATE => 'create';
44 use constant TARGET_PREPARE => 'prepare';
45 use constant TARGET_INSTALL => 'install';
46 use constant TARGET_IGNORE => 'ignore';
47  
48 use constant ON_WIN32 => $^O eq 'MSWin32';
49 use constant ON_NETWARE => $^O eq 'NetWare';
50 use constant ON_CYGWIN => $^O eq 'cygwin';
51 use constant ON_VMS => $^O eq 'VMS';
52 use constant ON_MINIX => $^O eq 'minix';
53  
54 use constant DOT_CPANPLUS => ON_VMS ? '_cpanplus' : '.cpanplus';
55  
56 use constant OPT_AUTOFLUSH => '-MCPANPLUS::Internals::Utils::Autoflush';
57  
58 use constant UNKNOWN_DL_LOCATION
59 => 'UNKNOWN-ORIGIN';
60  
61 use constant NMAKE => 'nmake.exe';
62 use constant NMAKE_URL =>
63 'ftp://ftp.microsoft.com/Softlib/MSLFILES/nmake15.exe';
64  
65 use constant INSTALL_VIA_PACKAGE_MANAGER
66 => sub { my $fmt = $_[0] or return;
67 return 1 if $fmt ne INSTALLER_BUILD and
68 $fmt ne INSTALLER_MM;
69 };
70  
71 use constant IS_CODEREF => sub { ref $_[-1] eq 'CODE' };
72 use constant IS_MODOBJ => sub { UNIVERSAL::isa($_[-1],
73 'CPANPLUS::Module') };
74 use constant IS_FAKE_MODOBJ => sub { UNIVERSAL::isa($_[-1],
75 'CPANPLUS::Module::Fake') };
76 use constant IS_AUTHOBJ => sub { UNIVERSAL::isa($_[-1],
77 'CPANPLUS::Module::Author') };
78 use constant IS_FAKE_AUTHOBJ
79 => sub { UNIVERSAL::isa($_[-1],
80 'CPANPLUS::Module::Author::Fake') };
81  
82 use constant IS_CONFOBJ => sub { UNIVERSAL::isa($_[-1],
83 'CPANPLUS::Configure') };
84  
85 use constant IS_RVOBJ => sub { UNIVERSAL::isa($_[-1],
86 'CPANPLUS::Backend::RV') };
87  
88 use constant IS_INTERNALS_OBJ
89 => sub { UNIVERSAL::isa($_[-1],
90 'CPANPLUS::Internals') };
91  
92 use constant IS_FILE => sub { return 1 if -e $_[-1] };
93  
94 use constant FILE_EXISTS => sub {
95 my $file = $_[-1];
96 return 1 if IS_FILE->($file);
97 local $Carp::CarpLevel =
98 $Carp::CarpLevel+2;
99 error(loc( q[File '%1' does not exist],
100 $file));
101 return;
102 };
103  
104 use constant FILE_READABLE => sub {
105 my $file = $_[-1];
106 return 1 if -e $file && -r _;
107 local $Carp::CarpLevel =
108 $Carp::CarpLevel+2;
109 error( loc( q[File '%1' is not readable ].
110 q[or does not exist], $file));
111 return;
112 };
113 use constant IS_DIR => sub { return 1 if -d $_[-1] };
114  
115 use constant DIR_EXISTS => sub {
116 my $dir = $_[-1];
117 return 1 if IS_DIR->($dir);
118 local $Carp::CarpLevel =
119 $Carp::CarpLevel+2;
120 error(loc(q[Dir '%1' does not exist],
121 $dir));
122 return;
123 };
124  
125 ### On VMS, if the $Config{make} is either MMK
126 ### or MMS, then the makefile is 'DESCRIP.MMS'.
127 use constant MAKEFILE => sub { my $file =
128 (ON_VMS and
129 $Config::Config{make} =~ /MM[S|K]/i)
130 ? 'DESCRIP.MMS'
131 : 'Makefile';
132  
133 return @_
134 ? File::Spec->catfile( @_, $file )
135 : $file;
136 };
137 use constant MAKEFILE_PL => sub { return @_
138 ? File::Spec->catfile( @_,
139 'Makefile.PL' )
140 : 'Makefile.PL';
141 };
142 use constant BUILD_PL => sub { return @_
143 ? File::Spec->catfile( @_,
144 'Build.PL' )
145 : 'Build.PL';
146 };
147  
148 use constant META_YML => sub { return @_
149 ? File::Spec->catfile( @_, 'META.yml' )
150 : 'META.yml';
151 };
152  
153 use constant MYMETA_YML => sub { return @_
154 ? File::Spec->catfile( @_, 'MYMETA.yml' )
155 : 'MYMETA.yml';
156 };
157  
158 use constant META_JSON => sub { return @_
159 ? File::Spec->catfile( @_, 'META.json' )
160 : 'META.json';
161 };
162  
163 use constant MYMETA_JSON => sub { return @_
164 ? File::Spec->catfile( @_, 'MYMETA.json' )
165 : 'MYMETA.json';
166 };
167  
168 use constant BLIB => sub { return @_
169 ? File::Spec->catfile(@_, 'blib')
170 : 'blib';
171 };
172  
173 use constant LIB => 'lib';
174 use constant LIB_DIR => sub { return @_
175 ? File::Spec->catdir(@_, LIB)
176 : LIB;
177 };
178 use constant AUTO => 'auto';
179 use constant LIB_AUTO_DIR => sub { return @_
180 ? File::Spec->catdir(@_, LIB, AUTO)
181 : File::Spec->catdir(LIB, AUTO)
182 };
183 use constant ARCH => 'arch';
184 use constant ARCH_DIR => sub { return @_
185 ? File::Spec->catdir(@_, ARCH)
186 : ARCH;
187 };
188 use constant ARCH_AUTO_DIR => sub { return @_
189 ? File::Spec->catdir(@_,ARCH,AUTO)
190 : File::Spec->catdir(ARCH,AUTO)
191 };
192  
193 use constant BLIB_LIBDIR => sub { return @_
194 ? File::Spec->catdir(
195 @_, BLIB->(), LIB )
196 : File::Spec->catdir( BLIB->(), LIB );
197 };
198  
199 use constant BIN => 'bin';
200  
201 use constant SCRIPT => 'script';
202  
203 use constant CONFIG_USER_LIB_DIR => sub {
204 require CPANPLUS::Internals::Utils;
205 LIB_DIR->(
206 CPANPLUS::Internals::Utils->_home_dir,
207 DOT_CPANPLUS
208 );
209 };
210 use constant CONFIG_USER_FILE => sub {
211 File::Spec->catfile(
212 CONFIG_USER_LIB_DIR->(),
213 split('::', CONFIG_USER),
214 ) . '.pm';
215 };
216 use constant CONFIG_SYSTEM_FILE => sub {
217 require CPANPLUS::Internals;
218 require File::Basename;
219 my $dir = File::Basename::dirname(
220 $INC{'CPANPLUS/Internals.pm'}
221 );
222  
223 ### XXX use constants
224 File::Spec->catfile(
225 $dir, qw[Config System.pm]
226 );
227 };
228  
229 use constant README => sub { my $obj = $_[0];
230 my $pkg = $obj->package_name;
231 $pkg .= '-' . $obj->package_version .
232 '.readme';
233 return $pkg;
234 };
235 use constant META_EXT => 'meta';
236  
237 use constant META => sub { my $obj = $_[0];
238 my $pkg = $obj->package_name;
239 $pkg .= '-' . $obj->package_version .
240 '.' . META_EXT;
241 return $pkg;
242 };
243  
244 use constant OPEN_FILE => sub {
245 my($file, $mode) = (@_, '');
246 my $fh;
247 open $fh, "$mode" . $file
248 or error(loc(
249 "Could not open file '%1': %2",
250 $file, $!));
251 return $fh if $fh;
252 return;
253 };
254  
255 use constant OPEN_DIR => sub {
256 my $dir = shift;
257 my $dh;
258 opendir $dh, $dir or error(loc(
259 "Could not open dir '%1': %2", $dir, $!
260 ));
261  
262 return $dh if $dh;
263 return;
264 };
265  
266 use constant READ_DIR => sub {
267 my $dir = shift;
268 my $dh = OPEN_DIR->( $dir ) or return;
269  
270 ### exclude . and ..
271 my @files = grep { $_ !~ /^\.{1,2}/ }
272 readdir($dh);
273  
274 ### Remove trailing dot on VMS when
275 ### using VMS syntax.
276 if( ON_VMS ) {
277 s/(?<!\^)\.$// for @files;
278 }
279  
280 return @files;
281 };
282  
283 use constant STRIP_GZ_SUFFIX
284 => sub {
285 my $file = $_[0] or return;
286 $file =~ s/.gz$//i;
287 return $file;
288 };
289  
290 use constant CHECKSUMS => 'CHECKSUMS';
291 use constant PGP_HEADER => '-----BEGIN PGP SIGNED MESSAGE-----';
292 use constant ENV_CPANPLUS_CONFIG
293 => 'PERL5_CPANPLUS_CONFIG';
294 use constant ENV_CPANPLUS_IS_EXECUTING
295 => 'PERL5_CPANPLUS_IS_EXECUTING';
296 use constant DEFAULT_EMAIL => 'cpanplus@example.com';
297 use constant CPANPLUS_UA => sub { ### for the version number ###
298 require CPANPLUS::Internals;
299 "CPANPLUS/$CPANPLUS::Internals::VERSION"
300 };
301 use constant TESTERS_URL => sub {
302 'http://cpantesters.org/distro/'.
303 uc(substr($_[0],0,1)) .'/'. $_[0] . '.yaml';
304 };
305 use constant TESTERS_DETAILS_URL
306 => sub {
307 'http://cpantesters.org/distro/'.
308 uc(substr($_[0],0,1)) .'/'. $_[0];
309 };
310  
311 use constant CREATE_FILE_URI
312 => sub {
313 my $dir = $_[0] or return;
314 return $dir =~ m|^/|
315 ? 'file://' . $dir
316 : 'file:///' . $dir;
317 };
318  
319 use constant EMPTY_DSLIP => ' ';
320  
321 use constant CUSTOM_AUTHOR_ID
322 => 'LOCAL';
323  
324 use constant DOT_SHELL_DEFAULT_RC
325 => '.shell-default.rc';
326  
327 use constant SOURCE_SQLITE_DB
328 => 'db.sql';
329  
330 use constant PREREQ_IGNORE => 0;
331 use constant PREREQ_INSTALL => 1;
332 use constant PREREQ_ASK => 2;
333 use constant PREREQ_BUILD => 3;
334 use constant BOOLEANS => [0,1];
335 use constant CALLING_FUNCTION
336 => sub { my $lvl = $_[0] || 0;
337 return join '::', (caller(2+$lvl))[3]
338 };
339 use constant PERL_CORE => 'perl';
340 use constant PERL_WRAPPER => 'use strict; BEGIN { my $old = select STDERR; $|++; select $old; $|++; $0 = shift(@ARGV); my $rv = do($0); die $@ if $@; }';
341 use constant STORABLE_EXT => '.stored';
342  
343 use constant GET_XS_FILES => sub { my $dir = $_[0] or return;
344 require File::Find;
345 my @files;
346 File::Find::find(
347 sub { push @files, $File::Find::name
348 if $File::Find::name =~ /\.xs$/i
349 }, $dir );
350  
351 return @files;
352 };
353  
354 use constant INSTALL_LOG_FILE
355 => sub { my $obj = shift or return;
356 my $name = $obj->name; $name =~ s/::/-/g;
357 $name .= '-'. $obj->version;
358 $name .= '-'. scalar(time) . '.log';
359 return $name;
360 };
361  
362 use constant ON_OLD_CYGWIN => do { ON_CYGWIN and $] < 5.008
363 ? loc(
364 "Your perl version for %1 is too low; ".
365 "Require %2 or higher for this function",
366 $^O, '5.8.0' )
367 : '';
368 };
369  
370 ### XXX these 2 are probably obsolete -- check & remove;
371 use constant DOT_EXISTS => '.exists';
372  
373 use constant QUOTE_PERL_ONE_LINER
374 => sub { my $line = shift or return;
375  
376 ### use double quotes on these systems
377 return qq["$line"]
378 if ON_WIN32 || ON_NETWARE || ON_VMS;
379  
380 ### single quotes on the rest
381 return qq['$line'];
382 };
383  
384 1;
385  
386 # Local variables:
387 # c-indentation-style: bsd
388 # c-basic-offset: 4
389 # indent-tabs-mode: nil
390 # End:
391 # vim: expandtab shiftwidth=4: