1package CPANPLUS::Internals::Constants; 2 3use strict; 4 5use CPANPLUS::Error; 6 7use Config; 8use File::Spec; 9use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext'; 10 11require Exporter; 12use vars qw[$VERSION @ISA @EXPORT]; 13 14use Package::Constants; 15 16$VERSION = "0.9912"; 17@ISA = qw[Exporter]; 18@EXPORT = Package::Constants->list( __PACKAGE__ ); 19 20sub constants { @EXPORT }; 21 22use constant INSTALLER_BUILD 23 => 'CPANPLUS::Dist::Build'; 24use constant INSTALLER_MM => 'CPANPLUS::Dist::MM'; 25use constant INSTALLER_SAMPLE 26 => 'CPANPLUS::Dist::Sample'; 27use constant INSTALLER_BASE => 'CPANPLUS::Dist::Base'; 28use constant INSTALLER_AUTOBUNDLE 29 => 'CPANPLUS::Dist::Autobundle'; 30 31use constant SHELL_DEFAULT => 'CPANPLUS::Shell::Default'; 32use constant SHELL_CLASSIC => 'CPANPLUS::Shell::Classic'; 33 34use constant CONFIG => 'CPANPLUS::Config'; 35use constant CONFIG_USER => 'CPANPLUS::Config::User'; 36use constant CONFIG_SYSTEM => 'CPANPLUS::Config::System'; 37use constant CONFIG_BOXED => 'CPANPLUS::Config::Boxed'; 38 39use constant DEFAULT_SOURCE_ENGINE 40 => 'CPANPLUS::Internals::Source::Memory'; 41 42use constant TARGET_INIT => 'init'; 43use constant TARGET_CREATE => 'create'; 44use constant TARGET_PREPARE => 'prepare'; 45use constant TARGET_INSTALL => 'install'; 46use constant TARGET_IGNORE => 'ignore'; 47 48use constant ON_WIN32 => $^O eq 'MSWin32'; 49use constant ON_NETWARE => $^O eq 'NetWare'; 50use constant ON_CYGWIN => $^O eq 'cygwin'; 51use constant ON_VMS => $^O eq 'VMS'; 52use constant ON_MINIX => $^O eq 'minix'; 53 54use constant DOT_CPANPLUS => ON_VMS ? '_cpanplus' : '.cpanplus'; 55 56use constant OPT_AUTOFLUSH => '-MCPANPLUS::Internals::Utils::Autoflush'; 57 58use constant UNKNOWN_DL_LOCATION 59 => 'UNKNOWN-ORIGIN'; 60 61use constant NMAKE => 'nmake.exe'; 62use constant NMAKE_URL => 63 'ftp://ftp.microsoft.com/Softlib/MSLFILES/nmake15.exe'; 64 65use 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 71use constant IS_CODEREF => sub { ref $_[-1] eq 'CODE' }; 72use constant IS_MODOBJ => sub { UNIVERSAL::isa($_[-1], 73 'CPANPLUS::Module') }; 74use constant IS_FAKE_MODOBJ => sub { UNIVERSAL::isa($_[-1], 75 'CPANPLUS::Module::Fake') }; 76use constant IS_AUTHOBJ => sub { UNIVERSAL::isa($_[-1], 77 'CPANPLUS::Module::Author') }; 78use constant IS_FAKE_AUTHOBJ 79 => sub { UNIVERSAL::isa($_[-1], 80 'CPANPLUS::Module::Author::Fake') }; 81 82use constant IS_CONFOBJ => sub { UNIVERSAL::isa($_[-1], 83 'CPANPLUS::Configure') }; 84 85use constant IS_RVOBJ => sub { UNIVERSAL::isa($_[-1], 86 'CPANPLUS::Backend::RV') }; 87 88use constant IS_INTERNALS_OBJ 89 => sub { UNIVERSAL::isa($_[-1], 90 'CPANPLUS::Internals') }; 91 92use constant IS_FILE => sub { return 1 if -e $_[-1] }; 93 94use 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 104use 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 }; 113use constant IS_DIR => sub { return 1 if -d $_[-1] }; 114 115use 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'. 127use 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 }; 137use constant MAKEFILE_PL => sub { return @_ 138 ? File::Spec->catfile( @_, 139 'Makefile.PL' ) 140 : 'Makefile.PL'; 141 }; 142use constant BUILD_PL => sub { return @_ 143 ? File::Spec->catfile( @_, 144 'Build.PL' ) 145 : 'Build.PL'; 146 }; 147 148use constant META_YML => sub { return @_ 149 ? File::Spec->catfile( @_, 'META.yml' ) 150 : 'META.yml'; 151 }; 152 153use constant MYMETA_YML => sub { return @_ 154 ? File::Spec->catfile( @_, 'MYMETA.yml' ) 155 : 'MYMETA.yml'; 156 }; 157 158use constant META_JSON => sub { return @_ 159 ? File::Spec->catfile( @_, 'META.json' ) 160 : 'META.json'; 161 }; 162 163use constant MYMETA_JSON => sub { return @_ 164 ? File::Spec->catfile( @_, 'MYMETA.json' ) 165 : 'MYMETA.json'; 166 }; 167 168use constant BLIB => sub { return @_ 169 ? File::Spec->catfile(@_, 'blib') 170 : 'blib'; 171 }; 172 173use constant LIB => 'lib'; 174use constant LIB_DIR => sub { return @_ 175 ? File::Spec->catdir(@_, LIB) 176 : LIB; 177 }; 178use constant AUTO => 'auto'; 179use constant LIB_AUTO_DIR => sub { return @_ 180 ? File::Spec->catdir(@_, LIB, AUTO) 181 : File::Spec->catdir(LIB, AUTO) 182 }; 183use constant ARCH => 'arch'; 184use constant ARCH_DIR => sub { return @_ 185 ? File::Spec->catdir(@_, ARCH) 186 : ARCH; 187 }; 188use constant ARCH_AUTO_DIR => sub { return @_ 189 ? File::Spec->catdir(@_,ARCH,AUTO) 190 : File::Spec->catdir(ARCH,AUTO) 191 }; 192 193use constant BLIB_LIBDIR => sub { return @_ 194 ? File::Spec->catdir( 195 @_, BLIB->(), LIB ) 196 : File::Spec->catdir( BLIB->(), LIB ); 197 }; 198 199use constant BIN => 'bin'; 200 201use constant SCRIPT => 'script'; 202 203use 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 }; 210use constant CONFIG_USER_FILE => sub { 211 File::Spec->catfile( 212 CONFIG_USER_LIB_DIR->(), 213 split('::', CONFIG_USER), 214 ) . '.pm'; 215 }; 216use 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 229use constant README => sub { my $obj = $_[0]; 230 my $pkg = $obj->package_name; 231 $pkg .= '-' . $obj->package_version . 232 '.readme'; 233 return $pkg; 234 }; 235use constant META_EXT => 'meta'; 236 237use 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 244use 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 255use 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 266use 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 283use constant STRIP_GZ_SUFFIX 284 => sub { 285 my $file = $_[0] or return; 286 $file =~ s/.gz$//i; 287 return $file; 288 }; 289 290use constant CHECKSUMS => 'CHECKSUMS'; 291use constant PGP_HEADER => '-----BEGIN PGP SIGNED MESSAGE-----'; 292use constant ENV_CPANPLUS_CONFIG 293 => 'PERL5_CPANPLUS_CONFIG'; 294use constant ENV_CPANPLUS_IS_EXECUTING 295 => 'PERL5_CPANPLUS_IS_EXECUTING'; 296use constant DEFAULT_EMAIL => 'cpanplus@example.com'; 297use constant CPANPLUS_UA => sub { ### for the version number ### 298 require CPANPLUS::Internals; 299 "CPANPLUS/$CPANPLUS::Internals::VERSION" 300 }; 301use constant TESTERS_URL => sub { 302 'http://cpantesters.org/distro/'. 303 uc(substr($_[0],0,1)) .'/'. $_[0] . '.yaml'; 304 }; 305use constant TESTERS_DETAILS_URL 306 => sub { 307 'http://cpantesters.org/distro/'. 308 uc(substr($_[0],0,1)) .'/'. $_[0]; 309 }; 310 311use constant CREATE_FILE_URI 312 => sub { 313 my $dir = $_[0] or return; 314 return $dir =~ m|^/| 315 ? 'file://' . $dir 316 : 'file:///' . $dir; 317 }; 318 319use constant EMPTY_DSLIP => ' '; 320 321use constant CUSTOM_AUTHOR_ID 322 => 'LOCAL'; 323 324use constant DOT_SHELL_DEFAULT_RC 325 => '.shell-default.rc'; 326 327use constant SOURCE_SQLITE_DB 328 => 'db.sql'; 329 330use constant PREREQ_IGNORE => 0; 331use constant PREREQ_INSTALL => 1; 332use constant PREREQ_ASK => 2; 333use constant PREREQ_BUILD => 3; 334use constant BOOLEANS => [0,1]; 335use constant CALLING_FUNCTION 336 => sub { my $lvl = $_[0] || 0; 337 return join '::', (caller(2+$lvl))[3] 338 }; 339use constant PERL_CORE => 'perl'; 340use constant PERL_WRAPPER => 'use strict; BEGIN { my $old = select STDERR; $|++; select $old; $|++; $0 = shift(@ARGV); my $rv = do($0); die $@ if $@; }'; 341use constant STORABLE_EXT => '.stored'; 342 343use 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 354use 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 362use 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; 371use constant DOT_EXISTS => '.exists'; 372 373use 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 3841; 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: 392