| 1 | package CPANPLUS::Config; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use base 'Object::Accessor'; | ||
| 7 | use base 'CPANPLUS::Internals::Utils'; | ||
| 8 | |||
| 9 | use Config; | ||
| 10 | use File::Spec; | ||
| 11 | use Module::Load; | ||
| 12 | use CPANPLUS; | ||
| 13 | use CPANPLUS::Error; | ||
| 14 | use CPANPLUS::Internals::Constants; | ||
| 15 | |||
| 16 | use File::Basename qw[dirname]; | ||
| 17 | use IPC::Cmd qw[can_run]; | ||
| 18 | use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext'; | ||
| 19 | use Module::Load::Conditional qw[check_install]; | ||
| 20 | use version; | ||
| 21 | |||
| 22 | use vars qw[$VERSION]; | ||
| 23 | $VERSION = "0.9914"; | ||
| 24 | |||
| 25 | =pod | ||
| 26 | |||
| 27 | =head1 NAME | ||
| 28 | |||
| 29 | CPANPLUS::Config - configuration defaults and heuristics for CPANPLUS | ||
| 30 | |||
| 31 | =head1 SYNOPSIS | ||
| 32 | |||
| 33 | ### conf object via CPANPLUS::Backend; | ||
| 34 | $cb = CPANPLUS::Backend->new; | ||
| 35 | $conf = $cb->configure_object; | ||
| 36 | |||
| 37 | ### or as a standalone object | ||
| 38 | $conf = CPANPLUS::Configure->new; | ||
| 39 | |||
| 40 | ### values in 'conf' section | ||
| 41 | $verbose = $conf->get_conf( 'verbose' ); | ||
| 42 | $conf->set_conf( verbose => 1 ); | ||
| 43 | |||
| 44 | ### values in 'program' section | ||
| 45 | $editor = $conf->get_program( 'editor' ); | ||
| 46 | $conf->set_program( editor => '/bin/vi' ); | ||
| 47 | |||
| 48 | =head1 DESCRIPTION | ||
| 49 | |||
| 50 | This module contains defaults and heuristics for configuration | ||
| 51 | information for CPANPLUS. To change any of these values, please | ||
| 52 | see the documentation in C<CPANPLUS::Configure>. | ||
| 53 | |||
| 54 | Below you'll find a list of configuration types and keys, and | ||
| 55 | their meaning. | ||
| 56 | |||
| 57 | =head1 CONFIGURATION | ||
| 58 | |||
| 59 | =cut | ||
| 60 | |||
| 61 | ### BAH! you can't have POD interleaved with a hash | ||
| 62 | ### declaration.. so declare every entry separately :( | ||
| 63 | my $Conf = { | ||
| 64 | '_fetch' => { | ||
| 65 | 'blacklist' => [ 'ftp' ], | ||
| 66 | }, | ||
| 67 | |||
| 68 | ### _source, _build and _mirror are supposed to be static | ||
| 69 | ### no changes should be needed unless pause/cpan changes | ||
| 70 | '_source' => { | ||
| 71 | 'hosts' => 'MIRRORED.BY', | ||
| 72 | 'auth' => '01mailrc.txt.gz', | ||
| 73 | 'stored' => 'sourcefiles', | ||
| 74 | 'dslip' => '03modlist.data.gz', | ||
| 75 | 'update' => '86400', | ||
| 76 | 'mod' => '02packages.details.txt.gz', | ||
| 77 | 'custom_index' => 'packages.txt', | ||
| 78 | }, | ||
| 79 | '_build' => { | ||
| 80 | 'plugins' => 'plugins', | ||
| 81 | 'moddir' => 'build', | ||
| 82 | 'startdir' => '', | ||
| 83 | 'distdir' => 'dist', | ||
| 84 | 'autobundle' => 'autobundle', | ||
| 85 | 'autobundle_prefix' => 'Snapshot', | ||
| 86 | 'autdir' => 'authors', | ||
| 87 | 'install_log_dir' => 'install-logs', | ||
| 88 | 'custom_sources' => 'custom-sources', | ||
| 89 | 'sanity_check' => 1, | ||
| 90 | }, | ||
| 91 | '_mirror' => { | ||
| 92 | 'base' => 'authors/id/', | ||
| 93 | 'auth' => 'authors/01mailrc.txt.gz', | ||
| 94 | 'dslip' => 'modules/03modlist.data.gz', | ||
| 95 | 'mod' => 'modules/02packages.details.txt.gz' | ||
| 96 | }, | ||
| 97 | }; | ||
| 98 | |||
| 99 | =head2 Section 'conf' | ||
| 100 | |||
| 101 | =over 4 | ||
| 102 | |||
| 103 | =item hosts | ||
| 104 | |||
| 105 | An array ref containing hosts entries to be queried for packages. | ||
| 106 | |||
| 107 | An example entry would like this: | ||
| 108 | |||
| 109 | { 'scheme' => 'ftp', | ||
| 110 | 'path' => '/pub/CPAN/', | ||
| 111 | 'host' => 'ftp.cpan.org' | ||
| 112 | }, | ||
| 113 | |||
| 114 | =cut | ||
| 115 | |||
| 116 | ### default host list | ||
| 117 | $Conf->{'conf'}->{'hosts'} = [ | ||
| 118 | { | ||
| 119 | 'scheme' => 'http', | ||
| 120 | 'path' => '/', | ||
| 121 | 'host' => 'www.cpan.org' | ||
| 122 | }, | ||
| 123 | ]; | ||
| 124 | |||
| 125 | =item allow_build_interactivity | ||
| 126 | |||
| 127 | Boolean flag to indicate whether 'perl Makefile.PL' and similar | ||
| 128 | are run interactively or not. Defaults to 'true'. | ||
| 129 | |||
| 130 | =cut | ||
| 131 | |||
| 132 | $Conf->{'conf'}->{'allow_build_interactivity'} = 1; | ||
| 133 | |||
| 134 | =item allow_unknown_prereqs | ||
| 135 | |||
| 136 | Boolean flag to indicate that unresolvable prereqs are acceptable. | ||
| 137 | If C<true> then only warnings will be issued (the behaviour before 0.9114) | ||
| 138 | when a module is unresolvable from any our sources (CPAN and/or | ||
| 139 | C<custom_sources>). If C<false> then an unresolvable prereq will fail | ||
| 140 | during the C<prepare> stage of distribution installation. | ||
| 141 | Defaults to C<true>. | ||
| 142 | |||
| 143 | =cut | ||
| 144 | |||
| 145 | $Conf->{'conf'}->{'allow_unknown_prereqs'} = 1; | ||
| 146 | |||
| 147 | =item base | ||
| 148 | |||
| 149 | The directory CPANPLUS keeps all its build and state information in. | ||
| 150 | Defaults to ~/.cpanplus. If L<File::HomeDir> is available, that will | ||
| 151 | be used to work out your C<HOME> directory. This may be overridden by | ||
| 152 | setting the C<PERL5_CPANPLUS_HOME> environment variable, see | ||
| 153 | L<CPANPLUS::Config::HomeEnv> for more details. | ||
| 154 | |||
| 155 | =cut | ||
| 156 | |||
| 157 | $Conf->{'conf'}->{'base'} = File::Spec->catdir( | ||
| 158 | __PACKAGE__->_home_dir, DOT_CPANPLUS ); | ||
| 159 | |||
| 160 | =item buildflags | ||
| 161 | |||
| 162 | Any flags to be passed to 'perl Build.PL'. See C<perldoc Module::Build> | ||
| 163 | for details. Defaults to an empty string. | ||
| 164 | |||
| 165 | =cut | ||
| 166 | |||
| 167 | $Conf->{'conf'}->{'buildflags'} = ''; | ||
| 168 | |||
| 169 | =item cpantest | ||
| 170 | |||
| 171 | Boolean flag to indicate whether or not to mail test results of module | ||
| 172 | installations to C<http://testers.cpan.org>. Defaults to 'false'. | ||
| 173 | |||
| 174 | =cut | ||
| 175 | |||
| 176 | $Conf->{'conf'}->{'cpantest'} = 0; | ||
| 177 | |||
| 178 | =item cpantest_mx | ||
| 179 | |||
| 180 | String holding an explicit mailserver to use when sending out emails | ||
| 181 | for C<http://testers.cpan.org>. An empty string will use your system | ||
| 182 | settings. Defaults to an empty string. | ||
| 183 | |||
| 184 | =cut | ||
| 185 | |||
| 186 | $Conf->{'conf'}->{'cpantest_mx'} = ''; | ||
| 187 | |||
| 188 | =item debug | ||
| 189 | |||
| 190 | Boolean flag to enable or disable extensive debugging information. | ||
| 191 | Defaults to 'false'. | ||
| 192 | |||
| 193 | =cut | ||
| 194 | |||
| 195 | $Conf->{'conf'}->{'debug'} = 0; | ||
| 196 | |||
| 197 | =item dist_type | ||
| 198 | |||
| 199 | Default distribution type to use when building packages. See C<cpan2dist> | ||
| 200 | or C<CPANPLUS::Dist> for details. An empty string will not use any | ||
| 201 | package building software. Defaults to an empty string. | ||
| 202 | |||
| 203 | =cut | ||
| 204 | |||
| 205 | $Conf->{'conf'}->{'dist_type'} = ''; | ||
| 206 | |||
| 207 | =item email | ||
| 208 | |||
| 209 | Email address to use for anonymous ftp access and as C<from> address | ||
| 210 | when sending emails. Defaults to an C<example.com> address. | ||
| 211 | |||
| 212 | =cut | ||
| 213 | |||
| 214 | $Conf->{'conf'}->{'email'} = DEFAULT_EMAIL; | ||
| 215 | |||
| 216 | =item enable_custom_sources | ||
| 217 | |||
| 218 | Boolean flag indicating whether custom sources should be enabled or | ||
| 219 | not. See the C<CUSTOM MODULE SOURCES> in C<CPANPLUS::Backend> for | ||
| 220 | details on how to use them. | ||
| 221 | |||
| 222 | Defaults to C<true> | ||
| 223 | |||
| 224 | =cut | ||
| 225 | |||
| 226 | ### this addresses #32248 which requests a possibility to | ||
| 227 | ### turn off custom sources | ||
| 228 | $Conf->{'conf'}->{'enable_custom_sources'} = 1; | ||
| 229 | |||
| 230 | =item extractdir | ||
| 231 | |||
| 232 | String containing the directory where fetched archives should be | ||
| 233 | extracted. An empty string will use a directory under your C<base> | ||
| 234 | directory. Defaults to an empty string. | ||
| 235 | |||
| 236 | =cut | ||
| 237 | |||
| 238 | $Conf->{'conf'}->{'extractdir'} = ''; | ||
| 239 | |||
| 240 | =item fetchdir | ||
| 241 | |||
| 242 | String containing the directory where fetched archives should be | ||
| 243 | stored. An empty string will use a directory under your C<base> | ||
| 244 | directory. Defaults to an empty string. | ||
| 245 | |||
| 246 | =cut | ||
| 247 | |||
| 248 | $Conf->{'conf'}->{'fetchdir'} = ''; | ||
| 249 | |||
| 250 | =item flush | ||
| 251 | |||
| 252 | Boolean indicating whether build failures, cache dirs etc should | ||
| 253 | be flushed after every operation or not. Defaults to 'true'. | ||
| 254 | |||
| 255 | =cut | ||
| 256 | |||
| 257 | $Conf->{'conf'}->{'flush'} = 1; | ||
| 258 | |||
| 259 | =item force | ||
| 260 | |||
| 261 | Boolean indicating whether files should be forcefully overwritten | ||
| 262 | if they exist, modules should be installed when they fail tests, | ||
| 263 | etc. Defaults to 'false'. | ||
| 264 | |||
| 265 | =cut | ||
| 266 | |||
| 267 | $Conf->{'conf'}->{'force'} = 0; | ||
| 268 | |||
| 269 | =item histfile | ||
| 270 | |||
| 271 | A string containing the history filename of the CPANPLUS readline instance. | ||
| 272 | |||
| 273 | =cut | ||
| 274 | |||
| 275 | $Conf->{'conf'}->{'histfile'} = File::Spec->catdir( | ||
| 276 | __PACKAGE__->_home_dir, DOT_CPANPLUS, 'history' ); | ||
| 277 | |||
| 278 | =item lib | ||
| 279 | |||
| 280 | An array ref holding directories to be added to C<@INC> when CPANPLUS | ||
| 281 | starts up. Defaults to an empty array reference. | ||
| 282 | |||
| 283 | =cut | ||
| 284 | |||
| 285 | $Conf->{'conf'}->{'lib'} = []; | ||
| 286 | |||
| 287 | =item makeflags | ||
| 288 | |||
| 289 | A string holding flags that will be passed to the C<make> program | ||
| 290 | when invoked. Defaults to an empty string. | ||
| 291 | |||
| 292 | =cut | ||
| 293 | |||
| 294 | $Conf->{'conf'}->{'makeflags'} = ''; | ||
| 295 | |||
| 296 | =item makemakerflags | ||
| 297 | |||
| 298 | A string holding flags that will be passed to C<perl Makefile.PL> | ||
| 299 | when invoked. Defaults to an empty string. | ||
| 300 | |||
| 301 | =cut | ||
| 302 | |||
| 303 | $Conf->{'conf'}->{'makemakerflags'} = ''; | ||
| 304 | |||
| 305 | =item md5 | ||
| 306 | |||
| 307 | A boolean indicating whether or not sha256 checks should be done when | ||
| 308 | an archive is fetched. Defaults to 'true' if you have C<Digest::SHA> | ||
| 309 | installed, 'false' otherwise. | ||
| 310 | |||
| 311 | =cut | ||
| 312 | |||
| 313 | $Conf->{'conf'}->{'md5'} = ( | ||
| 314 | check_install( module => 'Digest::SHA' ) ? 1 : 0 ); | ||
| 315 | |||
| 316 | =item no_update | ||
| 317 | |||
| 318 | A boolean indicating whether or not C<CPANPLUS>' source files should be | ||
| 319 | updated or not. Defaults to 'false'. | ||
| 320 | |||
| 321 | =cut | ||
| 322 | |||
| 323 | $Conf->{'conf'}->{'no_update'} = 0; | ||
| 324 | |||
| 325 | =item passive | ||
| 326 | |||
| 327 | A boolean indicating whether or not to use passive ftp connections. | ||
| 328 | Defaults to 'true'. | ||
| 329 | |||
| 330 | =cut | ||
| 331 | |||
| 332 | $Conf->{'conf'}->{'passive'} = 1; | ||
| 333 | |||
| 334 | =item prefer_bin | ||
| 335 | |||
| 336 | A boolean indicating whether or not to prefer command line programs | ||
| 337 | over perl modules. Defaults to 'false' unless you do not have | ||
| 338 | C<Compress::Zlib> installed (as that would mean we could not extract | ||
| 339 | C<.tar.gz> files) | ||
| 340 | |||
| 341 | =cut | ||
| 342 | |||
| 343 | ### if we don't have c::zlib, we'll need to use /bin/tar or we | ||
| 344 | ### can not extract any files. Good time to change the default | ||
| 345 | $Conf->{'conf'}->{'prefer_bin'} = | ||
| 346 | (eval {require Compress::Zlib; 1} ? 0 : 1 ); | ||
| 347 | |||
| 348 | =item prefer_makefile | ||
| 349 | |||
| 350 | A boolean indicating whether or not prefer a C<Makefile.PL> over a | ||
| 351 | C<Build.PL> file if both are present. Defaults to 'true', unless | ||
| 352 | the perl version is at least 5.10.1 or appropriate versions of L<Module::Build> | ||
| 353 | and L<CPANPLUS::Dist::Build> are available. | ||
| 354 | |||
| 355 | =cut | ||
| 356 | |||
| 357 | $Conf->{'conf'}->{'prefer_makefile'} = | ||
| 358 | ( $] >= 5.010001 or | ||
| 359 | ( check_install( module => 'Module::Build', version => '0.32' ) and | ||
| 360 | check_install( module => INSTALLER_BUILD, version => '0.60' ) ) | ||
| 361 | ? 0 : 1 ); | ||
| 362 | |||
| 363 | =item prereqs | ||
| 364 | |||
| 365 | A digit indicating what to do when a package you are installing has a | ||
| 366 | prerequisite. Options are: | ||
| 367 | |||
| 368 | 0 Do not install | ||
| 369 | 1 Install | ||
| 370 | 2 Ask | ||
| 371 | 3 Ignore (dangerous, install will probably fail!) | ||
| 372 | |||
| 373 | The default is to ask. | ||
| 374 | |||
| 375 | =cut | ||
| 376 | |||
| 377 | $Conf->{'conf'}->{'prereqs'} = PREREQ_ASK; | ||
| 378 | |||
| 379 | =item shell | ||
| 380 | |||
| 381 | A string holding the shell class you wish to start up when starting | ||
| 382 | C<CPANPLUS> in interactive mode. | ||
| 383 | |||
| 384 | Defaults to C<CPANPLUS::Shell::Default>, the default CPANPLUS shell. | ||
| 385 | |||
| 386 | =cut | ||
| 387 | |||
| 388 | $Conf->{'conf'}->{'shell'} = 'CPANPLUS::Shell::Default'; | ||
| 389 | |||
| 390 | =item show_startup_tip | ||
| 391 | |||
| 392 | A boolean indicating whether or not to show start up tips in the | ||
| 393 | interactive shell. Defaults to 'true'. | ||
| 394 | |||
| 395 | =cut | ||
| 396 | |||
| 397 | $Conf->{'conf'}->{'show_startup_tip'} = 1; | ||
| 398 | |||
| 399 | =item signature | ||
| 400 | |||
| 401 | A boolean indicating whether or not check signatures if packages are | ||
| 402 | signed. Defaults to 'true' if you have C<gpg> or C<Crypt::OpenPGP> | ||
| 403 | installed, 'false' otherwise. | ||
| 404 | |||
| 405 | =cut | ||
| 406 | |||
| 407 | $Conf->{'conf'}->{'signature'} = do { | ||
| 408 | check_install( module => 'Module::Signature', version => '0.06' ) | ||
| 409 | and ( can_run('gpg') || | ||
| 410 | check_install(module => 'Crypt::OpenPGP') | ||
| 411 | ); | ||
| 412 | } ? 1 : 0; | ||
| 413 | |||
| 414 | =item skiptest | ||
| 415 | |||
| 416 | A boolean indicating whether or not to skip tests when installing modules. | ||
| 417 | Defaults to 'false'. | ||
| 418 | |||
| 419 | =cut | ||
| 420 | |||
| 421 | $Conf->{'conf'}->{'skiptest'} = 0; | ||
| 422 | |||
| 423 | =item storable | ||
| 424 | |||
| 425 | A boolean indicating whether or not to use C<Storable> to write compiled | ||
| 426 | source file information to disk. This makes for faster startup and look | ||
| 427 | up times, but takes extra diskspace. Defaults to 'true' if you have | ||
| 428 | C<Storable> installed and 'false' if you don't. | ||
| 429 | |||
| 430 | =cut | ||
| 431 | |||
| 432 | $Conf->{'conf'}->{'storable'} = | ||
| 433 | ( check_install( module => 'Storable' ) ? 1 : 0 ); | ||
| 434 | |||
| 435 | =item timeout | ||
| 436 | |||
| 437 | Digit indicating the time before a fetch request times out (in seconds). | ||
| 438 | Defaults to 300. | ||
| 439 | |||
| 440 | =cut | ||
| 441 | |||
| 442 | $Conf->{'conf'}->{'timeout'} = 300; | ||
| 443 | |||
| 444 | =item verbose | ||
| 445 | |||
| 446 | A boolean indicating whether or not C<CPANPLUS> runs in verbose mode. | ||
| 447 | Defaults to 'true' if you have the environment variable | ||
| 448 | C<PERL5_CPANPLUS_VERBOSE> set to true, 'false' otherwise. | ||
| 449 | |||
| 450 | It is recommended you run with verbose enabled, but it is disabled | ||
| 451 | for historical reasons. | ||
| 452 | |||
| 453 | =cut | ||
| 454 | |||
| 455 | $Conf->{'conf'}->{'verbose'} = $ENV{PERL5_CPANPLUS_VERBOSE} || 0; | ||
| 456 | |||
| 457 | =item write_install_log | ||
| 458 | |||
| 459 | A boolean indicating whether or not to write install logs after installing | ||
| 460 | a module using the interactive shell. Defaults to 'true'. | ||
| 461 | |||
| 462 | |||
| 463 | =cut | ||
| 464 | |||
| 465 | $Conf->{'conf'}->{'write_install_logs'} = 1; | ||
| 466 | |||
| 467 | =item source_engine | ||
| 468 | |||
| 469 | Class to use as the source engine, which is generally a subclass of | ||
| 470 | C<CPANPLUS::Internals::Source>. Default to C<CPANPLUS::Internals::Source::Memory>. | ||
| 471 | |||
| 472 | =cut | ||
| 473 | |||
| 474 | $Conf->{'conf'}->{'source_engine'} = DEFAULT_SOURCE_ENGINE; | ||
| 475 | |||
| 476 | =item cpantest_reporter_args | ||
| 477 | |||
| 478 | A hashref of key => value pairs that are passed to the constructor | ||
| 479 | of C<Test::Reporter>. If you'd want to enable TLS for example, you'd | ||
| 480 | set it to: | ||
| 481 | |||
| 482 | { transport => 'Net::SMTP::TLS', | ||
| 483 | transport_args => [ User => 'Joe', Password => '123' ], | ||
| 484 | } | ||
| 485 | |||
| 486 | =cut | ||
| 487 | |||
| 488 | $Conf->{'conf'}->{'cpantest_reporter_args'} = {}; | ||
| 489 | |||
| 490 | =back | ||
| 491 | |||
| 492 | =head2 Section 'program' | ||
| 493 | |||
| 494 | =cut | ||
| 495 | |||
| 496 | ### Paths get stripped of whitespace on win32 in the constructor | ||
| 497 | ### sudo gets emptied if there's no need for it in the constructor | ||
| 498 | |||
| 499 | =over 4 | ||
| 500 | |||
| 501 | =item editor | ||
| 502 | |||
| 503 | A string holding the path to your editor of choice. Defaults to your | ||
| 504 | $ENV{EDITOR}, $ENV{VISUAL}, 'vi' or 'pico' programs, in that order. | ||
| 505 | |||
| 506 | =cut | ||
| 507 | |||
| 508 | $Conf->{'program'}->{'editor'} = do { | ||
| 509 | $ENV{'EDITOR'} || $ENV{'VISUAL'} || | ||
| 510 | can_run('vi') || can_run('pico') | ||
| 511 | }; | ||
| 512 | |||
| 513 | =item make | ||
| 514 | |||
| 515 | A string holding the path to your C<make> binary. Looks for the C<make> | ||
| 516 | program used to build perl or failing that, a C<make> in your path. | ||
| 517 | |||
| 518 | =cut | ||
| 519 | |||
| 520 | $Conf->{'program'}->{'make'} = | ||
| 521 | can_run($Config{'make'}) || can_run('make'); | ||
| 522 | |||
| 523 | =item pager | ||
| 524 | |||
| 525 | A string holding the path to your pager of choice. Defaults to your | ||
| 526 | $ENV{PAGER}, 'less' or 'more' programs, in that order. | ||
| 527 | |||
| 528 | =cut | ||
| 529 | |||
| 530 | $Conf->{'program'}->{'pager'} = | ||
| 531 | $ENV{'PAGER'} || can_run('less') || can_run('more'); | ||
| 532 | |||
| 533 | ### no one uses this feature anyway, and it's only working for EU::MM | ||
| 534 | ### and not for module::build | ||
| 535 | #'perl' => '', | ||
| 536 | |||
| 537 | =item shell | ||
| 538 | |||
| 539 | A string holding the path to your login shell of choice. Defaults to your | ||
| 540 | $ENV{SHELL} setting, or $ENV{COMSPEC} on Windows. | ||
| 541 | |||
| 542 | =cut | ||
| 543 | |||
| 544 | $Conf->{'program'}->{'shell'} = $^O eq 'MSWin32' | ||
| 545 | ? $ENV{COMSPEC} | ||
| 546 | : $ENV{SHELL}; | ||
| 547 | |||
| 548 | =item sudo | ||
| 549 | |||
| 550 | A string holding the path to your C<sudo> binary if your install path | ||
| 551 | requires super user permissions. Looks for C<sudo> in your path, or | ||
| 552 | remains empty if you do not require super user permissions to install. | ||
| 553 | |||
| 554 | =cut | ||
| 555 | |||
| 556 | $Conf->{'program'}->{'sudo'} = do { | ||
| 557 | ### let's assume you don't need sudo, | ||
| 558 | ### unless one of the below criteria tells us otherwise | ||
| 559 | my $sudo = undef; | ||
| 560 | |||
| 561 | ### you're a normal user, you might need sudo | ||
| 562 | if( $> ) { | ||
| 563 | |||
| 564 | ### check for all install dirs! | ||
| 565 | ### you have write permissions to the installdir, | ||
| 566 | ### you don't need sudo | ||
| 567 | if( -w $Config{'installsitelib'} && -w $Config{'installsitebin'} ) { | ||
| 568 | |||
| 569 | ### installsiteman3dir is a 5.8'ism.. don't check | ||
| 570 | ### it on 5.6.x... | ||
| 571 | if( defined $Config{'installsiteman3dir'} ) { | ||
| 572 | $sudo = -w $Config{'installsiteman3dir'} | ||
| 573 | ? undef | ||
| 574 | : can_run('sudo'); | ||
| 575 | } else { | ||
| 576 | $sudo = undef; | ||
| 577 | } | ||
| 578 | |||
| 579 | ### you have PERL_MM_OPT set to some alternate | ||
| 580 | ### install place. You probably have write permissions | ||
| 581 | ### to that | ||
| 582 | } elsif ( $ENV{'PERL_MM_OPT'} and | ||
| 583 | $ENV{'PERL_MM_OPT'} =~ /INSTALL|LIB|PREFIX/ | ||
| 584 | ) { | ||
| 585 | $sudo = undef; | ||
| 586 | |||
| 587 | ### you probably don't have write permissions | ||
| 588 | } else { | ||
| 589 | $sudo = can_run('sudo'); | ||
| 590 | } | ||
| 591 | } | ||
| 592 | |||
| 593 | ### and return the value | ||
| 594 | $sudo; | ||
| 595 | }; | ||
| 596 | |||
| 597 | =item perlwrapper | ||
| 598 | |||
| 599 | B<DEPRECATED> | ||
| 600 | |||
| 601 | A string holding the path to the C<cpanp-run-perl> utility bundled | ||
| 602 | with CPANPLUS, which is used to enable autoflushing in spawned processes. | ||
| 603 | |||
| 604 | =cut | ||
| 605 | |||
| 606 | ### perlwrapper that allows us to turn on autoflushing | ||
| 607 | $Conf->{'program'}->{'perlwrapper'} = sub { | ||
| 608 | my $name = 'cpanp-run-perl'; | ||
| 609 | |||
| 610 | my @bins = do{ | ||
| 611 | require Config; | ||
| 612 | my $ver = $Config::Config{version}; | ||
| 613 | |||
| 614 | ### if we are running with 'versiononly' enabled, | ||
| 615 | ### all binaries will have the perlversion appended | ||
| 616 | ### ie, cpanp will become cpanp5.9.5 | ||
| 617 | ### so prefer the versioned binary in that case | ||
| 618 | $Config::Config{versiononly} | ||
| 619 | ? ($name.$ver, $name) | ||
| 620 | : ($name, $name.$ver); | ||
| 621 | }; | ||
| 622 | |||
| 623 | ### patch from Steve Hay Fri 29 Jun 2007 14:26:02 GMT+02:00 | ||
| 624 | ### Msg-Id: <4684FA5A.7030506@uk.radan.com> | ||
| 625 | ### look for files with a ".bat" extension as well on Win32 | ||
| 626 | @bins = map { $_, "$_.bat" } @bins if $^O eq 'MSWin32'; | ||
| 627 | |||
| 628 | my $path; | ||
| 629 | BIN: for my $bin (@bins) { | ||
| 630 | |||
| 631 | ### parallel to your cpanp/cpanp-boxed | ||
| 632 | my $maybe = File::Spec->rel2abs( | ||
| 633 | File::Spec->catfile( dirname($0), $bin ) | ||
| 634 | ); | ||
| 635 | $path = $maybe and last BIN if -f $maybe; | ||
| 636 | |||
| 637 | ### parallel to your CPANPLUS.pm: | ||
| 638 | ### $INC{cpanplus}/../bin/cpanp-run-perl | ||
| 639 | $maybe = File::Spec->rel2abs( | ||
| 640 | File::Spec->catfile( | ||
| 641 | dirname($INC{'CPANPLUS.pm'}), | ||
| 642 | '..', # lib dir | ||
| 643 | 'bin', # bin dir | ||
| 644 | $bin, # script | ||
| 645 | ) | ||
| 646 | ); | ||
| 647 | $path = $maybe and last BIN if -f $maybe; | ||
| 648 | |||
| 649 | ### you installed CPANPLUS in a custom prefix, | ||
| 650 | ### so go parallel to /that/. PREFIX=/tmp/cp | ||
| 651 | ### would put cpanp-run-perl in /tmp/cp/bin and | ||
| 652 | ### CPANPLUS.pm in | ||
| 653 | ### /tmp/cp/lib/perl5/site_perl/5.8.8 | ||
| 654 | $maybe = File::Spec->rel2abs( | ||
| 655 | File::Spec->catfile( | ||
| 656 | dirname( $INC{'CPANPLUS.pm'} ), | ||
| 657 | '..', '..', '..', '..', # 4x updir | ||
| 658 | 'bin', # bin dir | ||
| 659 | $bin, # script | ||
| 660 | ) | ||
| 661 | ); | ||
| 662 | $path = $maybe and last BIN if -f $maybe; | ||
| 663 | |||
| 664 | ### in your path -- take this one last, the | ||
| 665 | ### previous two assume extracted tarballs | ||
| 666 | ### or user installs | ||
| 667 | ### note that we don't use 'can_run' as it's | ||
| 668 | ### not an executable, just a wrapper... | ||
| 669 | ### prefer anything that's found in the path parallel to your $^X | ||
| 670 | for my $dir (File::Spec->rel2abs( dirname($^X) ), | ||
| 671 | split(/\Q$Config::Config{path_sep}\E/, $ENV{PATH}), | ||
| 672 | File::Spec->curdir, | ||
| 673 | ) { | ||
| 674 | |||
| 675 | ### On VMS the path could be in UNIX format, and we | ||
| 676 | ### currently need it to be in VMS format | ||
| 677 | $dir = VMS::Filespec::vmspath($dir) if ON_VMS; | ||
| 678 | |||
| 679 | $maybe = File::Spec->catfile( $dir, $bin ); | ||
| 680 | $path = $maybe and last BIN if -f $maybe; | ||
| 681 | } | ||
| 682 | } | ||
| 683 | |||
| 684 | ### we should have a $path by now ideally, if so return it | ||
| 685 | return $path if defined $path; | ||
| 686 | |||
| 687 | ### CPANPLUS::Dist::MM doesn't require this anymore | ||
| 688 | ### but CPANPLUS::Dist::Build might if it is less than 0.60 | ||
| 689 | my $cpdb = check_install( module => INSTALLER_BUILD ); | ||
| 690 | return '' unless | ||
| 691 | $cpdb and eval { version->parse($cpdb->{version}) < version->parse('0.60') }; | ||
| 692 | |||
| 693 | ### if not, warn about it and give sensible default. | ||
| 694 | ### XXX try to be a no-op instead then.. | ||
| 695 | ### cross your fingers... | ||
| 696 | ### pass '-P' to perl: "run program through C | ||
| 697 | ### preprocessor before compilation" | ||
| 698 | ### XXX using -P actually changes the way some Makefile.PLs | ||
| 699 | ### are executed, so don't do that... --kane | ||
| 700 | error(loc( | ||
| 701 | "Could not find the '%1' binary in your path". | ||
| 702 | "--this may be a problem.\n". | ||
| 703 | "Please locate this program and set ". | ||
| 704 | "your '%2' config entry to its path.\n". | ||
| 705 | "From the default shell, you can do this by typing:\n\n". | ||
| 706 | " %3\n". | ||
| 707 | " %4\n", | ||
| 708 | $name, 'perlwrapper', | ||
| 709 | 's program perlwrapper FULL_PATH_TO_CPANP_RUN_PERL', | ||
| 710 | 's save' | ||
| 711 | )); | ||
| 712 | return ''; | ||
| 713 | }->(); | ||
| 714 | |||
| 715 | =back | ||
| 716 | |||
| 717 | =cut | ||
| 718 | |||
| 719 | sub new { | ||
| 720 | my $class = shift; | ||
| 721 | my $obj = $class->SUPER::new; | ||
| 722 | |||
| 723 | $obj->mk_accessors( keys %$Conf ); | ||
| 724 | |||
| 725 | for my $acc ( keys %$Conf ) { | ||
| 726 | my $subobj = Object::Accessor->new; | ||
| 727 | $subobj->mk_accessors( keys %{$Conf->{$acc}} ); | ||
| 728 | |||
| 729 | ### read in all the settings from the sub accessors; | ||
| 730 | for my $subacc ( $subobj->ls_accessors ) { | ||
| 731 | $subobj->$subacc( $Conf->{$acc}->{$subacc} ); | ||
| 732 | } | ||
| 733 | |||
| 734 | ### now store it in the parent object | ||
| 735 | $obj->$acc( $subobj ); | ||
| 736 | } | ||
| 737 | |||
| 738 | $obj->_clean_up_paths; | ||
| 739 | |||
| 740 | ### shut up IPC::Cmd warning about not finding IPC::Run on win32 | ||
| 741 | $IPC::Cmd::WARN = 0; | ||
| 742 | |||
| 743 | return $obj; | ||
| 744 | } | ||
| 745 | |||
| 746 | sub _clean_up_paths { | ||
| 747 | my $self = shift; | ||
| 748 | |||
| 749 | ### clean up paths if we are on win32 | ||
| 750 | if( $^O eq 'MSWin32' ) { | ||
| 751 | for my $pgm ( $self->program->ls_accessors ) { | ||
| 752 | my $path = $self->program->$pgm; | ||
| 753 | |||
| 754 | ### paths with whitespace needs to be shortened | ||
| 755 | ### for shell outs. | ||
| 756 | if ($path and $path =~ /\s+/) { | ||
| 757 | my($prog, $args); | ||
| 758 | |||
| 759 | ### patch from Steve Hay, 13th of June 2007 | ||
| 760 | ### msg-id: <467012A4.6060705@uk.radan.com> | ||
| 761 | ### windows directories are not allowed to end with | ||
| 762 | ### a space, so any occurrence of '\w\s+/\w+' means | ||
| 763 | ### we're dealing with arguments, not directory | ||
| 764 | ### names. | ||
| 765 | if ($path =~ /^(.*?)(\s+\/.*$)/) { | ||
| 766 | ($prog, $args) = ($1, $2); | ||
| 767 | |||
| 768 | ### otherwise, there are no arguments | ||
| 769 | } else { | ||
| 770 | ($prog, $args) = ($path, ''); | ||
| 771 | } | ||
| 772 | |||
| 773 | $prog = Win32::GetShortPathName( $prog ); | ||
| 774 | $self->program->$pgm( $prog . $args ); | ||
| 775 | } | ||
| 776 | } | ||
| 777 | } | ||
| 778 | |||
| 779 | return 1; | ||
| 780 | } | ||
| 781 | |||
| 782 | 1; | ||
| 783 | |||
| 784 | =pod | ||
| 785 | |||
| 786 | =head1 BUG REPORTS | ||
| 787 | |||
| 788 | Please report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>. | ||
| 789 | |||
| 790 | =head1 AUTHOR | ||
| 791 | |||
| 792 | This module by Jos Boumans E<lt>kane@cpan.orgE<gt>. | ||
| 793 | |||
| 794 | =head1 COPYRIGHT | ||
| 795 | |||
| 796 | The CPAN++ interface (of which this module is a part of) is copyright (c) | ||
| 797 | 2001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved. | ||
| 798 | |||
| 799 | This library is free software; you may redistribute and/or modify it | ||
| 800 | under the same terms as Perl itself. | ||
| 801 | |||
| 802 | =head1 SEE ALSO | ||
| 803 | |||
| 804 | L<CPANPLUS::Backend>, L<CPANPLUS::Configure::Setup>, L<CPANPLUS::Configure> | ||
| 805 | |||
| 806 | =cut | ||
| 807 | |||
| 808 | # Local variables: | ||
| 809 | # c-indentation-style: bsd | ||
| 810 | # c-basic-offset: 4 | ||
| 811 | # indent-tabs-mode: nil | ||
| 812 | # End: | ||
| 813 | # vim: expandtab shiftwidth=4: |