forked from jib/cpanplus-devel
/
Default.pm
1977 lines (1539 loc) · 57.5 KB
/
Default.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package CPANPLUS::Shell::Default;
use strict;
use CPANPLUS::Error;
use CPANPLUS::Backend;
use CPANPLUS::Configure::Setup;
use CPANPLUS::Internals::Constants;
use CPANPLUS::Internals::Constants::Report qw[GRADE_FAIL];
use Cwd;
use IPC::Cmd;
use Term::UI;
use Data::Dumper;
use Term::ReadLine;
use Module::Load qw[load];
use Params::Check qw[check];
use Module::Load::Conditional qw[can_load check_install];
use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';
local $Params::Check::VERBOSE = 1;
local $Data::Dumper::Indent = 1; # for dumpering from !
BEGIN {
use vars qw[ $VERSION @ISA ];
@ISA = qw[ CPANPLUS::Shell::_Base::ReadLine ];
$VERSION = "0.9123";
}
load CPANPLUS::Shell;
my $map = {
'm' => '_search_module',
'a' => '_search_author',
'!' => '_bang',
'?' => '_help',
'h' => '_help',
'q' => '_quit',
'r' => '_readme',
'v' => '_show_banner',
'w' => '__display_results',
'd' => '_fetch',
'z' => '_shell',
'f' => '_distributions',
'x' => '_reload_indices',
'i' => '_install',
't' => '_install',
'l' => '_details',
'p' => '_print',
's' => '_set_conf',
'o' => '_uptodate',
'b' => '_autobundle',
'u' => '_uninstall',
'/' => '_meta', # undocumented for now
'c' => '_reports',
'e' => '_reload_shell',
};
### free letters: e g j k n y ###
### will be filled if you have a .default-shell.rc and
### Config::Auto installed
my $rc = {};
### the shell object, scoped to the file ###
my $Shell;
my $Brand = loc('CPAN Terminal');
my $Prompt = $Brand . '> ';
=pod
=head1 NAME
CPANPLUS::Shell::Default - the default CPANPLUS shell
=head1 SYNOPSIS
### loading the shell:
$ cpanp # run 'cpanp' from the command line
$ perl -MCPANPLUS -eshell # load the shell from the command line
use CPANPLUS::Shell qw[Default]; # load this shell via the API
# always done via CPANPLUS::Shell
my $ui = CPANPLUS::Shell->new;
$ui->shell; # run the shell
$ui->dispatch_on_input( input => 'x'); # update the source using the
# dispatch method
### when in the shell:
### Note that all commands can also take options.
### Look at their underlying CPANPLUS::Backend methods to see
### what options those are.
cpanp> h # show help messages
cpanp> ? # show help messages
cpanp> m Acme # find acme modules, allows regexes
cpanp> a KANE # find modules by kane, allows regexes
cpanp> f Acme::Foo # get a list of all releases of Acme::Foo
cpanp> i Acme::Foo # install Acme::Foo
cpanp> i Acme-Foo-1.3 # install version 1.3 of Acme::Foo
cpanp> i <URI> # install from URI, like ftp://foo.com/X.tgz
cpanp> i <DIR> # install from an absolute or relative directory
cpanp> i 1 3..5 # install search results 1, 3, 4 and 5
cpanp> i * # install all search results
cpanp> a KANE; i *; # find modules by kane, install all results
cpanp> t Acme::Foo # test Acme::Foo, without installing it
cpanp> u Acme::Foo # uninstall Acme::Foo
cpanp> d Acme::Foo # download Acme::Foo
cpanp> z Acme::Foo # download & extract Acme::Foo, then open a
# shell in the extraction directory
cpanp> c Acme::Foo # get a list of test results for Acme::Foo
cpanp> l Acme::Foo # view details about the Acme::Foo package
cpanp> r Acme::Foo # view Acme::Foo's README file
cpanp> o # get a list of all installed modules that
# are out of date
cpanp> o 1..3 # list uptodateness from a previous search
cpanp> s conf # show config settings
cpanp> s conf md5 1 # enable md5 checks
cpanp> s program # show program settings
cpanp> s edit # edit config file
cpanp> s reconfigure # go through initial configuration again
cpanp> s selfupdate # update your CPANPLUS install
cpanp> s save # save config to disk
cpanp> s mirrors # show currently selected mirrors
cpanp> ! [PERL CODE] # execute the following perl code
cpanp> b # create an autobundle for this computers
# perl installation
cpanp> x # reload index files (purges cache)
cpanp> x --update_source # reload index files, get fresh source files
cpanp> p [FILE] # print error stack (to a file)
cpanp> v # show the banner
cpanp> w # show last search results again
cpanp> q # quit the shell
cpanp> e # exit the shell and reload
cpanp> /plugins # list available plugins
cpanp> /? PLUGIN # list help test of <PLUGIN>
### common options:
cpanp> i ... --skiptest # skip tests
cpanp> i ... --force # force all operations
cpanp> i ... --verbose # run in verbose mode
=head1 DESCRIPTION
This module provides the default user interface to C<CPANPLUS>. You
can start it via the C<cpanp> binary, or as detailed in the L<SYNOPSIS>.
=cut
sub new {
my $class = shift;
my $cb = CPANPLUS::Backend->new( @_ );
my $self = $class->SUPER::_init(
brand => $Brand,
term => Term::ReadLine->new( $Brand ),
prompt => $Prompt,
backend => $cb,
format => "%4s %-55s %8s %-10s\n",
dist_format => "%4s %-42s %-12s %8s %-10s\n",
);
### make it available package wide ###
$Shell = $self;
my $rc_file = File::Spec->catfile(
$cb->configure_object->get_conf('base'),
DOT_SHELL_DEFAULT_RC,
);
if( -e $rc_file && -r _ ) {
$rc = $self->_read_configuration_from_rc( $rc_file );
}
### register install callback ###
$cb->_register_callback(
name => 'install_prerequisite',
code => \&__ask_about_install,
);
### execute any login commands specified ###
$self->dispatch_on_input( input => $rc->{'login'} )
if defined $rc->{'login'};
### register test report callbacks ###
$cb->_register_callback(
name => 'edit_test_report',
code => \&__ask_about_edit_test_report,
);
$cb->_register_callback(
name => 'send_test_report',
code => \&__ask_about_send_test_report,
);
$cb->_register_callback(
name => 'proceed_on_test_failure',
code => \&__ask_about_test_failure,
);
### load all the plugins
$self->_plugins_init;
if (my $histfile = $cb->configure_object->get_conf( 'histfile' )) {
my $term = $self->term;
if ($term->can('AddHistory')) {
if (open my $fh, '<', $histfile) {
local $/ = "\n";
while (my $line = <$fh>) {
chomp($line);
$term->AddHistory($line);
}
close($fh);
}
}
}
return $self;
}
sub shell {
my $self = shift;
my $term = $self->term;
my $conf = $self->backend->configure_object;
$self->_show_banner;
$self->__print( "*** Type 'p' now to show start up log\n" ); # XXX add to banner?
$self->_show_random_tip if $conf->get_conf('show_startup_tip');
$self->_input_loop && $self->__print( "\n" );
$self->_quit;
}
sub _input_loop {
my $self = shift;
my $term = $self->term;
my $cb = $self->backend;
my $normal_quit = 0;
while (
defined (my $input = eval { $term->readline($self->prompt) } )
or $self->_signals->{INT}{count} == 1
) {
### re-initiate all signal handlers
while (my ($sig, $entry) = each %{$self->_signals} ) {
$SIG{$sig} = $entry->{handler} if exists($entry->{handler});
}
$self->__print( "\n" );
last if $self->dispatch_on_input( input => $input );
### flush the lib cache ###
$cb->_flush( list => [qw|lib load|] );
} continue {
### clear the sigint count
$self->_signals->{INT}{count}--
if $self->_signals->{INT}{count};
### reset the 'install prereq?' cached answer
$self->settings->{'install_all_prereqs'} = undef;
}
return 1;
}
### return 1 to quit ###
sub dispatch_on_input {
my $self = shift;
my $conf = $self->backend->configure_object();
my $term = $self->term;
my %hash = @_;
my($string, $noninteractive);
my $tmpl = {
input => { required => 1, store => \$string },
noninteractive => { required => 0, store => \$noninteractive },
};
check( $tmpl, \%hash ) or return;
### indicates whether or not the user will receive a shell
### prompt after the command has finished.
$self->noninteractive($noninteractive) if defined $noninteractive;
my $rv = 1;
my @cmds = split ';', $string;
while( my $input = shift @cmds ) {
### to send over the socket ###
my $org_input = $input;
my $key; my $options;
{ ### make whitespace not count when using special chars
{ $input =~ s|^\s*([!?/])|$1 |; }
### get the first letter of the input
$input =~ s|^\s*([\w\?\!/])\w*||;
chomp $input;
$key = lc($1);
### we figured out what the command was...
### if we have more input, that DOES NOT start with a white
### space char, we misparsed.. like 'Test::Foo::Bar', which
### would turn into 't', '::Foo::Bar'...
if( $input and $input !~ s/^\s+// ) {
$self->__print( loc("Could not understand command: %1\n".
"Possibly missing command before argument(s)?\n",
$org_input) );
return;
}
### allow overrides from the config file ###
if( defined $rc->{$key} ) {
$input = $rc->{$key} . $input;
}
### grab command line options like --no-force and --verbose ###
($options,$input) = $term->parse_options($input)
unless $key eq '!';
}
### emtpy line? ###
return unless $key;
### time to quit ###
return 1 if $key eq 'q';
my $method = $map->{$key};
### dispatch meta locally at all times ###
if( $key eq '/' ) {
### keep track of failures
$rv *= length $self->$method(input => $input, options => $options);
next;
}
### flush unless we're trying to print the stack
CPANPLUS::Error->flush unless $key eq 'p';
### connected over a socket? ###
if( $self->remote ) {
### unsupported commands ###
if( $key eq 'z' or
($key eq 's' and $input =~ /^\s*edit/)
) {
$self->__print( "\n",
loc( "Command '%1' not supported over remote connection",
join ' ', $key, $input
), "\n\n" );
} else {
my($status,$buff) = $self->__send_remote_command($org_input);
$self->__print( "\n", loc("Command failed!"), "\n\n" )
unless $status;
### keep track of failures
$rv *= length $status;
$self->_pager_open if $buff =~ tr/\n// > $self->_term_rowcount;
$self->__print( $buff );
$self->_pager_close;
}
### or just a plain local shell? ###
} else {
unless( $self->can($method) ) {
$self->__print(loc("Unknown command '%1'. Usage:", $key), "\n");
$self->_help;
} else {
### some methods don't need modules ###
my @mods;
@mods = $self->_select_modules($input)
unless grep {$key eq $_} qw[! m a v w x p s b / ? h];
### keep track of failures
$rv *= defined eval { $self->$method(
modules => \@mods,
options => $options,
input => $input,
choice => $key )
};
error( $@ ) if $@;
}
}
}
### outside the shell loop, we can return the actual return value;
return $rv if $self->noninteractive;
return;
}
sub _select_modules {
my $self = shift;
my $input = shift or return;
my $cache = $self->cache;
my $cb = $self->backend;
### expand .. in $input
$input =~ s{\b(\d+)\s*\.\.\s*(\d+)\b}
{join(' ', ($1 < 1 ? 1 : $1) .. ($2 > $#{$cache} ? $#{$cache} : $2))}eg;
$input = join(' ', 1 .. $#{$cache}) if $input eq '*';
$input =~ s/'/::/g; # perl 4 convention
my @rv;
for my $mod (split /\s+/, $input) {
### it's a cache look up ###
if( $mod =~ /^\d+/ and $mod > 0 ) {
unless( scalar @$cache ) {
$self->__print( loc("No search was done yet!"), "\n" );
} elsif ( my $obj = $cache->[$mod] ) {
push @rv, $obj;
} else {
$self->__print( loc("No such module: %1", $mod), "\n" );
}
} else {
my $obj = $cb->parse_module( module => $mod );
unless( $obj ) {
$self->__print( loc("No such module: %1", $mod), "\n" );
} else {
push @rv, $obj;
}
}
}
unless( scalar @rv ) {
$self->__print( loc("No modules found to operate on!\n") );
return;
} else {
return @rv;
}
}
sub _format_version {
my $self = shift;
my $version = shift || 0;
### fudge $version into the 'optimal' format
$version = 0 if $version eq 'undef';
$version =~ s/_//g; # everything after gets stripped off otherwise
### allow 6 digits after the dot, as that's how perl stringifies
### x.y.z numbers.
$version = sprintf('%3.6f', $version);
$version = '' if $version == '0.00';
$version =~ s/(00{0,3})$/' ' x (length $1)/e;
return $version;
}
sub __display_results {
my $self = shift;
my $cache = $self->cache;
my @rv = @$cache;
if( scalar @rv ) {
$self->_pager_open if $#{$cache} >= $self->_term_rowcount;
my $i = 1;
for my $mod (@rv) {
next unless $mod; # first one is undef
# humans start counting at 1
### for dists only -- we have checksum info
if( $mod->mtime ) {
$self->__printf(
$self->dist_format,
$i,
$mod->module,
$mod->mtime,
$self->_format_version( $mod->version ),
$mod->author->cpanid
);
} else {
$self->__printf(
$self->format,
$i,
$mod->module,
$self->_format_version( $mod->version ),
$mod->author->cpanid
);
}
$i++;
}
$self->_pager_close;
} else {
$self->__print( loc("No results to display"), "\n" );
}
return 1;
}
sub _quit {
my $self = shift;
my $term = $self->term;
$self->dispatch_on_input( input => $rc->{'logout'} )
if defined $rc->{'logout'};
if ($term->can('GetHistory')) {
my @history = $term->GetHistory;
my $histfile = $self->backend->configure_object->get_conf('histfile');
if (open my $fh, '>', $histfile) {
foreach my $line (@history) {
print {$fh} "$line\n";
}
close($fh);
}
else {
warn "Cannot open history file '$histfile' - $!";
}
}
$self->__print( loc("Exiting CPANPLUS shell"), "\n" );
return 1;
}
###########################
### actual command subs ###
###########################
### print out the help message ###
### perhaps, '?' should be a slightly different version ###
{ my @help;
sub _help {
my $self = shift;
my %hash = @_;
my $input;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
input => { required => 0, store => \$input }
};
my $args = check( $tmpl, \%hash ) or return;
}
@help = (
loc('[General]' ),
loc(' h | ? # display help' ),
loc(' q # exit' ),
loc(' e # exit and reload' ),
loc(' v # version information' ),
loc('[Search]' ),
loc(' a AUTHOR ... # search by author(s)' ),
loc(' m MODULE ... # search by module(s)' ),
loc(' f MODULE ... # list all releases of a module' ),
loc(" o [ MODULE ... ] # list installed module(s) that aren't up to date" ),
loc(' w # display the result of your last search again' ),
loc('[Operations]' ),
loc(' i MODULE | NUMBER ... # install module(s), by name or by search number' ),
loc(' i URI | ... # install module(s), by URI (ie http://foo.com/X.tgz)' ),
loc(' i DIR | ... # install module(s), by path (ie ./Module-1.0)' ),
loc(' t MODULE | NUMBER ... # test module(s), by name or by search number' ),
loc(' u MODULE | NUMBER ... # uninstall module(s), by name or by search number' ),
loc(' d MODULE | NUMBER ... # download module(s)' ),
loc(' l MODULE | NUMBER ... # display detailed information about module(s)' ),
loc(' r MODULE | NUMBER ... # display README files of module(s)' ),
loc(' c MODULE | NUMBER ... # check for module report(s) from cpan-testers' ),
loc(' z MODULE | NUMBER ... # extract module(s) and open command prompt in it' ),
loc('[Local Administration]' ),
loc(' b # write a bundle file for your configuration' ),
loc(' s program [OPT VALUE] # set program locations for this session' ),
loc(' s conf [OPT VALUE] # set config options for this session' ),
loc(' s mirrors # show currently selected mirrors' ),
loc(' s reconfigure # reconfigure settings ' ),
loc(' s selfupdate # update your CPANPLUS install '),
loc(' s save [user|system] # save settings for this user or systemwide' ),
loc(' s edit [user|system] # open configuration file in editor and reload' ),
loc(' ! EXPR # evaluate a perl statement' ),
loc(' p [FILE] # print the error stack (optionally to a file)' ),
loc(' x # reload CPAN indices (purges cache)' ),
loc(' x --update_source # reload CPAN indices, get fresh source files' ),
loc('[Common Options]' ),
loc(' i ... --skiptest # skip tests' ),
loc(' i ... --force # force all operations' ),
loc(' i ... --verbose # run in verbose mode' ),
loc('[Plugins]' ),
loc(' /plugins # list available plugins' ),
loc(' /? [PLUGIN NAME] # show usage for (a particular) plugin(s)' ),
) unless @help;
$self->_pager_open if (@help >= $self->_term_rowcount);
### XXX: functional placeholder for actual 'detailed' help.
$self->__print( "Detailed help for the command '$input' is " .
"not available.\n\n" ) if length $input;
$self->__print( map {"$_\n"} @help );
$self->__print( $/ );
$self->_pager_close;
return 1;
}
}
### eval some code ###
sub _bang {
my $self = shift;
my $cb = $self->backend;
my %hash = @_;
my $input;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
input => { required => 1, store => \$input }
};
my $args = check( $tmpl, \%hash ) or return;
}
local $Data::Dumper::Indent = 1; # for dumpering from !
eval $input;
error( $@ ) if $@;
$self->__print( "\n" );
return if $@;
return 1;
}
sub _search_module {
my $self = shift;
my $cb = $self->backend;
my %hash = @_;
my $args;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
input => { required => 1, },
options => { default => { } },
};
$args = check( $tmpl, \%hash ) or return;
}
my @regexes = map { qr/$_/i } split /\s+/, $args->{'input'};
### XXX this is rather slow, because (probably)
### of the many method calls
### XXX need to profile to speed it up =/
### find the modules ###
my @rv = sort { $a->module cmp $b->module }
$cb->search(
%{$args->{'options'}},
type => 'module',
allow => \@regexes,
);
### store the result in the cache ###
$self->cache([undef,@rv]);
$self->__display_results;
return 1;
}
sub _search_author {
my $self = shift;
my $cb = $self->backend;
my %hash = @_;
my $args;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
input => { required => 1, },
options => { default => { } },
};
$args = check( $tmpl, \%hash ) or return;
}
my @regexes = map { qr/$_/i } split /\s+/, $args->{'input'};
my @rv;
for my $type (qw[author cpanid]) {
push @rv, $cb->search(
%{$args->{'options'}},
type => $type,
allow => \@regexes,
);
}
my %seen;
my @list = sort { $a->module cmp $b->module }
grep { defined }
map { $_->modules }
grep { not $seen{$_}++ } @rv;
$self->cache([undef,@list]);
$self->__display_results;
return 1;
}
sub _readme {
my $self = shift;
my $cb = $self->backend;
my %hash = @_;
my $args; my $mods; my $opts;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
modules => { required => 1, store => \$mods },
options => { default => { }, store => \$opts },
};
$args = check( $tmpl, \%hash ) or return;
}
return unless scalar @$mods;
$self->_pager_open;
for my $mod ( @$mods ) {
$self->__print( $mod->readme( %$opts ) );
}
$self->_pager_close;
return 1;
}
sub _fetch {
my $self = shift;
my $cb = $self->backend;
my %hash = @_;
my $args; my $mods; my $opts;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
modules => { required => 1, store => \$mods },
options => { default => { }, store => \$opts },
};
$args = check( $tmpl, \%hash ) or return;
}
$self->_pager_open if @$mods >= $self->_term_rowcount;
my $rv = 1;
for my $mod (@$mods) {
my $where = $mod->fetch( %$opts );
$rv *= length $where;
$self->__print(
$where
? loc("Successfully fetched '%1' to '%2'",
$mod->module, $where )
: loc("Failed to fetch '%1'", $mod->module)
);
$self->__print( "\n" );
}
$self->_pager_close;
return 1 if $rv;
return;
}
sub _shell {
my $self = shift;
my $cb = $self->backend;
my $conf = $cb->configure_object;
my %hash = @_;
my $shell = $conf->get_program('shell');
unless( $shell ) {
$self->__print(
loc("Your config does not specify a subshell!"), "\n",
loc("Perhaps you need to re-run your setup?"), "\n"
);
return;
}
my $args; my $mods; my $opts;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
modules => { required => 1, store => \$mods },
options => { default => { }, store => \$opts },
};
$args = check( $tmpl, \%hash ) or return;
}
my $cwd = Cwd::cwd();
for my $mod (@$mods) {
$mod->fetch( %$opts ) or next;
$mod->extract( %$opts ) or next;
$cb->_chdir( dir => $mod->status->extract() ) or next;
#local $ENV{PERL5OPT} = CPANPLUS::inc->original_perl5opt;
if( system($shell) and $! ) {
$self->__print(
loc("Error executing your subshell '%1': %2",
$shell, $!),"\n"
);
next;
}
}
$cb->_chdir( dir => $cwd );
return 1;
}
sub _distributions {
my $self = shift;
my $cb = $self->backend;
my $conf = $cb->configure_object;
my %hash = @_;
my $args; my $mods; my $opts;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
modules => { required => 1, store => \$mods },
options => { default => { }, store => \$opts },
};
$args = check( $tmpl, \%hash ) or return;
}
my @list;
for my $mod (@$mods) {
push @list, sort { $a->version <=> $b->version }
grep { defined } $mod->distributions( %$opts );
}
my @rv = sort { $a->module cmp $b->module } @list;
$self->cache([undef,@rv]);
$self->__display_results;
return 1;
}
sub _reload_indices {
my $self = shift;
my $cb = $self->backend;
my %hash = @_;
my $args; my $opts;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
options => { default => { }, store => \$opts },
};
$args = check( $tmpl, \%hash ) or return;
}
my $rv = $cb->reload_indices( %$opts );
### so the update failed, but you didnt give it any options either
if( !$rv and !(keys %$opts) ) {
$self->__print(
"\nFailure may be due to corrupt source files\n" .
"Try this:\n\tx --update_source\n\n" );
}
return $rv;
}
sub _install {
my $self = shift;
my $cb = $self->backend;
my $conf = $cb->configure_object;
my %hash = @_;
my $args; my $mods; my $opts; my $choice;
{ local $Params::Check::ALLOW_UNKNOWN = 1;
my $tmpl = {
modules => { required => 1, store => \$mods },
options => { default => { }, store => \$opts },
choice => { required => 1, store => \$choice,
allow => [qw|i t|] },
};
$args = check( $tmpl, \%hash ) or return;
}
unless( scalar @$mods ) {
$self->__print( loc("Nothing done\n") );
return;
}
my $target = $choice eq 'i' ? TARGET_INSTALL : TARGET_CREATE;
my $prompt = $choice eq 'i' ? loc('Installing ') : loc('Testing ');
my $action = $choice eq 'i' ? 'install' : 'test';
my $status = {};
### first loop over the mods to install them ###
for my $mod (@$mods) {
$self->__print( $prompt, $mod->module, " (".$mod->version.")", "\n" );
my $log_length = length CPANPLUS::Error->stack_as_string;
### store the status for look up when we're done with all
### install calls
$status->{$mod} = $mod->install( %$opts, target => $target );
### would you like a log file of what happened?
if( $conf->get_conf('write_install_logs') ) {
if ( ON_WIN32 and !check_install(
module => 'IPC::Run', version => 0.55 )
) {
error(loc("IPC::Run version '%1' is required on MSWin32"
. " in order to capture buffers."
. " The logfile generated may not contain"
. " any useful data, until it is installed", 0.55));
}
my $dir = File::Spec->catdir(
$conf->get_conf('base'),
$conf->_get_build('install_log_dir'),
);
### create the dir if it doesn't exit yet
$cb->_mkdir( dir => $dir ) unless -d $dir;
my $file = File::Spec->catfile(
$dir,
INSTALL_LOG_FILE->( $mod )
);
if ( open my $fh, ">$file" ) {
my $stack = CPANPLUS::Error->stack_as_string;
### remove everything in the log that was there *before*
### we started this install
substr( $stack, 0, $log_length, '' );
print $fh $stack;
close $fh;
$self->__print(
loc("*** Install log written to:\n %1\n\n", $file)
);
} else {
warn "Could not open '$file': $!\n";
next;
}
}
}
my $flag;
### then report whether all this went ok or not ###
for my $mod (@$mods) {
# if( $mod->status->installed ) {
if( $status->{$mod} ) {
$self->__print(
loc("Module '%1' %tense(%2,past) successfully\n",
$mod->module, $action)
);
} else {
$flag++;