| 1 | package CPANPLUS::Configure::Setup; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use vars qw[@ISA $VERSION]; | ||
| 5 | $VERSION = "0.9912"; | ||
| 6 | |||
| 7 | use base qw[CPANPLUS::Internals::Utils]; | ||
| 8 | use base qw[Object::Accessor]; | ||
| 9 | |||
| 10 | use Config; | ||
| 11 | use Term::UI; | ||
| 12 | use Module::Load; | ||
| 13 | use Term::ReadLine; | ||
| 14 | |||
| 15 | use CPANPLUS::Internals::Utils; | ||
| 16 | use CPANPLUS::Internals::Constants; | ||
| 17 | use CPANPLUS::Error; | ||
| 18 | |||
| 19 | use IPC::Cmd qw[can_run]; | ||
| 20 | use Params::Check qw[check]; | ||
| 21 | use Module::Load::Conditional qw[check_install]; | ||
| 22 | use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext'; | ||
| 23 | |||
| 24 | ### silence Term::UI | ||
| 25 | $Term::UI::VERBOSE = 0; | ||
| 26 | |||
| 27 | #Can't ioctl TIOCGETP: Unknown error | ||
| 28 | #Consider installing Term::ReadKey from CPAN site nearby | ||
| 29 | # at http://www.perl.com/CPAN | ||
| 30 | #Or use | ||
| 31 | # perl -MCPAN -e shell | ||
| 32 | #to reach CPAN. Falling back to 'stty'. | ||
| 33 | # If you do not want to see this warning, set PERL_READLINE_NOWARN | ||
| 34 | #in your environment. | ||
| 35 | #'stty' is not recognized as an internal or external command, | ||
| 36 | #operable program or batch file. | ||
| 37 | #Cannot call `stty': No such file or directory at C:/Perl/site/lib/Term/ReadLine/ | ||
| 38 | |||
| 39 | ### setting this var in the meantime to avoid this warning ### | ||
| 40 | $ENV{PERL_READLINE_NOWARN} = 1; | ||
| 41 | |||
| 42 | |||
| 43 | sub new { | ||
| 44 | my $class = shift; | ||
| 45 | my %hash = @_; | ||
| 46 | |||
| 47 | my $tmpl = { | ||
| 48 | configure_object => { }, | ||
| 49 | term => { }, | ||
| 50 | backend => { }, | ||
| 51 | autoreply => { default => 0, }, | ||
| 52 | skip_mirrors => { default => 0, }, | ||
| 53 | use_previous => { default => 1, }, | ||
| 54 | config_type => { default => CONFIG_USER }, | ||
| 55 | }; | ||
| 56 | |||
| 57 | my $args = check( $tmpl, \%hash ) or return; | ||
| 58 | |||
| 59 | ### initialize object | ||
| 60 | my $obj = $class->SUPER::new( keys %$tmpl ); | ||
| 61 | for my $acc ( $obj->ls_accessors ) { | ||
| 62 | $obj->$acc( $args->{$acc} ); | ||
| 63 | } | ||
| 64 | |||
| 65 | ### otherwise there's a circular use ### | ||
| 66 | load CPANPLUS::Configure; | ||
| 67 | load CPANPLUS::Backend; | ||
| 68 | |||
| 69 | $obj->configure_object( CPANPLUS::Configure->new() ) | ||
| 70 | unless $obj->configure_object; | ||
| 71 | |||
| 72 | $obj->backend( CPANPLUS::Backend->new( $obj->configure_object ) ) | ||
| 73 | unless $obj->backend; | ||
| 74 | |||
| 75 | ### use empty string in case user only has T::R::Stub -- it complains | ||
| 76 | $obj->term( Term::ReadLine->new('') ) | ||
| 77 | unless $obj->term; | ||
| 78 | |||
| 79 | ### enable autoreply if that was passed ### | ||
| 80 | $Term::UI::AUTOREPLY = $obj->autoreply; | ||
| 81 | |||
| 82 | return $obj; | ||
| 83 | } | ||
| 84 | |||
| 85 | sub init { | ||
| 86 | my $self = shift; | ||
| 87 | my $term = $self->term; | ||
| 88 | |||
| 89 | ### default setting, unless changed | ||
| 90 | $self->config_type( CONFIG_USER ) unless $self->config_type; | ||
| 91 | |||
| 92 | my $save = loc('Save & exit'); | ||
| 93 | my $exit = loc('Quit without saving'); | ||
| 94 | my @map = ( | ||
| 95 | # key on the display # method to dispatch to | ||
| 96 | [ loc('Select Configuration file') => '_save_where' ], | ||
| 97 | [ loc('Setup CLI Programs') => '_setup_program' ], | ||
| 98 | [ loc('Setup CPANPLUS Home directory') => '_setup_base' ], | ||
| 99 | [ loc('Setup FTP/Email settings') => '_setup_ftp' ], | ||
| 100 | [ loc('Setup basic preferences') => '_setup_conf' ], | ||
| 101 | [ loc('Setup installer settings') => '_setup_installer' ], | ||
| 102 | [ loc('Select mirrors'), => '_setup_hosts' ], | ||
| 103 | [ loc('Edit configuration file') => '_edit' ], | ||
| 104 | [ $save => '_save' ], | ||
| 105 | [ $exit => 1 ], | ||
| 106 | ); | ||
| 107 | |||
| 108 | my @keys = map { $_->[0] } @map; # sorted keys | ||
| 109 | my %map = map { @$_ } @map; # lookup hash | ||
| 110 | |||
| 111 | PICK_SECTION: { | ||
| 112 | print loc(" | ||
| 113 | =================> MAIN MENU <================= | ||
| 114 | |||
| 115 | Welcome to the CPANPLUS configuration. Please select which | ||
| 116 | parts you wish to configure | ||
| 117 | |||
| 118 | Defaults are taken from your current configuration. | ||
| 119 | If you would save now, your settings would be written to: | ||
| 120 | |||
| 121 | %1 | ||
| 122 | |||
| 123 | ", $self->config_type ); | ||
| 124 | |||
| 125 | my $choice = $term->get_reply( | ||
| 126 | prompt => "Section to configure:", | ||
| 127 | choices => \@keys, | ||
| 128 | default => $keys[0] | ||
| 129 | ); | ||
| 130 | |||
| 131 | ### exit configuration? | ||
| 132 | if( $choice eq $exit ) { | ||
| 133 | print loc(" | ||
| 134 | Quitting setup, changes will not be saved. | ||
| 135 | "); | ||
| 136 | return 1; | ||
| 137 | } | ||
| 138 | |||
| 139 | my $method = $map{$choice}; | ||
| 140 | |||
| 141 | my $rv = $self->$method or print loc(" | ||
| 142 | There was an error setting up this section. You might want to try again | ||
| 143 | "); | ||
| 144 | |||
| 145 | ### was it save & exit? | ||
| 146 | if( $choice eq $save and $rv ) { | ||
| 147 | print loc(" | ||
| 148 | Quitting setup, changes are saved to '%1' | ||
| 149 | ", $self->config_type | ||
| 150 | ); | ||
| 151 | return 1; | ||
| 152 | } | ||
| 153 | |||
| 154 | ### otherwise, present choice again | ||
| 155 | redo PICK_SECTION; | ||
| 156 | } | ||
| 157 | } | ||
| 158 | |||
| 159 | |||
| 160 | |||
| 161 | ### sub that figures out what kind of config type the user wants | ||
| 162 | sub _save_where { | ||
| 163 | my $self = shift; | ||
| 164 | my $term = $self->term; | ||
| 165 | my $conf = $self->configure_object; | ||
| 166 | |||
| 167 | |||
| 168 | ASK_CONFIG_TYPE: { | ||
| 169 | |||
| 170 | print loc( q[ | ||
| 171 | Where would you like to save your CPANPLUS Configuration file? | ||
| 172 | |||
| 173 | If you want to configure CPANPLUS for this user only, | ||
| 174 | select the '%1' option. | ||
| 175 | The file will then be saved in your homedirectory. | ||
| 176 | |||
| 177 | If you are the system administrator of this machine, | ||
| 178 | and would like to make this config available globally, | ||
| 179 | select the '%2' option. | ||
| 180 | The file will be then be saved in your CPANPLUS | ||
| 181 | installation directory. | ||
| 182 | |||
| 183 | ], CONFIG_USER, CONFIG_SYSTEM ); | ||
| 184 | |||
| 185 | |||
| 186 | ### ask what config type we should save to | ||
| 187 | my $type = $term->get_reply( | ||
| 188 | prompt => loc("Type of configuration file"), | ||
| 189 | default => $self->config_type || CONFIG_USER, | ||
| 190 | choices => [CONFIG_USER, CONFIG_SYSTEM], | ||
| 191 | ); | ||
| 192 | |||
| 193 | my $file = $conf->_config_pm_to_file( $type ); | ||
| 194 | |||
| 195 | ### can we save to this file? | ||
| 196 | unless( $conf->can_save( $file ) ) { | ||
| 197 | error(loc( | ||
| 198 | "Can not save to file '%1'-- please check permissions " . | ||
| 199 | "and try again", $file | ||
| 200 | )); | ||
| 201 | |||
| 202 | redo ASK_CONFIG_FILE; | ||
| 203 | } | ||
| 204 | |||
| 205 | ### you already have the file -- are we allowed to overwrite | ||
| 206 | ### or should we try again? | ||
| 207 | if ( -e $file and -w _ ) { | ||
| 208 | print loc(q[ | ||
| 209 | I see you already have this file: | ||
| 210 | %1 | ||
| 211 | |||
| 212 | The file will not be overwritten until you explicitly save it. | ||
| 213 | |||
| 214 | ], $file ); | ||
| 215 | |||
| 216 | redo ASK_CONFIG_TYPE | ||
| 217 | unless $term->ask_yn( | ||
| 218 | prompt => loc( "Do you wish to use this file?"), | ||
| 219 | default => 'n', | ||
| 220 | ); | ||
| 221 | } | ||
| 222 | |||
| 223 | print $/, loc("Using '%1' as your configuration type", $type); | ||
| 224 | |||
| 225 | return $self->config_type($type); | ||
| 226 | } | ||
| 227 | } | ||
| 228 | |||
| 229 | |||
| 230 | ### setup the build & cache dirs | ||
| 231 | sub _setup_base { | ||
| 232 | my $self = shift; | ||
| 233 | my $term = $self->term; | ||
| 234 | my $conf = $self->configure_object; | ||
| 235 | |||
| 236 | my $base = $conf->get_conf('base'); | ||
| 237 | my $home = File::Spec->catdir( $self->_home_dir, DOT_CPANPLUS ); | ||
| 238 | |||
| 239 | print loc(" | ||
| 240 | CPANPLUS needs a directory of its own to cache important index | ||
| 241 | files and maybe keep a temporary mirror of CPAN files. | ||
| 242 | This may be a site-wide directory or a personal directory. | ||
| 243 | |||
| 244 | For a single-user installation, we suggest using your home directory. | ||
| 245 | |||
| 246 | "); | ||
| 247 | |||
| 248 | my $where; | ||
| 249 | ASK_HOME_DIR: { | ||
| 250 | my $other = loc('Somewhere else'); | ||
| 251 | if( $base and ($base ne $home) ) { | ||
| 252 | print loc("You have several choices:"); | ||
| 253 | |||
| 254 | $where = $term->get_reply( | ||
| 255 | prompt => loc('Please pick one'), | ||
| 256 | choices => [$home, $base, $other], | ||
| 257 | default => $home, | ||
| 258 | ); | ||
| 259 | } else { | ||
| 260 | $where = $base; | ||
| 261 | } | ||
| 262 | |||
| 263 | if( $where and -d $where ) { | ||
| 264 | print loc(" | ||
| 265 | I see you already have a directory: | ||
| 266 | %1 | ||
| 267 | |||
| 268 | "), $where; | ||
| 269 | |||
| 270 | my $yn = $term->ask_yn( | ||
| 271 | prompt => loc('Should I use it?'), | ||
| 272 | default => 'y', | ||
| 273 | ); | ||
| 274 | $where = '' unless $yn; | ||
| 275 | } | ||
| 276 | |||
| 277 | if( $where and ($where ne $other) and not -d $where ) { | ||
| 278 | if (!$self->_mkdir( dir => $where ) ) { | ||
| 279 | print "\n", loc("Unable to create directory '%1'", $where); | ||
| 280 | redo ASK_HOME_DIR; | ||
| 281 | } | ||
| 282 | |||
| 283 | } elsif( not $where or ($where eq $other) ) { | ||
| 284 | print loc(" | ||
| 285 | First of all, I'd like to create this directory. | ||
| 286 | |||
| 287 | "); | ||
| 288 | |||
| 289 | NEW_HOME: { | ||
| 290 | $where = $term->get_reply( | ||
| 291 | prompt => loc('Where shall I create it?'), | ||
| 292 | default => $home, | ||
| 293 | ); | ||
| 294 | |||
| 295 | my $again; | ||
| 296 | if( -d $where and not -w _ ) { | ||
| 297 | print "\n", loc("I can't seem to write in this directory"); | ||
| 298 | $again++; | ||
| 299 | } elsif (!$self->_mkdir( dir => $where ) ) { | ||
| 300 | print "\n", loc("Unable to create directory '%1'", $where); | ||
| 301 | $again++; | ||
| 302 | } | ||
| 303 | |||
| 304 | if( $again ) { | ||
| 305 | print "\n", loc('Please select another directory'), "\n\n"; | ||
| 306 | redo NEW_HOME; | ||
| 307 | } | ||
| 308 | } | ||
| 309 | } | ||
| 310 | } | ||
| 311 | |||
| 312 | ### tidy up the path and store it | ||
| 313 | $where = File::Spec->rel2abs($where); | ||
| 314 | $conf->set_conf( base => $where ); | ||
| 315 | |||
| 316 | ### create subdirectories ### | ||
| 317 | my @dirs = | ||
| 318 | File::Spec->catdir( $where, $self->_perl_version(perl => $^X), | ||
| 319 | $conf->_get_build('moddir') ), | ||
| 320 | map { | ||
| 321 | File::Spec->catdir( $where, $conf->_get_build($_) ) | ||
| 322 | } qw[autdir distdir]; | ||
| 323 | |||
| 324 | for my $dir ( @dirs ) { | ||
| 325 | unless( $self->_mkdir( dir => $dir ) ) { | ||
| 326 | warn loc("I wasn't able to create '%1'", $dir), "\n"; | ||
| 327 | } | ||
| 328 | } | ||
| 329 | |||
| 330 | ### clear away old storable images before 0.031 | ||
| 331 | for my $src (qw[dslip mailrc packages]) { | ||
| 332 | 1 while unlink File::Spec->catfile( $where, $src ); | ||
| 333 | |||
| 334 | } | ||
| 335 | |||
| 336 | print loc(q[ | ||
| 337 | Your CPANPLUS build and cache directory has been set to: | ||
| 338 | %1 | ||
| 339 | |||
| 340 | ], $where); | ||
| 341 | |||
| 342 | return 1; | ||
| 343 | } | ||
| 344 | |||
| 345 | sub _setup_ftp { | ||
| 346 | my $self = shift; | ||
| 347 | my $term = $self->term; | ||
| 348 | my $conf = $self->configure_object; | ||
| 349 | |||
| 350 | ######################### | ||
| 351 | ## are you a pacifist? ## | ||
| 352 | ######################### | ||
| 353 | |||
| 354 | print loc(" | ||
| 355 | If you are connecting through a firewall or proxy that doesn't handle | ||
| 356 | FTP all that well you can use passive FTP. | ||
| 357 | |||
| 358 | "); | ||
| 359 | |||
| 360 | my $yn = $term->ask_yn( | ||
| 361 | prompt => loc("Use passive FTP?"), | ||
| 362 | default => $conf->get_conf('passive'), | ||
| 363 | ); | ||
| 364 | |||
| 365 | $conf->set_conf(passive => $yn); | ||
| 366 | |||
| 367 | ### set the ENV var as well, else it won't get set till AFTER | ||
| 368 | ### the configuration is saved. but we fetch files BEFORE that. | ||
| 369 | $ENV{FTP_PASSIVE} = $yn; | ||
| 370 | |||
| 371 | print "\n"; | ||
| 372 | print $yn | ||
| 373 | ? loc("I will use passive FTP.") | ||
| 374 | : loc("I won't use passive FTP."); | ||
| 375 | print "\n"; | ||
| 376 | |||
| 377 | ############################# | ||
| 378 | ## should fetches timeout? ## | ||
| 379 | ############################# | ||
| 380 | |||
| 381 | print loc(" | ||
| 382 | CPANPLUS can specify a network timeout for downloads (in whole seconds). | ||
| 383 | If none is desired (or to skip this question), enter '0'. | ||
| 384 | |||
| 385 | "); | ||
| 386 | |||
| 387 | my $timeout = 0 + $term->get_reply( | ||
| 388 | prompt => loc("Network timeout for downloads"), | ||
| 389 | default => $conf->get_conf('timeout') || 0, | ||
| 390 | allow => qr/(?!\D)/, ### whole numbers only | ||
| 391 | ); | ||
| 392 | |||
| 393 | $conf->set_conf(timeout => $timeout); | ||
| 394 | |||
| 395 | print "\n"; | ||
| 396 | print $timeout | ||
| 397 | ? loc("The network timeout for downloads is %1 seconds.", $timeout) | ||
| 398 | : loc("The network timeout for downloads is not set."); | ||
| 399 | print "\n"; | ||
| 400 | |||
| 401 | ############################ | ||
| 402 | ## where can I reach you? ## | ||
| 403 | ############################ | ||
| 404 | |||
| 405 | print loc(" | ||
| 406 | What email address should we send as our anonymous password when | ||
| 407 | fetching modules from CPAN servers? Some servers will NOT allow you to | ||
| 408 | connect without a valid email address, or at least something that looks | ||
| 409 | like one. | ||
| 410 | Also, if you choose to report test results at some point, a valid email | ||
| 411 | is required for the 'from' field, so choose wisely. | ||
| 412 | |||
| 413 | "); | ||
| 414 | |||
| 415 | my $other = 'Something else'; | ||
| 416 | my @choices = (DEFAULT_EMAIL, $Config{cf_email}, $other); | ||
| 417 | my $current = $conf->get_conf('email'); | ||
| 418 | |||
| 419 | ### if your current address is not in the list, add it to the choices | ||
| 420 | unless (grep { $_ eq $current } @choices) { | ||
| 421 | unshift @choices, $current; | ||
| 422 | } | ||
| 423 | |||
| 424 | my $email = $term->get_reply( | ||
| 425 | prompt => loc('Which email address shall I use?'), | ||
| 426 | default => $current || $choices[0], | ||
| 427 | choices => \@choices, | ||
| 428 | ); | ||
| 429 | |||
| 430 | if( $email eq $other ) { | ||
| 431 | EMAIL: { | ||
| 432 | $email = $term->get_reply( | ||
| 433 | prompt => loc('Email address: '), | ||
| 434 | ); | ||
| 435 | |||
| 436 | unless( $self->_valid_email($email) ) { | ||
| 437 | print loc(" | ||
| 438 | You did not enter a valid email address, please try again! | ||
| 439 | ") if length $email; | ||
| 440 | |||
| 441 | redo EMAIL; | ||
| 442 | } | ||
| 443 | } | ||
| 444 | } | ||
| 445 | |||
| 446 | print loc(" | ||
| 447 | Your 'email' is now: | ||
| 448 | %1 | ||
| 449 | |||
| 450 | ", $email); | ||
| 451 | |||
| 452 | $conf->set_conf( email => $email ); | ||
| 453 | |||
| 454 | return 1; | ||
| 455 | } | ||
| 456 | |||
| 457 | |||
| 458 | ### commandline programs | ||
| 459 | sub _setup_program { | ||
| 460 | my $self = shift; | ||
| 461 | my $term = $self->term; | ||
| 462 | my $conf = $self->configure_object; | ||
| 463 | |||
| 464 | print loc(" | ||
| 465 | CPANPLUS can use command line utilities to do certain | ||
| 466 | tasks, rather than use perl modules. | ||
| 467 | |||
| 468 | If you wish to use a certain command utility, just enter | ||
| 469 | the full path (or accept the default). If you do not wish | ||
| 470 | to use it, enter a single space. | ||
| 471 | |||
| 472 | Note that the paths you provide should not contain spaces, which is | ||
| 473 | needed to make a distinction between program name and options to that | ||
| 474 | program. For Win32 machines, you can use the short name for a path, | ||
| 475 | like '%1'. | ||
| 476 | ", 'c:\Progra~1\prog.exe' ); | ||
| 477 | |||
| 478 | for my $prog ( sort $conf->options( type => 'program') ) { | ||
| 479 | PROGRAM: { | ||
| 480 | print "\n", loc("Where can I find your '%1' utility? ". | ||
| 481 | "(Enter a single space to disable)", $prog ), "\n"; | ||
| 482 | |||
| 483 | my $loc = $term->get_reply( | ||
| 484 | prompt => "Path to your '$prog'", | ||
| 485 | default => $conf->get_program( $prog ), | ||
| 486 | ); | ||
| 487 | |||
| 488 | ### empty line clears it | ||
| 489 | my $cmd = $loc =~ /^\s*$/ ? undef : $loc; | ||
| 490 | my ($bin) = $cmd =~ /^(\S+)/; | ||
| 491 | |||
| 492 | ### did you provide a valid program ? | ||
| 493 | if( $bin and not can_run( $bin ) ) { | ||
| 494 | print "\n"; | ||
| 495 | print loc("Can not find the binary '%1' in your path!", $bin); | ||
| 496 | redo PROGRAM; | ||
| 497 | } | ||
| 498 | |||
| 499 | ### make is special -- we /need/ it! | ||
| 500 | if( $prog eq 'make' and not $bin ) { | ||
| 501 | print loc( | ||
| 502 | "==> Without your '%1' utility, I can not function! <==", | ||
| 503 | 'make' | ||
| 504 | ); | ||
| 505 | print loc("Please provide one!"); | ||
| 506 | |||
| 507 | ### show win32 where to download | ||
| 508 | if ( $^O eq 'MSWin32' ) { | ||
| 509 | print loc("You can get '%1' from:", NMAKE); | ||
| 510 | print "\t". NMAKE_URL ."\n"; | ||
| 511 | } | ||
| 512 | print "\n"; | ||
| 513 | redo PROGRAM; | ||
| 514 | } | ||
| 515 | |||
| 516 | $conf->set_program( $prog => $cmd ); | ||
| 517 | print $cmd | ||
| 518 | ? loc( "Your '%1' utility has been set to '%2'.", | ||
| 519 | $prog, $cmd ) | ||
| 520 | : loc( "Your '%1' has been disabled.", $prog ); | ||
| 521 | print "\n"; | ||
| 522 | } | ||
| 523 | } | ||
| 524 | |||
| 525 | return 1; | ||
| 526 | } | ||
| 527 | |||
| 528 | sub _setup_installer { | ||
| 529 | my $self = shift; | ||
| 530 | my $term = $self->term; | ||
| 531 | my $conf = $self->configure_object; | ||
| 532 | |||
| 533 | my $none = 'None'; | ||
| 534 | { | ||
| 535 | print loc(" | ||
| 536 | CPANPLUS uses binary programs as well as Perl modules to accomplish | ||
| 537 | various tasks. Normally, CPANPLUS will prefer the use of Perl modules | ||
| 538 | over binary programs. | ||
| 539 | |||
| 540 | You can change this setting by making CPANPLUS prefer the use of | ||
| 541 | certain binary programs if they are available. | ||
| 542 | |||
| 543 | "); | ||
| 544 | |||
| 545 | ### default to using binaries if we don't have compress::zlib only | ||
| 546 | ### -- it'll get very noisy otherwise | ||
| 547 | my $type = 'prefer_bin'; | ||
| 548 | my $yn = $term->ask_yn( | ||
| 549 | prompt => loc("Should I prefer the use of binary programs?"), | ||
| 550 | default => $conf->get_conf( $type ), | ||
| 551 | ); | ||
| 552 | |||
| 553 | print $yn | ||
| 554 | ? loc("Ok, I will prefer to use binary programs if possible.") | ||
| 555 | : loc("Ok, I will prefer to use Perl modules if possible."); | ||
| 556 | print "\n\n"; | ||
| 557 | |||
| 558 | |||
| 559 | $conf->set_conf( $type => $yn ); | ||
| 560 | } | ||
| 561 | |||
| 562 | { | ||
| 563 | print loc(" | ||
| 564 | Makefile.PL is run by perl in a separate process, and accepts various | ||
| 565 | flags that controls the module's installation. For instance, if you | ||
| 566 | would like to install modules to your private user directory, set | ||
| 567 | 'makemakerflags' to: | ||
| 568 | |||
| 569 | LIB=~/perl/lib INSTALLMAN1DIR=~/perl/man/man1 INSTALLMAN3DIR=~/perl/man/man3 | ||
| 570 | |||
| 571 | and be sure that you do NOT set UNINST=1 in 'makeflags' below. | ||
| 572 | |||
| 573 | Enter a name=value list separated by whitespace, but quote any embedded | ||
| 574 | spaces that you want to preserve. (Enter a space to clear any existing | ||
| 575 | settings.) | ||
| 576 | |||
| 577 | If you don't understand this question, just press ENTER. | ||
| 578 | |||
| 579 | "); | ||
| 580 | |||
| 581 | my $type = 'makemakerflags'; | ||
| 582 | my $flags = $term->get_reply( | ||
| 583 | prompt => 'Makefile.PL flags?', | ||
| 584 | default => $conf->get_conf($type), | ||
| 585 | ); | ||
| 586 | |||
| 587 | $flags = '' if $flags eq $none || $flags !~ /\S/; | ||
| 588 | |||
| 589 | print "\n", loc("Your '%1' have been set to:", 'Makefile.PL flags'), | ||
| 590 | "\n ", ( $flags ? $flags : loc('*nothing entered*')), | ||
| 591 | "\n\n"; | ||
| 592 | |||
| 593 | $conf->set_conf( $type => $flags ); | ||
| 594 | } | ||
| 595 | |||
| 596 | { | ||
| 597 | print loc(" | ||
| 598 | Like Makefile.PL, we run 'make' and 'make install' as separate processes. | ||
| 599 | If you have any parameters (e.g. '-j3' in dual processor systems) you want | ||
| 600 | to pass to the calls, please specify them here. | ||
| 601 | |||
| 602 | In particular, 'UNINST=1' is recommended for root users, unless you have | ||
| 603 | fine-tuned ideas of where modules should be installed in the \@INC path. | ||
| 604 | |||
| 605 | Enter a name=value list separated by whitespace, but quote any embedded | ||
| 606 | spaces that you want to preserve. (Enter a space to clear any existing | ||
| 607 | settings.) | ||
| 608 | |||
| 609 | Again, if you don't understand this question, just press ENTER. | ||
| 610 | |||
| 611 | "); | ||
| 612 | my $type = 'makeflags'; | ||
| 613 | my $flags = $term->get_reply( | ||
| 614 | prompt => 'make flags?', | ||
| 615 | default => $conf->get_conf($type), | ||
| 616 | ); | ||
| 617 | |||
| 618 | $flags = '' if $flags eq $none || $flags !~ /\S/; | ||
| 619 | |||
| 620 | print "\n", loc("Your '%1' have been set to:", $type), | ||
| 621 | "\n ", ( $flags ? $flags : loc('*nothing entered*')), | ||
| 622 | "\n\n"; | ||
| 623 | |||
| 624 | $conf->set_conf( $type => $flags ); | ||
| 625 | } | ||
| 626 | |||
| 627 | { | ||
| 628 | print loc(" | ||
| 629 | An alternative to ExtUtils::MakeMaker and Makefile.PL there's a module | ||
| 630 | called Module::Build which uses a Build.PL. | ||
| 631 | |||
| 632 | If you would like to specify any flags to pass when executing the | ||
| 633 | Build.PL (and Build) script, please enter them below. | ||
| 634 | |||
| 635 | For instance, if you would like to install modules to your private | ||
| 636 | user directory, you could enter: | ||
| 637 | |||
| 638 | install_base=/my/private/path | ||
| 639 | |||
| 640 | Or to uninstall old copies of modules before updating, you might | ||
| 641 | want to enter: | ||
| 642 | |||
| 643 | uninst=1 | ||
| 644 | |||
| 645 | Again, if you don't understand this question, just press ENTER. | ||
| 646 | |||
| 647 | "); | ||
| 648 | |||
| 649 | my $type = 'buildflags'; | ||
| 650 | my $flags = $term->get_reply( | ||
| 651 | prompt => 'Build.PL and Build flags?', | ||
| 652 | default => $conf->get_conf($type), | ||
| 653 | ); | ||
| 654 | |||
| 655 | $flags = '' if $flags eq $none || $flags !~ /\S/; | ||
| 656 | |||
| 657 | print "\n", loc("Your '%1' have been set to:", | ||
| 658 | 'Build.PL and Build flags'), | ||
| 659 | "\n ", ( $flags ? $flags : loc('*nothing entered*')), | ||
| 660 | "\n\n"; | ||
| 661 | |||
| 662 | $conf->set_conf( $type => $flags ); | ||
| 663 | } | ||
| 664 | |||
| 665 | ### use EU::MM or module::build? ### | ||
| 666 | { | ||
| 667 | print loc(" | ||
| 668 | Some modules provide both a Build.PL (Module::Build) and a Makefile.PL | ||
| 669 | (ExtUtils::MakeMaker). By default, CPANPLUS prefers Makefile.PL. | ||
| 670 | |||
| 671 | Module::Build support is not bundled standard with CPANPLUS, but | ||
| 672 | requires you to install 'CPANPLUS::Dist::Build' from CPAN. | ||
| 673 | |||
| 674 | Although Module::Build is a pure perl solution, which means you will | ||
| 675 | not need a 'make' binary, it does have some limitations. The most | ||
| 676 | important is that CPANPLUS is unable to uninstall any modules installed | ||
| 677 | by Module::Build. | ||
| 678 | |||
| 679 | Again, if you don't understand this question, just press ENTER. | ||
| 680 | |||
| 681 | "); | ||
| 682 | my $type = 'prefer_makefile'; | ||
| 683 | my $yn = $term->ask_yn( | ||
| 684 | prompt => loc("Prefer Makefile.PL over Build.PL?"), | ||
| 685 | default => $conf->get_conf($type), | ||
| 686 | ); | ||
| 687 | |||
| 688 | $conf->set_conf( $type => $yn ); | ||
| 689 | } | ||
| 690 | |||
| 691 | { | ||
| 692 | print loc(' | ||
| 693 | If you like, CPANPLUS can add extra directories to your @INC list during | ||
| 694 | startup. These will just be used by CPANPLUS and will not change your | ||
| 695 | external environment or perl interpreter. Enter a space separated list of | ||
| 696 | pathnames to be added to your @INC, quoting any with embedded whitespace. | ||
| 697 | (To clear the current value enter a single space.) | ||
| 698 | |||
| 699 | '); | ||
| 700 | |||
| 701 | my $type = 'lib'; | ||
| 702 | my $flags = $term->get_reply( | ||
| 703 | prompt => loc('Additional @INC directories to add?'), | ||
| 704 | default => (join " ", @{$conf->get_conf($type) || []} ), | ||
| 705 | ); | ||
| 706 | |||
| 707 | my $lib; | ||
| 708 | unless( $flags =~ /\S/ ) { | ||
| 709 | $lib = []; | ||
| 710 | } else { | ||
| 711 | (@$lib) = $flags =~ m/\s*("[^"]+"|'[^']+'|[^\s]+)/g; | ||
| 712 | } | ||
| 713 | |||
| 714 | print "\n", loc("Your additional libs are now:"), "\n"; | ||
| 715 | |||
| 716 | print scalar @$lib | ||
| 717 | ? map { " $_\n" } @$lib | ||
| 718 | : " ", loc("*nothing entered*"), "\n"; | ||
| 719 | print "\n\n"; | ||
| 720 | |||
| 721 | $conf->set_conf( $type => $lib ); | ||
| 722 | } | ||
| 723 | |||
| 724 | return 1; | ||
| 725 | } | ||
| 726 | |||
| 727 | |||
| 728 | sub _setup_conf { | ||
| 729 | my $self = shift; | ||
| 730 | my $term = $self->term; | ||
| 731 | my $conf = $self->configure_object; | ||
| 732 | |||
| 733 | my $none = 'None'; | ||
| 734 | { | ||
| 735 | ############ | ||
| 736 | ## noisy? ## | ||
| 737 | ############ | ||
| 738 | |||
| 739 | print loc(" | ||
| 740 | In normal operation I can just give you basic information about what I | ||
| 741 | am doing, or I can be more verbose and give you every little detail. | ||
| 742 | |||
| 743 | "); | ||
| 744 | |||
| 745 | my $type = 'verbose'; | ||
| 746 | my $yn = $term->ask_yn( | ||
| 747 | prompt => loc("Should I be verbose?"), | ||
| 748 | default => $conf->get_conf( $type ), ); | ||
| 749 | |||
| 750 | print "\n"; | ||
| 751 | print $yn | ||
| 752 | ? loc("You asked for it!") | ||
| 753 | : loc("I'll try to be quiet"); | ||
| 754 | |||
| 755 | $conf->set_conf( $type => $yn ); | ||
| 756 | } | ||
| 757 | |||
| 758 | { | ||
| 759 | ####################### | ||
| 760 | ## flush you animal! ## | ||
| 761 | ####################### | ||
| 762 | |||
| 763 | print loc(" | ||
| 764 | In the interest of speed, we keep track of what modules were installed | ||
| 765 | successfully and which failed in the current session. We can flush this | ||
| 766 | data automatically, or you can explicitly issue a 'flush' when you want | ||
| 767 | to purge it. | ||
| 768 | |||
| 769 | "); | ||
| 770 | |||
| 771 | my $type = 'flush'; | ||
| 772 | my $yn = $term->ask_yn( | ||
| 773 | prompt => loc("Flush automatically?"), | ||
| 774 | default => $conf->get_conf( $type ), | ||
| 775 | ); | ||
| 776 | |||
| 777 | print "\n"; | ||
| 778 | print $yn | ||
| 779 | ? loc("I'll flush after every full module install.") | ||
| 780 | : loc("I won't flush until you tell me to."); | ||
| 781 | |||
| 782 | $conf->set_conf( $type => $yn ); | ||
| 783 | } | ||
| 784 | |||
| 785 | { | ||
| 786 | ##################### | ||
| 787 | ## force installs? ## | ||
| 788 | ##################### | ||
| 789 | |||
| 790 | print loc(" | ||
| 791 | Usually, when a test fails, I won't install the module, but if you | ||
| 792 | prefer, I can force the install anyway. | ||
| 793 | |||
| 794 | "); | ||
| 795 | |||
| 796 | my $type = 'force'; | ||
| 797 | my $yn = $term->ask_yn( | ||
| 798 | prompt => loc("Force installs?"), | ||
| 799 | default => $conf->get_conf( $type ), | ||
| 800 | ); | ||
| 801 | |||
| 802 | print "\n"; | ||
| 803 | print $yn | ||
| 804 | ? loc("I will force installs.") | ||
| 805 | : loc("I won't force installs."); | ||
| 806 | |||
| 807 | $conf->set_conf( $type => $yn ); | ||
| 808 | } | ||
| 809 | |||
| 810 | { | ||
| 811 | ################### | ||
| 812 | ## about prereqs ## | ||
| 813 | ################### | ||
| 814 | |||
| 815 | print loc(" | ||
| 816 | Sometimes a module will require other modules to be installed before it | ||
| 817 | will work. CPANPLUS can attempt to install these for you automatically | ||
| 818 | if you like, or you can do the deed yourself. | ||
| 819 | |||
| 820 | If you would prefer that we NEVER try to install extra modules | ||
| 821 | automatically, select NO. (Usually you will want this set to YES.) | ||
| 822 | |||
| 823 | If you would like to build modules to satisfy testing or prerequisites, | ||
| 824 | but not actually install them, select BUILD. | ||
| 825 | |||
| 826 | NOTE: This feature requires you to flush the 'lib' cache for longer | ||
| 827 | running programs (refer to the CPANPLUS::Backend documentations for | ||
| 828 | more details). | ||
| 829 | |||
| 830 | Otherwise, select ASK to have us ask your permission to install them. | ||
| 831 | |||
| 832 | "); | ||
| 833 | |||
| 834 | my $type = 'prereqs'; | ||
| 835 | |||
| 836 | my @map = ( | ||
| 837 | [ PREREQ_IGNORE, # conf value | ||
| 838 | loc('No, do not install prerequisites'), # UI Value | ||
| 839 | loc("I won't install prerequisites") # diag message | ||
| 840 | ], | ||
| 841 | [ PREREQ_INSTALL, | ||
| 842 | loc('Yes, please install prerequisites'), | ||
| 843 | loc("I will install prerequisites") | ||
| 844 | ], | ||
| 845 | [ PREREQ_ASK, | ||
| 846 | loc('Ask me before installing a prerequisite'), | ||
| 847 | loc("I will ask permission to install") | ||
| 848 | ], | ||
| 849 | [ PREREQ_BUILD, | ||
| 850 | loc('Build prerequisites, but do not install them'), | ||
| 851 | loc( "I will only build, but not install prerequisites" ) | ||
| 852 | ], | ||
| 853 | ); | ||
| 854 | |||
| 855 | my %reply = map { $_->[1] => $_->[0] } @map; # choice => value | ||
| 856 | my %diag = map { $_->[1] => $_->[2] } @map; # choice => diag message | ||
| 857 | my %conf = map { $_->[0] => $_->[1] } @map; # value => ui choice | ||
| 858 | |||
| 859 | my $reply = $term->get_reply( | ||
| 860 | prompt => loc('Follow prerequisites?'), | ||
| 861 | default => $conf{ $conf->get_conf( $type ) }, | ||
| 862 | choices => [ @conf{ sort keys %conf } ], | ||
| 863 | ); | ||
| 864 | print "\n"; | ||
| 865 | |||
| 866 | my $value = $reply{ $reply }; | ||
| 867 | my $diag = $diag{ $reply }; | ||
| 868 | |||
| 869 | $conf->set_conf( $type => $value ); | ||
| 870 | print $diag, "\n"; | ||
| 871 | } | ||
| 872 | |||
| 873 | { print loc(" | ||
| 874 | Modules in the CPAN archives are protected with md5 checksums. | ||
| 875 | |||
| 876 | This requires the Perl module Digest::MD5 to be installed (which | ||
| 877 | CPANPLUS can do for you later); | ||
| 878 | |||
| 879 | "); | ||
| 880 | my $type = 'md5'; | ||
| 881 | |||
| 882 | my $yn = $term->ask_yn( | ||
| 883 | prompt => loc("Shall I use the MD5 checksums?"), | ||
| 884 | default => $conf->get_conf( $type ), | ||
| 885 | ); | ||
| 886 | |||
| 887 | print $yn | ||
| 888 | ? loc("I will use the MD5 checksums if you have it") | ||
| 889 | : loc("I won't use the MD5 checksums"); | ||
| 890 | |||
| 891 | $conf->set_conf( $type => $yn ); | ||
| 892 | |||
| 893 | } | ||
| 894 | |||
| 895 | |||
| 896 | { ########################################### | ||
| 897 | ## sally sells seashells by the seashore ## | ||
| 898 | ########################################### | ||
| 899 | |||
| 900 | print loc(" | ||
| 901 | By default CPANPLUS uses its own shell when invoked. If you would prefer | ||
| 902 | a different shell, such as one you have written or otherwise acquired, | ||
| 903 | please enter the full name for your shell module. | ||
| 904 | |||
| 905 | "); | ||
| 906 | |||
| 907 | my $type = 'shell'; | ||
| 908 | my $other = 'Other'; | ||
| 909 | my @choices = (qw| CPANPLUS::Shell::Default | ||
| 910 | CPANPLUS::Shell::Classic |, | ||
| 911 | $other ); | ||
| 912 | my $default = $conf->get_conf($type); | ||
| 913 | |||
| 914 | unshift @choices, $default unless grep { $_ eq $default } @choices; | ||
| 915 | |||
| 916 | my $reply = $term->get_reply( | ||
| 917 | prompt => loc('Which CPANPLUS shell do you want to use?'), | ||
| 918 | default => $default, | ||
| 919 | choices => \@choices, | ||
| 920 | ); | ||
| 921 | |||
| 922 | if( $reply eq $other ) { | ||
| 923 | SHELL: { | ||
| 924 | $reply = $term->get_reply( | ||
| 925 | prompt => loc( 'Please enter the name of the shell '. | ||
| 926 | 'you wish to use: '), | ||
| 927 | ); | ||
| 928 | |||
| 929 | unless( check_install( module => $reply ) ) { | ||
| 930 | print "\n", | ||
| 931 | loc("Could not find '$reply' in your path " . | ||
| 932 | "-- please try again"), | ||
| 933 | "\n"; | ||
| 934 | redo SHELL; | ||
| 935 | } | ||
| 936 | } | ||
| 937 | } | ||
| 938 | |||
| 939 | print "\n", loc("Your shell is now: %1", $reply), "\n\n"; | ||
| 940 | |||
| 941 | $conf->set_conf( $type => $reply ); | ||
| 942 | } | ||
| 943 | |||
| 944 | { | ||
| 945 | ################### | ||
| 946 | ## use storable? ## | ||
| 947 | ################### | ||
| 948 | |||
| 949 | print loc(" | ||
| 950 | To speed up the start time of CPANPLUS, and maintain a cache over | ||
| 951 | multiple runs, we can use Storable to freeze some information. | ||
| 952 | Would you like to do this? | ||
| 953 | |||
| 954 | "); | ||
| 955 | my $type = 'storable'; | ||
| 956 | my $yn = $term->ask_yn( | ||
| 957 | prompt => loc("Use Storable?"), | ||
| 958 | default => $conf->get_conf( $type ) ? 1 : 0, | ||
| 959 | ); | ||
| 960 | print "\n"; | ||
| 961 | print $yn | ||
| 962 | ? loc("I will use Storable if you have it") | ||
| 963 | : loc("I will not use Storable"); | ||
| 964 | |||
| 965 | $conf->set_conf( $type => $yn ); | ||
| 966 | } | ||
| 967 | |||
| 968 | { | ||
| 969 | ################### | ||
| 970 | ## use sqlite ? ## | ||
| 971 | ################### | ||
| 972 | |||
| 973 | print loc(" | ||
| 974 | |||
| 975 | To limit the amount of RAM used by CPANPLUS, you can use the SQLite | ||
| 976 | source backend instead. Note that it is currently still experimental. | ||
| 977 | Would you like to do this? | ||
| 978 | |||
| 979 | "); | ||
| 980 | my $type = 'source_engine'; | ||
| 981 | my $class = 'CPANPLUS::Internals::Source::SQLite'; | ||
| 982 | my $yn = $term->ask_yn( | ||
| 983 | prompt => loc("Use SQLite?"), | ||
| 984 | default => $conf->get_conf( $type ) eq $class ? 1 : 0, | ||
| 985 | ); | ||
| 986 | print "\n"; | ||
| 987 | print $yn | ||
| 988 | ? loc("I will use SQLite") | ||
| 989 | : loc("I will not use SQLite"); | ||
| 990 | |||
| 991 | $conf->set_conf( $type => $class ); | ||
| 992 | } | ||
| 993 | |||
| 994 | { | ||
| 995 | ################### | ||
| 996 | ## use cpantest? ## | ||
| 997 | ################### | ||
| 998 | |||
| 999 | print loc(" | ||
| 1000 | CPANPLUS has support for the Test::Reporter module, which can be utilized | ||
| 1001 | to report success and failures of modules installed by CPANPLUS. Would | ||
| 1002 | you like to do this? Note that you will still be prompted before | ||
| 1003 | sending each report. | ||
| 1004 | |||
| 1005 | If you don't have all the required modules installed yet, you should | ||
| 1006 | consider installing '%1' | ||
| 1007 | |||
| 1008 | This package bundles all the required modules to enable test reporting | ||
| 1009 | and querying from CPANPLUS. | ||
| 1010 | You can do so straight after this installation. | ||
| 1011 | |||
| 1012 | ", 'Bundle::CPANPLUS::Test::Reporter'); | ||
| 1013 | |||
| 1014 | my $type = 'cpantest'; | ||
| 1015 | my $yn = $term->ask_yn( | ||
| 1016 | prompt => loc('Report test results?'), | ||
| 1017 | default => $conf->get_conf( $type ) ? 1 : 0, | ||
| 1018 | ); | ||
| 1019 | |||
| 1020 | print "\n"; | ||
| 1021 | print $yn | ||
| 1022 | ? loc("I will prompt you to report test results") | ||
| 1023 | : loc("I won't prompt you to report test results"); | ||
| 1024 | |||
| 1025 | $conf->set_conf( $type => $yn ); | ||
| 1026 | } | ||
| 1027 | |||
| 1028 | { | ||
| 1029 | ################################### | ||
| 1030 | ## use cryptographic signatures? ## | ||
| 1031 | ################################### | ||
| 1032 | |||
| 1033 | print loc(" | ||
| 1034 | The Module::Signature extension allows CPAN authors to sign their | ||
| 1035 | distributions using PGP signatures. Would you like to check for | ||
| 1036 | module's cryptographic integrity before attempting to install them? | ||
| 1037 | Note that this requires either the 'gpg' utility or Crypt::OpenPGP | ||
| 1038 | to be installed. | ||
| 1039 | |||
| 1040 | "); | ||
| 1041 | my $type = 'signature'; | ||
| 1042 | |||
| 1043 | my $yn = $term->ask_yn( | ||
| 1044 | prompt => loc('Shall I check module signatures?'), | ||
| 1045 | default => $conf->get_conf($type) ? 1 : 0, | ||
| 1046 | ); | ||
| 1047 | |||
| 1048 | print "\n"; | ||
| 1049 | print $yn | ||
| 1050 | ? loc("Ok, I will attempt to check module signatures.") | ||
| 1051 | : loc("Ok, I won't attempt to check module signatures."); | ||
| 1052 | |||
| 1053 | $conf->set_conf( $type => $yn ); | ||
| 1054 | } | ||
| 1055 | |||
| 1056 | return 1; | ||
| 1057 | } | ||
| 1058 | |||
| 1059 | sub _setup_hosts { | ||
| 1060 | my $self = shift; | ||
| 1061 | my $term = $self->term; | ||
| 1062 | my $conf = $self->configure_object; | ||
| 1063 | |||
| 1064 | |||
| 1065 | if( scalar @{ $conf->get_conf('hosts') } ) { | ||
| 1066 | |||
| 1067 | my $hosts; | ||
| 1068 | for my $href ( @{$conf->get_conf('hosts')} ) { | ||
| 1069 | $hosts .= "\t$href->{scheme}://$href->{host}$href->{path}\n"; | ||
| 1070 | } | ||
| 1071 | |||
| 1072 | print loc(" | ||
| 1073 | I see you already have some hosts selected: | ||
| 1074 | |||
| 1075 | $hosts | ||
| 1076 | |||
| 1077 | If you'd like to stick with your current settings, just select 'Yes'. | ||
| 1078 | Otherwise, select 'No' and you can reconfigure your hosts | ||
| 1079 | |||
| 1080 | "); | ||
| 1081 | my $yn = $term->ask_yn( | ||
| 1082 | prompt => loc("Would you like to keep your current hosts?"), | ||
| 1083 | default => 'y', | ||
| 1084 | ); | ||
| 1085 | return 1 if $yn; | ||
| 1086 | } | ||
| 1087 | |||
| 1088 | my @hosts; | ||
| 1089 | MAIN: { | ||
| 1090 | |||
| 1091 | print loc(" | ||
| 1092 | Now we need to know where your favorite CPAN sites are located. Make a | ||
| 1093 | list of a few sites (just in case the first on the array won't work). | ||
| 1094 | |||
| 1095 | If you are mirroring CPAN to your local workstation, specify a file: | ||
| 1096 | URI by picking the CUSTOM option. | ||
| 1097 | |||
| 1098 | Otherwise, let us fetch the official CPAN mirror list and you can pick | ||
| 1099 | the mirror that suits you best from a list by using the MIRROR option; | ||
| 1100 | First, pick a nearby continent and country. Then, you will be presented | ||
| 1101 | with a list of URLs of CPAN mirrors in the country you selected. Select | ||
| 1102 | one or more of those URLs. | ||
| 1103 | |||
| 1104 | Note, the latter option requires a working net connection. | ||
| 1105 | |||
| 1106 | You can select VIEW to see your current selection and QUIT when you | ||
| 1107 | are done. | ||
| 1108 | |||
| 1109 | "); | ||
| 1110 | |||
| 1111 | my $reply = $term->get_reply( | ||
| 1112 | prompt => loc('Please choose an option'), | ||
| 1113 | choices => [qw|Mirror Custom View Quit|], | ||
| 1114 | default => 'Mirror', | ||
| 1115 | ); | ||
| 1116 | |||
| 1117 | goto MIRROR if $reply eq 'Mirror'; | ||
| 1118 | goto CUSTOM if $reply eq 'Custom'; | ||
| 1119 | goto QUIT if $reply eq 'Quit'; | ||
| 1120 | |||
| 1121 | $self->_view_hosts(@hosts) if $reply eq 'View'; | ||
| 1122 | redo MAIN; | ||
| 1123 | } | ||
| 1124 | |||
| 1125 | my $mirror_file; | ||
| 1126 | my $hosts; | ||
| 1127 | MIRROR: { | ||
| 1128 | $mirror_file ||= $self->_get_mirrored_by or return; | ||
| 1129 | $hosts ||= $self->_parse_mirrored_by($mirror_file) or return; | ||
| 1130 | |||
| 1131 | my ($continent, $country, $host) = $self->_guess_from_timezone( $hosts ); | ||
| 1132 | |||
| 1133 | CONTINENT: { | ||
| 1134 | my %seen; | ||
| 1135 | my @choices = sort map { | ||
| 1136 | $_->{'continent'} | ||
| 1137 | } grep { | ||
| 1138 | not $seen{$_->{'continent'}}++ | ||
| 1139 | } values %$hosts; | ||
| 1140 | push @choices, qw[Custom Up Quit]; | ||
| 1141 | |||
| 1142 | my $reply = $term->get_reply( | ||
| 1143 | prompt => loc('Pick a continent'), | ||
| 1144 | default => $continent, | ||
| 1145 | choices => \@choices, | ||
| 1146 | ); | ||
| 1147 | |||
| 1148 | goto MAIN if $reply eq 'Up'; | ||
| 1149 | goto CUSTOM if $reply eq 'Custom'; | ||
| 1150 | goto QUIT if $reply eq 'Quit'; | ||
| 1151 | |||
| 1152 | $continent = $reply; | ||
| 1153 | } | ||
| 1154 | |||
| 1155 | COUNTRY: { | ||
| 1156 | my %seen; | ||
| 1157 | my @choices = sort map { | ||
| 1158 | $_->{'country'} | ||
| 1159 | } grep { | ||
| 1160 | not $seen{$_->{'country'}}++ | ||
| 1161 | } grep { | ||
| 1162 | ($_->{'continent'} eq $continent) | ||
| 1163 | } values %$hosts; | ||
| 1164 | push @choices, qw[Custom Up Quit]; | ||
| 1165 | |||
| 1166 | my $reply = $term->get_reply( | ||
| 1167 | prompt => loc('Pick a country'), | ||
| 1168 | default => $country, | ||
| 1169 | choices => \@choices, | ||
| 1170 | ); | ||
| 1171 | |||
| 1172 | goto CONTINENT if $reply eq 'Up'; | ||
| 1173 | goto CUSTOM if $reply eq 'Custom'; | ||
| 1174 | goto QUIT if $reply eq 'Quit'; | ||
| 1175 | |||
| 1176 | $country = $reply; | ||
| 1177 | } | ||
| 1178 | |||
| 1179 | HOST: { | ||
| 1180 | my @list = grep { | ||
| 1181 | $_->{'continent'} eq $continent and | ||
| 1182 | $_->{'country'} eq $country | ||
| 1183 | } values %$hosts; | ||
| 1184 | |||
| 1185 | my %map; my $default; | ||
| 1186 | for my $href (@list) { | ||
| 1187 | for my $con ( @{$href->{'connections'}} ) { | ||
| 1188 | next unless length $con->{'host'}; | ||
| 1189 | |||
| 1190 | my $entry = $con->{'scheme'} . '://' . $con->{'host'}; | ||
| 1191 | $default = $entry if $con->{'host'} eq $host; | ||
| 1192 | |||
| 1193 | $map{$entry} = $con; | ||
| 1194 | } | ||
| 1195 | } | ||
| 1196 | |||
| 1197 | CHOICE: { | ||
| 1198 | |||
| 1199 | ### doesn't play nice with Term::UI :( | ||
| 1200 | ### should make t::ui figure out pager opens | ||
| 1201 | #$self->_pager_open; # host lists might be long | ||
| 1202 | |||
| 1203 | print loc(" | ||
| 1204 | You can enter multiple sites by separating them by a space. | ||
| 1205 | For example: | ||
| 1206 | 1 4 2 5 | ||
| 1207 | "); | ||
| 1208 | |||
| 1209 | my @reply = $term->get_reply( | ||
| 1210 | prompt => loc('Please pick a site: '), | ||
| 1211 | choices => [sort(keys %map), | ||
| 1212 | qw|Custom View Up Quit|], | ||
| 1213 | default => $default, | ||
| 1214 | multi => 1, | ||
| 1215 | ); | ||
| 1216 | #$self->_pager_close; | ||
| 1217 | |||
| 1218 | |||
| 1219 | goto COUNTRY if grep { $_ eq 'Up' } @reply; | ||
| 1220 | goto CUSTOM if grep { $_ eq 'Custom' } @reply; | ||
| 1221 | goto QUIT if grep { $_ eq 'Quit' } @reply; | ||
| 1222 | |||
| 1223 | ### add the host, but only if it's not on the stack already ### | ||
| 1224 | unless( grep { $_ eq 'View' } @reply ) { | ||
| 1225 | for my $reply (@reply) { | ||
| 1226 | if( grep { $_ eq $map{$reply} } @hosts ) { | ||
| 1227 | print loc("Host '%1' already selected", $reply); | ||
| 1228 | print "\n\n"; | ||
| 1229 | } else { | ||
| 1230 | push @hosts, $map{$reply} | ||
| 1231 | } | ||
| 1232 | } | ||
| 1233 | } | ||
| 1234 | |||
| 1235 | $self->_view_hosts(@hosts); | ||
| 1236 | |||
| 1237 | goto QUIT if $self->autoreply; | ||
| 1238 | redo CHOICE; | ||
| 1239 | } | ||
| 1240 | } | ||
| 1241 | } | ||
| 1242 | |||
| 1243 | CUSTOM: { | ||
| 1244 | print loc(" | ||
| 1245 | If there are any additional URLs you would like to use, please add them | ||
| 1246 | now. You may enter them separately or as a space delimited list. | ||
| 1247 | |||
| 1248 | We provide a default fall-back URL, but you are welcome to override it | ||
| 1249 | with e.g. 'http://www.cpan.org/' if LWP, wget or curl is installed. | ||
| 1250 | |||
| 1251 | (Enter a single space when you are done, or to simply skip this step.) | ||
| 1252 | |||
| 1253 | Note that if you want to use a local depository, you will have to enter | ||
| 1254 | as follows: | ||
| 1255 | |||
| 1256 | file://server/path/to/cpan | ||
| 1257 | |||
| 1258 | if the file is on a server on your local network or as: | ||
| 1259 | |||
| 1260 | file:///path/to/cpan | ||
| 1261 | |||
| 1262 | if the file is on your local disk. Note the three /// after the file: bit | ||
| 1263 | |||
| 1264 | "); | ||
| 1265 | |||
| 1266 | CHOICE: { | ||
| 1267 | my $reply = $term->get_reply( | ||
| 1268 | prompt => loc("Additionals host(s) to add: "), | ||
| 1269 | default => '', | ||
| 1270 | ); | ||
| 1271 | |||
| 1272 | last CHOICE unless $reply =~ /\S/; | ||
| 1273 | |||
| 1274 | my $href = $self->_parse_host($reply); | ||
| 1275 | |||
| 1276 | if( $href ) { | ||
| 1277 | push @hosts, $href | ||
| 1278 | unless grep { | ||
| 1279 | $href->{'scheme'} eq $_->{'scheme'} and | ||
| 1280 | $href->{'host'} eq $_->{'host'} and | ||
| 1281 | $href->{'path'} eq $_->{'path'} | ||
| 1282 | } @hosts; | ||
| 1283 | |||
| 1284 | last CHOICE if $self->autoreply; | ||
| 1285 | } else { | ||
| 1286 | print loc("Invalid uri! Please try again!"); | ||
| 1287 | } | ||
| 1288 | |||
| 1289 | $self->_view_hosts(@hosts); | ||
| 1290 | |||
| 1291 | redo CHOICE; | ||
| 1292 | } | ||
| 1293 | |||
| 1294 | DONE: { | ||
| 1295 | |||
| 1296 | print loc(" | ||
| 1297 | Where would you like to go now? | ||
| 1298 | |||
| 1299 | Please pick one of the following options or Quit when you are done | ||
| 1300 | |||
| 1301 | "); | ||
| 1302 | my $answer = $term->get_reply( | ||
| 1303 | prompt => loc("Where to now?"), | ||
| 1304 | default => 'Quit', | ||
| 1305 | choices => [qw|Mirror Custom View Quit|], | ||
| 1306 | ); | ||
| 1307 | |||
| 1308 | if( $answer eq 'View' ) { | ||
| 1309 | $self->_view_hosts(@hosts); | ||
| 1310 | redo DONE; | ||
| 1311 | } | ||
| 1312 | |||
| 1313 | goto MIRROR if $answer eq 'Mirror'; | ||
| 1314 | goto CUSTOM if $answer eq 'Custom'; | ||
| 1315 | goto QUIT if $answer eq 'Quit'; | ||
| 1316 | } | ||
| 1317 | } | ||
| 1318 | |||
| 1319 | QUIT: { | ||
| 1320 | $conf->set_conf( hosts => \@hosts ); | ||
| 1321 | |||
| 1322 | print loc(" | ||
| 1323 | Your host configuration has been saved | ||
| 1324 | |||
| 1325 | "); | ||
| 1326 | } | ||
| 1327 | |||
| 1328 | return 1; | ||
| 1329 | } | ||
| 1330 | |||
| 1331 | sub _view_hosts { | ||
| 1332 | my $self = shift; | ||
| 1333 | my @hosts = @_; | ||
| 1334 | |||
| 1335 | print "\n\n"; | ||
| 1336 | |||
| 1337 | if( scalar @hosts ) { | ||
| 1338 | my $i = 1; | ||
| 1339 | for my $host (@hosts) { | ||
| 1340 | |||
| 1341 | ### show full path on file uris, otherwise, just show host | ||
| 1342 | my $path = join '', ( | ||
| 1343 | $host->{'scheme'} eq 'file' | ||
| 1344 | ? ( ($host->{'host'} || '[localhost]'), | ||
| 1345 | $host->{path} ) | ||
| 1346 | : $host->{'host'} | ||
| 1347 | ); | ||
| 1348 | |||
| 1349 | printf "%-40s %30s\n", | ||
| 1350 | loc("Selected %1",$host->{'scheme'} . '://' . $path ), | ||
| 1351 | loc("%quant(%2,host) selected thus far.", $i); | ||
| 1352 | $i++; | ||
| 1353 | } | ||
| 1354 | } else { | ||
| 1355 | print loc("No hosts selected so far."); | ||
| 1356 | } | ||
| 1357 | |||
| 1358 | print "\n\n"; | ||
| 1359 | |||
| 1360 | return 1; | ||
| 1361 | } | ||
| 1362 | |||
| 1363 | sub _get_mirrored_by { | ||
| 1364 | my $self = shift; | ||
| 1365 | my $cpan = $self->backend; | ||
| 1366 | my $conf = $self->configure_object; | ||
| 1367 | |||
| 1368 | print loc(" | ||
| 1369 | Now, we are going to fetch the mirror list for first-time configurations. | ||
| 1370 | This may take a while... | ||
| 1371 | |||
| 1372 | "); | ||
| 1373 | |||
| 1374 | ### use the new configuration ### | ||
| 1375 | $cpan->configure_object( $conf ); | ||
| 1376 | |||
| 1377 | load CPANPLUS::Module::Fake; | ||
| 1378 | load CPANPLUS::Module::Author::Fake; | ||
| 1379 | |||
| 1380 | my $mb = CPANPLUS::Module::Fake->new( | ||
| 1381 | module => $conf->_get_source('hosts'), | ||
| 1382 | path => '', | ||
| 1383 | package => $conf->_get_source('hosts'), | ||
| 1384 | author => CPANPLUS::Module::Author::Fake->new( | ||
| 1385 | _id => $cpan->_id ), | ||
| 1386 | _id => $cpan->_id, | ||
| 1387 | ); | ||
| 1388 | |||
| 1389 | my $file = $cpan->_fetch( fetchdir => $conf->get_conf('base'), | ||
| 1390 | module => $mb ); | ||
| 1391 | |||
| 1392 | return $file if $file; | ||
| 1393 | return; | ||
| 1394 | } | ||
| 1395 | |||
| 1396 | sub _parse_mirrored_by { | ||
| 1397 | my $self = shift; | ||
| 1398 | my $file = shift; | ||
| 1399 | |||
| 1400 | -s $file or return; | ||
| 1401 | |||
| 1402 | my $fh = new FileHandle; | ||
| 1403 | $fh->open("$file") | ||
| 1404 | or ( | ||
| 1405 | warn(loc('Could not open file "%1": %2', $file, $!)), | ||
| 1406 | return | ||
| 1407 | ); | ||
| 1408 | |||
| 1409 | ### slurp the file in ### | ||
| 1410 | { local $/; $file = <$fh> } | ||
| 1411 | |||
| 1412 | ### remove comments ### | ||
| 1413 | $file =~ s/#.*$//gm; | ||
| 1414 | |||
| 1415 | $fh->close; | ||
| 1416 | |||
| 1417 | ### sample host entry ### | ||
| 1418 | # ftp.sun.ac.za: | ||
| 1419 | # frequency = "daily" | ||
| 1420 | # dst_ftp = "ftp://ftp.sun.ac.za/CPAN/CPAN/" | ||
| 1421 | # dst_location = "Stellenbosch, South Africa, Africa (-26.1992 28.0564)" | ||
| 1422 | # dst_organisation = "University of Stellenbosch" | ||
| 1423 | # dst_timezone = "+2" | ||
| 1424 | # dst_contact = "ftpadm@ftp.sun.ac.za" | ||
| 1425 | # dst_src = "ftp.funet.fi" | ||
| 1426 | # | ||
| 1427 | # # dst_dst = "ftp://ftp.sun.ac.za/CPAN/CPAN/" | ||
| 1428 | # # dst_contact = "mailto:ftpadm@ftp.sun.ac.za | ||
| 1429 | # # dst_src = "ftp.funet.fi" | ||
| 1430 | |||
| 1431 | ### host name as key, rest of the entry as value ### | ||
| 1432 | my %hosts = $file =~ m/([a-zA-Z0-9\-\.]+):\s+((?:\w+\s+=\s+".*?"\s+)+)/gs; | ||
| 1433 | |||
| 1434 | while (my($host,$data) = each %hosts) { | ||
| 1435 | |||
| 1436 | my $href; | ||
| 1437 | map { | ||
| 1438 | s/^\s*//; | ||
| 1439 | my @a = split /\s*=\s*/; | ||
| 1440 | $a[1] =~ s/^"(.+?)"$/$1/g; | ||
| 1441 | $href->{ pop @a } = pop @a; | ||
| 1442 | } grep /\S/, split /\n/, $data; | ||
| 1443 | |||
| 1444 | ($href->{city_area}, $href->{country}, $href->{continent}, | ||
| 1445 | $href->{latitude}, $href->{longitude} ) = | ||
| 1446 | $href->{dst_location} =~ | ||
| 1447 | m/ | ||
| 1448 | #Aizu-Wakamatsu, Tohoku-chiho, Fukushima | ||
| 1449 | ^"?( | ||
| 1450 | (?:[^,]+?)\s* # city | ||
| 1451 | (?: | ||
| 1452 | (?:,\s*[^,]+?)\s* # optional area | ||
| 1453 | )*? # some have multiple areas listed | ||
| 1454 | ) | ||
| 1455 | |||
| 1456 | #Japan | ||
| 1457 | ,\s*([^,]+?)\s* # country | ||
| 1458 | |||
| 1459 | #Asia | ||
| 1460 | ,\s*([^,]+?)\s* # continent | ||
| 1461 | |||
| 1462 | # (37.4333 139.9821) | ||
| 1463 | \((\S+)\s+(\S+?)\)"?$ # (latitude longitude) | ||
| 1464 | /sx; | ||
| 1465 | |||
| 1466 | ### parse the different hosts, store them in config format ### | ||
| 1467 | my @list; | ||
| 1468 | |||
| 1469 | for my $type (qw[dst_ftp dst_rsync dst_http]) { | ||
| 1470 | my $path = $href->{$type}; | ||
| 1471 | next unless $path =~ /\w/; | ||
| 1472 | if ($type eq 'dst_rsync' && $path !~ /^rsync:/) { | ||
| 1473 | $path =~ s{::}{/}; | ||
| 1474 | $path = "rsync://$path/"; | ||
| 1475 | } | ||
| 1476 | my $parts = $self->_parse_host($path); | ||
| 1477 | push @list, $parts; | ||
| 1478 | } | ||
| 1479 | |||
| 1480 | $href->{connections} = \@list; | ||
| 1481 | $hosts{$host} = $href; | ||
| 1482 | } | ||
| 1483 | |||
| 1484 | return \%hosts; | ||
| 1485 | } | ||
| 1486 | |||
| 1487 | sub _parse_host { | ||
| 1488 | my $self = shift; | ||
| 1489 | my $host = shift; | ||
| 1490 | |||
| 1491 | my @parts = $host =~ m|^(\w*)://([^/]*)(/.*)$|s; | ||
| 1492 | |||
| 1493 | my $href; | ||
| 1494 | for my $key (qw[scheme host path]) { | ||
| 1495 | $href->{$key} = shift @parts; | ||
| 1496 | } | ||
| 1497 | |||
| 1498 | return if lc($href->{'scheme'}) ne 'file' and !$href->{'host'}; | ||
| 1499 | return if !$href->{'path'}; | ||
| 1500 | |||
| 1501 | return $href; | ||
| 1502 | } | ||
| 1503 | |||
| 1504 | ## tries to figure out close hosts based on your timezone | ||
| 1505 | ## | ||
| 1506 | ## Currently can only report on unique items for each of zones, countries, and | ||
| 1507 | ## sites. In the future this will be combined with something else (perhaps a | ||
| 1508 | ## ping?) to narrow down multiple choices. | ||
| 1509 | ## | ||
| 1510 | ## Tries to return the best zone, country, and site for your location. Any non- | ||
| 1511 | ## unique items will be set to undef instead. | ||
| 1512 | ## | ||
| 1513 | ## (takes hashref, returns array) | ||
| 1514 | ## | ||
| 1515 | sub _guess_from_timezone { | ||
| 1516 | my $self = shift; | ||
| 1517 | my $hosts = shift; | ||
| 1518 | my (%zones, %countries, %sites); | ||
| 1519 | |||
| 1520 | ### autrijus - build time zone table | ||
| 1521 | my %freq_weight = ( | ||
| 1522 | 'hourly' => 2400, | ||
| 1523 | '4 times a day' => 400, | ||
| 1524 | '4x daily' => 400, | ||
| 1525 | 'daily' => 100, | ||
| 1526 | 'twice daily' => 50, | ||
| 1527 | 'weekly' => 15, | ||
| 1528 | ); | ||
| 1529 | |||
| 1530 | while (my ($site, $host) = each %{$hosts}) { | ||
| 1531 | my ($zone, $continent, $country, $frequency) = | ||
| 1532 | @{$host}{qw/dst_timezone continent country frequency/}; | ||
| 1533 | |||
| 1534 | |||
| 1535 | # skip non-well-formed ones | ||
| 1536 | next unless $continent and $country and $zone =~ /^[-+]?\d+(?::30)?/; | ||
| 1537 | ### fix style | ||
| 1538 | chomp $zone; | ||
| 1539 | $zone =~ s/:30/.5/; | ||
| 1540 | $zone =~ s/^\+//; | ||
| 1541 | $zone =~ s/"//g; | ||
| 1542 | |||
| 1543 | $zones{$zone}{$continent}++; | ||
| 1544 | $countries{$zone}{$continent}{$country}++; | ||
| 1545 | $sites{$zone}{$continent}{$country}{$site} = $freq_weight{$frequency}; | ||
| 1546 | } | ||
| 1547 | |||
| 1548 | use Time::Local; | ||
| 1549 | my $offset = ((timegm(localtime) - timegm(gmtime)) / 3600); | ||
| 1550 | |||
| 1551 | local $_; | ||
| 1552 | |||
| 1553 | ## pick the entry with most country/site/frequency, one level each; | ||
| 1554 | ## note it has to be sorted -- otherwise we're depending on the hash order. | ||
| 1555 | ## also, the list context assignment (pick first one) is deliberate. | ||
| 1556 | |||
| 1557 | my ($continent) = map { | ||
| 1558 | (sort { ($_->{$b} <=> $_->{$a}) or $b cmp $a } keys(%{$_})) | ||
| 1559 | } $zones{$offset}; | ||
| 1560 | |||
| 1561 | my ($country) = map { | ||
| 1562 | (sort { ($_->{$b} <=> $_->{$a}) or $b cmp $a } keys(%{$_})) | ||
| 1563 | } $countries{$offset}{$continent}; | ||
| 1564 | |||
| 1565 | my ($site) = map { | ||
| 1566 | (sort { ($_->{$b} <=> $_->{$a}) or $b cmp $a } keys(%{$_})) | ||
| 1567 | } $sites{$offset}{$continent}{$country}; | ||
| 1568 | |||
| 1569 | return ($continent, $country, $site); | ||
| 1570 | } # _guess_from_timezone | ||
| 1571 | |||
| 1572 | |||
| 1573 | ### big big regex, stolen to check if you enter a valid address | ||
| 1574 | { | ||
| 1575 | my $RFC822PAT; # RFC pattern to match for valid email address | ||
| 1576 | |||
| 1577 | sub _valid_email { | ||
| 1578 | my $self = shift; | ||
| 1579 | if (!$RFC822PAT) { | ||
| 1580 | my $esc = '\\\\'; my $Period = '\.'; my $space = '\040'; | ||
| 1581 | my $tab = '\t'; my $OpenBR = '\['; my $CloseBR = '\]'; | ||
| 1582 | my $OpenParen = '\('; my $CloseParen = '\)'; my $NonASCII = '\x80-\xff'; | ||
| 1583 | my $ctrl = '\000-\037'; my $CRlist = '\012\015'; | ||
| 1584 | |||
| 1585 | my $qtext = qq/[^$esc$NonASCII$CRlist\"]/; | ||
| 1586 | my $dtext = qq/[^$esc$NonASCII$CRlist$OpenBR$CloseBR]/; | ||
| 1587 | my $quoted_pair = qq< $esc [^$NonASCII] >; # an escaped character | ||
| 1588 | my $ctext = qq< [^$esc$NonASCII$CRlist()] >; | ||
| 1589 | my $Cnested = qq< $OpenParen $ctext* (?: $quoted_pair $ctext* )* $CloseParen >; | ||
| 1590 | my $comment = qq< $OpenParen $ctext* (?: (?: $quoted_pair | $Cnested ) $ctext* )* $CloseParen >; | ||
| 1591 | my $X = qq< [$space$tab]* (?: $comment [$space$tab]* )* >; | ||
| 1592 | my $atom_char = qq/[^($space)<>\@,;:\".$esc$OpenBR$CloseBR$ctrl$NonASCII]/; | ||
| 1593 | my $atom = qq< $atom_char+ (?!$atom_char) >; | ||
| 1594 | my $quoted_str = qq< \" $qtext * (?: $quoted_pair $qtext * )* \" >; | ||
| 1595 | my $word = qq< (?: $atom | $quoted_str ) >; | ||
| 1596 | my $domain_ref = $atom; | ||
| 1597 | my $domain_lit = qq< $OpenBR (?: $dtext | $quoted_pair )* $CloseBR >; | ||
| 1598 | my $sub_domain = qq< (?: $domain_ref | $domain_lit) $X >; | ||
| 1599 | my $domain = qq< $sub_domain (?: $Period $X $sub_domain)* >; | ||
| 1600 | my $route = qq< \@ $X $domain (?: , $X \@ $X $domain )* : $X >; | ||
| 1601 | my $local_part = qq< $word $X (?: $Period $X $word $X )* >; | ||
| 1602 | my $addr_spec = qq< $local_part \@ $X $domain >; | ||
| 1603 | my $route_addr = qq[ < $X (?: $route )? $addr_spec > ]; | ||
| 1604 | my $phrase_ctrl = '\000-\010\012-\037'; # like ctrl, but without tab | ||
| 1605 | my $phrase_char = qq/[^()<>\@,;:\".$esc$OpenBR$CloseBR$NonASCII$phrase_ctrl]/; | ||
| 1606 | my $phrase = qq< $word $phrase_char * (?: (?: $comment | $quoted_str ) $phrase_char * )* >; | ||
| 1607 | $RFC822PAT = qq< $X (?: $addr_spec | $phrase $route_addr) >; | ||
| 1608 | } | ||
| 1609 | |||
| 1610 | return scalar ($_[0] =~ /$RFC822PAT/ox); | ||
| 1611 | } | ||
| 1612 | } | ||
| 1613 | |||
| 1614 | |||
| 1615 | |||
| 1616 | |||
| 1617 | |||
| 1618 | |||
| 1619 | 1; | ||
| 1620 | |||
| 1621 | |||
| 1622 | sub _edit { | ||
| 1623 | my $self = shift; | ||
| 1624 | my $conf = $self->configure_object; | ||
| 1625 | my $file = shift || $conf->_config_pm_to_file( $self->config_type ); | ||
| 1626 | my $editor = shift || $conf->get_program('editor'); | ||
| 1627 | my $term = $self->term; | ||
| 1628 | |||
| 1629 | unless( $editor ) { | ||
| 1630 | print loc(" | ||
| 1631 | I'm sorry, I can't find a suitable editor, so I can't offer you | ||
| 1632 | post-configuration editing of the config file | ||
| 1633 | |||
| 1634 | "); | ||
| 1635 | return 1; | ||
| 1636 | } | ||
| 1637 | |||
| 1638 | ### save the thing first, so there's something to edit | ||
| 1639 | $self->_save; | ||
| 1640 | |||
| 1641 | return !system("$editor $file"); | ||
| 1642 | } | ||
| 1643 | |||
| 1644 | sub _save { | ||
| 1645 | my $self = shift; | ||
| 1646 | my $conf = $self->configure_object; | ||
| 1647 | |||
| 1648 | return $conf->save( $self->config_type ); | ||
| 1649 | } | ||
| 1650 | |||
| 1651 | 1; |