blib/lib/CPANPLUS/Shell/Classic.pm untested

filter: Statementstmt 0.0% 0 / 512 Branchbran 0.0% 0 / 138 Conditioncond 0.0% 0 / 84 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 43 Podpod 0.0% 0 / 29 totaltotal 0.0% 0 / 806 CC 70 SCAR 36.7
CC
70
Cov
0%
_set_conf
156.0
_distribution
72.0
_pp_uptodate
72.0
CRAP 39.3
1 ##################################################
2 ### CPANPLUS/Shell/Classic.pm ###
3 ### Backwards compatible shell for CPAN++ ###
4 ### Written 08-04-2002 by Jos Boumans ###
5 ##################################################
6  
7 package CPANPLUS::Shell::Classic;
8  
9 use strict;
10  
11  
12 use CPANPLUS::Error;
13 use CPANPLUS::Backend;
14 use CPANPLUS::Configure::Setup;
15 use CPANPLUS::Internals::Constants;
16  
17 use Cwd;
18 use IPC::Cmd;
19 use Term::UI;
20 use Data::Dumper;
21 use Term::ReadLine;
22  
23 use Module::Load qw[load];
24 use Params::Check qw[check];
25 use Module::Load::Conditional qw[can_load];
26  
27 $Params::Check::VERBOSE = 1;
28 $Params::Check::ALLOW_UNKNOWN = 1;
29  
30 BEGIN {
31 use vars qw[ $VERSION @ISA ];
32 @ISA = qw[ CPANPLUS::Shell::_Base::ReadLine ];
33 $VERSION = "0.9914";
34 }
35  
36 load CPANPLUS::Shell;
37  
38  
39 ### our command set ###
40 my $map = {
41 a => '_author',
42 b => '_bundle',
43 d => '_distribution',
44 'm' => '_module',
45 i => '_find_all',
46 r => '_uptodate',
47 u => '_not_supported',
48 ls => '_ls',
49 get => '_fetch',
50 make => '_install',
51 test => '_install',
52 install => '_install',
53 clean => '_not_supported',
54 look => '_shell',
55 readme => '_readme',
56 h => '_help',
57 '?' => '_help',
58 o => '_set_conf',
59 reload => '_reload',
60 autobundle => '_autobundle',
61 '!' => '_bang',
62 #'q' => '_quit', # done it the loop itself
63 };
64  
65 ### the shell object, scoped to the file ###
66 my $Shell;
67 my $Brand = 'cpan';
68 my $Prompt = $Brand . '> ';
69  
70 sub new {
71 my $class = shift;
72  
73 my $cb = new CPANPLUS::Backend;
74 my $self = $class->SUPER::_init(
75 brand => $Brand,
76 term => Term::ReadLine->new( $Brand ),
77 prompt => $Prompt,
78 backend => $cb,
79 format => "%5s %-50s %8s %-10s\n",
80 );
81 ### make it available package wide ###
82 $Shell = $self;
83  
84 ### enable verbose, it's the cpan.pm way
85 $cb->configure_object->set_conf( verbose => 1 );
86  
87  
88 ### register install callback ###
89 $cb->_register_callback(
90 name => 'install_prerequisite',
91 code => \&__ask_about_install,
92 );
93  
94 ### register test report callback ###
95 $cb->_register_callback(
96 name => 'edit_test_report',
97 code => \&__ask_about_test_report,
98 );
99  
100 if (my $histfile = $self->configure_object->get_conf( 'histfile' )) {
101 my $term = $self->term;
102 if ($term->can('AddHistory')) {
103 if (open my $fh, '<', $histfile) {
104 local $/ = "\n";
105 while (my $line = <$fh>) {
106 chomp($line);
107 $term->AddHistory($line);
108 }
109 close($fh);
110 }
111 }
112 }
113  
114 return $self;
115 }
116  
117 sub shell {
118 my $self = shift;
119 my $term = $self->term;
120  
121 $self->_show_banner;
122 $self->_input_loop && print "\n";
123 $self->_quit;
124 }
125  
126 sub _input_loop {
127 my $self = shift;
128 my $term = $self->term;
129 my $cb = $self->backend;
130  
131 my $normal_quit = 0;
132 while (
133 defined (my $input = eval { $term->readline($self->prompt) } )
134 or $self->_signals->{INT}{count} == 1
135 ) {
136 ### re-initiate all signal handlers
137 while (my ($sig, $entry) = each %{$self->_signals} ) {
138 $SIG{$sig} = $entry->{handler} if exists($entry->{handler});
139 }
140  
141 last if $self->_dispatch_on_input( input => $input );
142  
143 ### flush the lib cache ###
144 $cb->_flush( list => [qw|lib load|] );
145  
146 } continue {
147 $self->_signals->{INT}{count}--
148 if $self->_signals->{INT}{count}; # clear the sigint count
149 }
150  
151 return 1;
152 }
153  
154 sub _dispatch_on_input {
155 my $self = shift;
156 my $conf = $self->backend->configure_object();
157 my $term = $self->term;
158 my %hash = @_;
159  
160 my $string;
161 my $tmpl = {
162 input => { required => 1, store => \$string }
163 };
164  
165 check( $tmpl, \%hash ) or return;
166  
167 ### the original force setting;
168 my $force_store = $conf->get_conf( 'force' );
169  
170 ### parse the input: the first part before the space
171 ### is the command, followed by arguments.
172 ### see the usage below
173 my $key;
174 PARSE_INPUT: {
175 $string =~ s|^\s*([\w\?\!]+)\s*||;
176 chomp $string;
177 $key = lc($1);
178 }
179  
180 ### you prefixed the input with 'force'
181 ### that means we set the force flag, and
182 ### reparse the input...
183 ### YAY goto block :)
184 if( $key eq 'force' ) {
185 $conf->set_conf( force => 1 );
186 goto PARSE_INPUT;
187 }
188  
189 ### you want to quit
190 return 1 if $key =~ /^q/;
191  
192 my $method = $map->{$key};
193 unless( $self->can( $method ) ) {
194 print "Unknown command '$key'. Type ? for help.\n";
195 return;
196 }
197  
198 ### dispatch the method call
199 eval { $self->$method(
200 command => $key,
201 result => [ split /\s+/, $string ],
202 input => $string );
203 };
204 warn $@ if $@;
205  
206 return;
207 }
208  
209 ### displays quit message
210 sub _quit {
211 my $self = shift;
212 my $term = $self->term;
213  
214 if ($term->can('GetHistory')) {
215 my @history = $term->GetHistory;
216  
217 my $histfile = $self->configure_object->get_conf('histfile');
218  
219 if (open my $fh, '>', $histfile) {
220 foreach my $line (@history) {
221 print {$fh} "$line\n";
222 }
223 close($fh);
224 }
225 else {
226 warn "Cannot open history file '$histfile' - $!";
227 }
228 }
229  
230 ### well, that's what CPAN.pm says...
231 print "Lockfile removed\n";
232 }
233  
234 sub _not_supported {
235 my $self = shift;
236 my %hash = @_;
237  
238 my $cmd;
239 my $tmpl = {
240 command => { required => 1, store => \$cmd }
241 };
242  
243 check( $tmpl, \%hash ) or return;
244  
245 print "Sorry, the command '$cmd' is not supported\n";
246  
247 return;
248 }
249  
250 sub _fetch {
251 my $self = shift;
252 my $cb = $self->backend;
253 my %hash = @_;
254  
255 my($aref, $input);
256 my $tmpl = {
257 result => { store => \$aref, default => [] },
258 input => { default => 'all', store => \$input },
259 };
260  
261 check( $tmpl, \%hash ) or return;
262  
263 for my $mod (@$aref) {
264 my $obj;
265  
266 unless( $obj = $cb->module_tree($mod) ) {
267 print "Warning: Cannot get $input, don't know what it is\n";
268 print "Try the command\n\n";
269 print "\ti /$mod/\n\n";
270 print "to find objects with matching identifiers.\n";
271  
272 next;
273 }
274  
275 $obj->fetch && $obj->extract;
276 }
277  
278 return $aref;
279 }
280  
281 sub _install {
282 my $self = shift;
283 my $cb = $self->backend;
284 my %hash = @_;
285  
286 my $mapping = {
287 make => { target => TARGET_CREATE, skiptest => 1 },
288 test => { target => TARGET_CREATE },
289 install => { target => TARGET_INSTALL },
290 };
291  
292 my($aref,$cmd);
293 my $tmpl = {
294 result => { store => \$aref, default => [] },
295 command => { required => 1, store => \$cmd, allow => [keys %$mapping] },
296 };
297  
298 check( $tmpl, \%hash ) or return;
299  
300 for my $mod (@$aref) {
301 my $obj = $cb->module_tree( $mod );
302  
303 unless( $obj ) {
304 print "No such module '$mod'\n";
305 next;
306 }
307  
308 my $opts = $mapping->{$cmd};
309 $obj->install( %$opts );
310 }
311  
312 return $aref;
313 }
314  
315 sub _shell {
316 my $self = shift;
317 my $cb = $self->backend;
318 my $conf = $cb->configure_object;
319 my %hash = @_;
320  
321 my($aref, $cmd);
322 my $tmpl = {
323 result => { store => \$aref, default => [] },
324 command => { required => 1, store => \$cmd },
325  
326 };
327  
328 check( $tmpl, \%hash ) or return;
329  
330  
331 my $shell = $conf->get_program('shell');
332 unless( $shell ) {
333 print "Your configuration does not define a value for subshells.\n".
334 qq[Please define it with "o conf shell <your shell>"\n];
335 return;
336 }
337  
338 my $cwd = Cwd::cwd();
339  
340 for my $mod (@$aref) {
341 print "Running $cmd for $mod\n";
342  
343 my $obj = $cb->module_tree( $mod ) or next;
344 $obj->fetch or next;
345 $obj->extract or next;
346  
347 $cb->_chdir( dir => $obj->status->extract ) or next;
348  
349 #local $ENV{PERL5OPT} = CPANPLUS::inc->original_perl5opt;
350 if( system($shell) and $! ) {
351 print "Error executing your subshell '$shell': $!\n";
352 next;
353 }
354 }
355 $cb->_chdir( dir => $cwd );
356  
357 return $aref;
358 }
359  
360 sub _readme {
361 my $self = shift;
362 my $cb = $self->backend;
363 my $conf = $cb->configure_object;
364 my %hash = @_;
365  
366 my($aref, $cmd);
367 my $tmpl = {
368 result => { store => \$aref, default => [] },
369 command => { required => 1, store => \$cmd },
370  
371 };
372  
373 check( $tmpl, \%hash ) or return;
374  
375 for my $mod (@$aref) {
376 my $obj = $cb->module_tree( $mod ) or next;
377  
378 if( my $readme = $obj->readme ) {
379  
380 $self->_pager_open;
381 print $readme;
382 $self->_pager_close;
383 }
384 }
385  
386 return 1;
387 }
388  
389 sub _reload {
390 my $self = shift;
391 my $cb = $self->backend;
392 my $conf = $cb->configure_object;
393 my %hash = @_;
394  
395 my($input, $cmd);
396 my $tmpl = {
397 input => { default => 'all', store => \$input },
398 command => { required => 1, store => \$cmd },
399  
400 };
401  
402 check( $tmpl, \%hash ) or return;
403  
404 if ( $input =~ /cpan/i ) {
405 print qq[You want to reload the CPAN code\n];
406 print qq[Just type 'q' and then restart... ] .
407 qq[Trust me, it is MUCH safer\n];
408  
409 } elsif ( $input =~ /index/i ) {
410 $cb->reload_indices(update_source => 1);
411  
412 } else {
413 print qq[cpan re-evals the CPANPLUS.pm file\n];
414 print qq[index re-reads the index files\n];
415 }
416  
417 return 1;
418 }
419  
420 sub _autobundle {
421 my $self = shift;
422 my $cb = $self->backend;
423  
424 print qq[Writing bundle file... This may take a while\n];
425  
426 my $where = $cb->autobundle();
427  
428 print $where
429 ? qq[\nWrote autobundle to $where\n]
430 : qq[\nCould not create autobundle\n];
431  
432 return 1;
433 }
434  
435 sub _set_conf {
436 my $self = shift;
437 my $cb = $self->backend;
438 my $conf = $cb->configure_object;
439 my %hash = @_;
440  
441 my($aref, $input);
442 my $tmpl = {
443 result => { store => \$aref, default => [] },
444 input => { default => 'all', store => \$input },
445 };
446  
447 check( $tmpl, \%hash ) or return;
448  
449 my $type = shift @$aref;
450  
451 if( $type eq 'debug' ) {
452 print qq[Sorry you cannot set debug options through ] .
453 qq[this shell in CPANPLUS\n];
454 return;
455  
456 } elsif ( $type eq 'conf' ) {
457  
458 ### from CPAN.pm :o)
459 # CPAN::Shell::o and CPAN::Config::edit are closely related. 'o conf'
460 # should have been called set and 'o debug' maybe 'set debug'
461  
462 # commit Commit changes to disk
463 # defaults Reload defaults from disk
464 # init Interactive setting of all options
465  
466 my $name = shift @$aref;
467 my $value = "@$aref";
468  
469 if( $name eq 'init' ) {
470 my $setup = CPANPLUS::Configure::Setup->new(
471 conf => $cb->configure_object,
472 term => $self->term,
473 backend => $cb,
474 );
475 return $setup->init;
476  
477 } elsif ($name eq 'commit' ) {;
478 $cb->configure_object->save;
479 print "Your CPAN++ configuration info has been saved!\n\n";
480 return;
481  
482 } elsif ($name eq 'defaults' ) {
483 print qq[Sorry, CPANPLUS cannot restore default for you.\n] .
484 qq[Perhaps you should run the interactive setup again.\n] .
485 qq[\ttry running 'o conf init'\n];
486 return;
487  
488 ### we're just supplying things in the 'conf' section now,
489 ### not the program section.. it's a bit of a hassle to make that
490 ### work cleanly with the original CPAN.pm interface, so we'll fix
491 ### it when people start complaining, which is hopefully never.
492 } else {
493 unless( $name ) {
494 my @list = grep { $_ ne 'hosts' }
495 $conf->options( type => $type );
496  
497 my $method = 'get_' . $type;
498  
499 local $Data::Dumper::Indent = 0;
500 for my $name ( @list ) {
501 my $val = $conf->$method($name);
502 ($val) = ref($val)
503 ? (Data::Dumper::Dumper($val) =~ /= (.*);$/)
504 : "'$val'";
505 printf " %-25s %s\n", $name, $val;
506 }
507  
508 } elsif ( $name eq 'hosts' ) {
509 print "Setting hosts is not trivial.\n" .
510 "It is suggested you edit the " .
511 "configuration file manually";
512  
513 } else {
514 my $method = 'set_' . $type;
515 if( $conf->$method($name => defined $value ? $value : '') ) {
516 my $set_to = defined $value ? $value : 'EMPTY STRING';
517 print "Key '$name' was set to '$set_to'\n";
518 }
519 }
520 }
521 } else {
522 print qq[Known options:\n] .
523 qq[ conf set or get configuration variables\n] .
524 qq[ debug set or get debugging options\n];
525 }
526  
527 return;
528 }
529  
530 ########################
531 ### search functions ###
532 ########################
533  
534 sub _author {
535 my $self = shift;
536 my $cb = $self->backend;
537 my %hash = @_;
538  
539 my($aref, $short, $input, $class);
540 my $tmpl = {
541 result => { store => \$aref, default => ['/./'] },
542 short => { default => 0, store => \$short },
543 input => { default => 'all', store => \$input },
544 class => { default => 'Author', no_override => 1,
545 store => \$class },
546 };
547  
548 check( $tmpl, \%hash ) or return;
549  
550 my @regexes = map { m|/(.+)/| ? qr/$1/ : $_ } @$aref;
551  
552  
553 my @rv;
554 for my $type (qw[author cpanid]) {
555 push @rv, $cb->search( type => $type, allow => \@regexes );
556 }
557  
558 unless( @rv ) {
559 print "No object of type $class found for argument $input\n"
560 unless $short;
561 return;
562 }
563  
564 return $self->_pp_author(
565 result => \@rv,
566 class => $class,
567 short => $short,
568 input => $input );
569  
570 }
571  
572 ### find all modules matching a query ###
573 sub _module {
574 my $self = shift;
575 my $cb = $self->backend;
576 my %hash = @_;
577  
578 my($aref, $short, $input, $class);
579 my $tmpl = {
580 result => { store => \$aref, default => ['/./'] },
581 short => { default => 0, store => \$short },
582 input => { default => 'all', store => \$input },
583 class => { default => 'Module', no_override => 1,
584 store => \$class },
585 };
586  
587 check( $tmpl, \%hash ) or return;
588  
589 my @rv;
590 for my $module (@$aref) {
591 if( $module =~ m|/(.+)/| ) {
592 push @rv, $cb->search( type => 'module',
593 allow => [qr/$1/i] );
594 } else {
595 my $obj = $cb->module_tree( $module ) or next;
596 push @rv, $obj;
597 }
598 }
599  
600 return $self->_pp_module(
601 result => \@rv,
602 class => $class,
603 short => $short,
604 input => $input );
605 }
606  
607 ### find all bundles matching a query ###
608 sub _bundle {
609 my $self = shift;
610 my $cb = $self->backend;
611 my %hash = @_;
612  
613 my($aref, $short, $input, $class);
614 my $tmpl = {
615 result => { store => \$aref, default => ['/./'] },
616 short => { default => 0, store => \$short },
617 input => { default => 'all', store => \$input },
618 class => { default => 'Bundle', no_override => 1,
619 store => \$class },
620 };
621  
622 check( $tmpl, \%hash ) or return;
623  
624 my @rv;
625 for my $bundle (@$aref) {
626 if( $bundle =~ m|/(.+)/| ) {
627 push @rv, $cb->search( type => 'module',
628 allow => [qr/Bundle::.*?$1/i] );
629 } else {
630 my $obj = $cb->module_tree( "Bundle::${bundle}" ) or next;
631 push @rv, $obj;
632 }
633 }
634  
635 return $self->_pp_module(
636 result => \@rv,
637 class => $class,
638 short => $short,
639 input => $input );
640 }
641  
642 sub _distribution {
643 my $self = shift;
644 my $cb = $self->backend;
645 my %hash = @_;
646  
647 my($aref, $short, $input, $class);
648 my $tmpl = {
649 result => { store => \$aref, default => ['/./'] },
650 short => { default => 0, store => \$short },
651 input => { default => 'all', store => \$input },
652 class => { default => 'Distribution', no_override => 1,
653 store => \$class },
654 };
655  
656 check( $tmpl, \%hash ) or return;
657  
658 my @rv;
659 for my $module (@$aref) {
660 ### if it's a regex... ###
661 if ( my ($match) = $module =~ m|^/(.+)/$|) {
662  
663 ### something like /FOO/Bar.tar.gz/ was entered
664 if (my ($path,$package) = $match =~ m|^/?(.+)/(.+)$|) {
665 my $seen;
666  
667 my @data = $cb->search( type => 'package',
668 allow => [qr/$package/i] );
669  
670 my @list = $cb->search( type => 'path',
671 allow => [qr/$path/i],
672 data => \@data );
673  
674 ### make sure we don't list the same dist twice
675 for my $val ( @list ) {
676 next if $seen->{$val->package}++;
677  
678 push @rv, $val;
679 }
680  
681 ### something like /FOO/ or /Bar.tgz/ was entered
682 ### so we look both in the path, as well as in the package name
683 } else {
684 my $seen;
685 { my @list = $cb->search( type => 'package',
686 allow => [qr/$match/i] );
687  
688 ### make sure we don't list the same dist twice
689 for my $val ( @list ) {
690 next if $seen->{$val->package}++;
691  
692 push @rv, $val;
693 }
694 }
695  
696 { my @list = $cb->search( type => 'path',
697 allow => [qr/$match/i] );
698  
699 ### make sure we don't list the same dist twice
700 for my $val ( @list ) {
701 next if $seen->{$val->package}++;
702  
703 push @rv, $val;
704 }
705  
706 }
707 }
708  
709 } else {
710  
711 ### user entered a full dist, like: R/RC/RCAPUTO/POE-0.19.tar.gz
712 if (my ($path,$package) = $module =~ m|^/?(.+)/(.+)$|) {
713 my @data = $cb->search( type => 'package',
714 allow => [qr/^$package$/] );
715 my @list = $cb->search( type => 'path',
716 allow => [qr/$path$/i],
717 data => \@data);
718  
719 ### make sure we don't list the same dist twice
720 my $seen;
721 for my $val ( @list ) {
722 next if $seen->{$val->package}++;
723  
724 push @rv, $val;
725 }
726 }
727 }
728 }
729  
730 return $self->_pp_distribution(
731 result => \@rv,
732 class => $class,
733 short => $short,
734 input => $input );
735 }
736  
737 sub _find_all {
738 my $self = shift;
739  
740 my @rv;
741 for my $method (qw[_author _bundle _module _distribution]) {
742 my $aref = $self->$method( @_, short => 1 );
743  
744 push @rv, @$aref if $aref;
745 }
746  
747 print scalar(@rv). " items found\n"
748 }
749  
750 sub _uptodate {
751 my $self = shift;
752 my $cb = $self->backend;
753 my %hash = @_;
754  
755 my($aref, $short, $input, $class);
756 my $tmpl = {
757 result => { store => \$aref, default => ['/./'] },
758 short => { default => 0, store => \$short },
759 input => { default => 'all', store => \$input },
760 class => { default => 'Uptodate', no_override => 1,
761 store => \$class },
762 };
763  
764 check( $tmpl, \%hash ) or return;
765  
766  
767 my @rv;
768 if( @$aref) {
769 for my $module (@$aref) {
770 if( $module =~ m|/(.+)/| ) {
771 my @list = $cb->search( type => 'module',
772 allow => [qr/$1/i] );
773  
774 ### only add those that are installed and not core
775 push @rv, grep { not $_->package_is_perl_core }
776 grep { $_->installed_file }
777 @list;
778  
779 } else {
780 my $obj = $cb->module_tree( $module ) or next;
781 push @rv, $obj;
782 }
783 }
784 } else {
785 @rv = @{$cb->_all_installed};
786 }
787  
788 return $self->_pp_uptodate(
789 result => \@rv,
790 class => $class,
791 short => $short,
792 input => $input );
793 }
794  
795 sub _ls {
796 my $self = shift;
797 my $cb = $self->backend;
798 my %hash = @_;
799  
800 my($aref, $short, $input, $class);
801 my $tmpl = {
802 result => { store => \$aref, default => [] },
803 short => { default => 0, store => \$short },
804 input => { default => 'all', store => \$input },
805 class => { default => 'Uptodate', no_override => 1,
806 store => \$class },
807 };
808  
809 check( $tmpl, \%hash ) or return;
810  
811 my @rv;
812 for my $name (@$aref) {
813 my $auth = $cb->author_tree( uc $name );
814  
815 unless( $auth ) {
816 print qq[ls command rejects argument $name: not an author\n];
817 next;
818 }
819  
820 push @rv, $auth->distributions;
821 }
822  
823 return $self->_pp_ls(
824 result => \@rv,
825 class => $class,
826 short => $short,
827 input => $input );
828 }
829  
830 ############################
831 ### pretty printing subs ###
832 ############################
833  
834  
835 sub _pp_author {
836 my $self = shift;
837 my %hash = @_;
838  
839 my( $aref, $short, $class, $input );
840 my $tmpl = {
841 result => { required => 1, default => [], strict_type => 1,
842 store => \$aref },
843 short => { default => 0, store => \$short },
844 class => { required => 1, store => \$class },
845 input => { required => 1, store => \$input },
846 };
847  
848 check( $tmpl, \%hash ) or return;
849  
850 ### no results
851 if( !@$aref ) {
852 print "No objects of type $class found for argument $input\n"
853 unless $short;
854  
855 ### one result, long output desired;
856 } elsif( @$aref == 1 and !$short ) {
857  
858 ### should look like this:
859 #cpan> a KANE
860 #Author id = KANE
861 # EMAIL boumans@frg.eur.nl
862 # FULLNAME Jos Boumans
863  
864 my $obj = shift @$aref;
865  
866 print "$class id = ", $obj->cpanid(), "\n";
867 printf " %-12s %s\n", 'EMAIL', $obj->email();
868 printf " %-12s %s%s\n", 'FULLNAME', $obj->author();
869  
870 } else {
871  
872 ### should look like this:
873 #Author KANE (Jos Boumans)
874 #Author LBROCARD (Leon Brocard)
875 #2 items found
876  
877 for my $obj ( @$aref ) {
878 printf qq[%-15s %s ("%s" (%s))\n],
879 $class, $obj->cpanid, $obj->author, $obj->email;
880 }
881 print scalar(@$aref)." items found\n" unless $short;
882 }
883  
884 return $aref;
885 }
886  
887 sub _pp_module {
888 my $self = shift;
889 my %hash = @_;
890  
891 my( $aref, $short, $class, $input );
892 my $tmpl = {
893 result => { required => 1, default => [], strict_type => 1,
894 store => \$aref },
895 short => { default => 0, store => \$short },
896 class => { required => 1, store => \$class },
897 input => { required => 1, store => \$input },
898 };
899  
900 check( $tmpl, \%hash ) or return;
901  
902  
903 ### no results
904 if( !@$aref ) {
905 print "No objects of type $class found for argument $input\n"
906 unless $short;
907  
908 ### one result, long output desired;
909 } elsif( @$aref == 1 and !$short ) {
910  
911  
912 ### should look like this:
913 #Module id = LWP
914 # DESCRIPTION Libwww-perl
915 # CPAN_USERID GAAS (Gisle Aas <gisle@ActiveState.com>)
916 # CPAN_VERSION 5.64
917 # CPAN_FILE G/GA/GAAS/libwww-perl-5.64.tar.gz
918 # DSLI_STATUS RmpO (released,mailing-list,perl,object-oriented)
919 # MANPAGE LWP - The World-Wide Web library for Perl
920 # INST_FILE C:\Perl\site\lib\LWP.pm
921 # INST_VERSION 5.62
922  
923 my $obj = shift @$aref;
924 my $aut_obj = $obj->author;
925 my $format = " %-12s %s%s\n";
926  
927 print "$class id = ", $obj->module(), "\n";
928 printf $format, 'DESCRIPTION', $obj->description()
929 if $obj->description();
930  
931 printf $format, 'CPAN_USERID', $aut_obj->cpanid() . " (" .
932 $aut_obj->author() . " <" . $aut_obj->email() . ">)";
933  
934 printf $format, 'CPAN_VERSION', $obj->version();
935 printf $format, 'CPAN_FILE', $obj->path() . '/' . $obj->package();
936  
937 printf $format, 'DSLI_STATUS', $self->_pp_dslip($obj->dslip)
938 if $obj->dslip() =~ /\w/;
939  
940 #printf $format, 'MANPAGE', $obj->foo();
941 ### this is for bundles... CPAN.pm downloads them,
942 #printf $format, 'CONATAINS,
943 # parses and goes from there...
944  
945 printf $format, 'INST_FILE', $obj->installed_file ||
946 '(not installed)';
947 printf $format, 'INST_VERSION', $obj->installed_version;
948  
949  
950  
951 } else {
952  
953 ### should look like this:
954 #Module LWP (G/GA/GAAS/libwww-perl-5.64.tar.gz)
955 #Module POE (R/RC/RCAPUTO/POE-0.19.tar.gz)
956 #2 items found
957  
958 for my $obj ( @$aref ) {
959 printf "%-15s %-15s (%s)\n", $class, $obj->module(),
960 $obj->path() .'/'. $obj->package();
961 }
962 print scalar(@$aref). " items found\n" unless $short;
963 }
964  
965 return $aref;
966 }
967  
968 sub _pp_dslip {
969 my $self = shift;
970 my $dslip = shift or return;
971  
972 my (%_statusD, %_statusS, %_statusL, %_statusI);
973  
974 @_statusD{qw(? i c a b R M S)} =
975 qw(unknown idea pre-alpha alpha beta released mature standard);
976  
977 @_statusS{qw(? m d u n)} =
978 qw(unknown mailing-list developer comp.lang.perl.* none);
979  
980 @_statusL{qw(? p c + o h)} = qw(unknown perl C C++ other hybrid);
981 @_statusI{qw(? f r O h)} =
982 qw(unknown functions references+ties object-oriented hybrid);
983  
984 my @status = split("", $dslip);
985  
986 my $results = sprintf( "%s (%s,%s,%s,%s)",
987 $dslip,
988 $_statusD{$status[0]},
989 $_statusS{$status[1]},
990 $_statusL{$status[2]},
991 $_statusI{$status[3]}
992 );
993  
994 return $results;
995 }
996  
997 sub _pp_distribution {
998 my $self = shift;
999 my $cb = $self->backend;
1000 my %hash = @_;
1001  
1002 my( $aref, $short, $class, $input );
1003 my $tmpl = {
1004 result => { required => 1, default => [], strict_type => 1,
1005 store => \$aref },
1006 short => { default => 0, store => \$short },
1007 class => { required => 1, store => \$class },
1008 input => { required => 1, store => \$input },
1009 };
1010  
1011 check( $tmpl, \%hash ) or return;
1012  
1013  
1014 ### no results
1015 if( !@$aref ) {
1016 print "No objects of type $class found for argument $input\n"
1017 unless $short;
1018  
1019 ### one result, long output desired;
1020 } elsif( @$aref == 1 and !$short ) {
1021  
1022  
1023 ### should look like this:
1024 #Distribution id = S/SA/SABECK/POE-Component-Client-POP3-0.02.tar.gz
1025 # CPAN_USERID SABECK (Scott Beck <scott@gossamer-threads.com>)
1026 # CONTAINSMODS POE::Component::Client::POP3
1027  
1028 my $obj = shift @$aref;
1029 my $aut_obj = $obj->author;
1030 my $pkg = $obj->package;
1031 my $format = " %-12s %s\n";
1032  
1033 my @list = $cb->search( type => 'package',
1034 allow => [qr/^$pkg$/] );
1035  
1036  
1037 print "$class id = ", $obj->path(), '/', $obj->package(), "\n";
1038 printf $format, 'CPAN_USERID',
1039 $aut_obj->cpanid .' ('. $aut_obj->author .
1040 ' '. $aut_obj->email .')';
1041  
1042 ### yes i know it's ugly, but it's what cpan.pm does
1043 printf $format, 'CONTAINSMODS', join (' ', map { $_->module } @list);
1044  
1045 } else {
1046  
1047 ### should look like this:
1048 #Distribution LWP (G/GA/GAAS/libwww-perl-5.64.tar.gz)
1049 #Distribution POE (R/RC/RCAPUTO/POE-0.19.tar.gz)
1050 #2 items found
1051  
1052 for my $obj ( @$aref ) {
1053 printf "%-15s %s\n", $class, $obj->path() .'/'. $obj->package();
1054 }
1055  
1056 print scalar(@$aref). " items found\n" unless $short;
1057 }
1058  
1059 return $aref;
1060 }
1061  
1062 sub _pp_uptodate {
1063 my $self = shift;
1064 my $cb = $self->backend;
1065 my %hash = @_;
1066  
1067 my( $aref, $short, $class, $input );
1068 my $tmpl = {
1069 result => { required => 1, default => [], strict_type => 1,
1070 store => \$aref },
1071 short => { default => 0, store => \$short },
1072 class => { required => 1, store => \$class },
1073 input => { required => 1, store => \$input },
1074 };
1075  
1076 check( $tmpl, \%hash ) or return;
1077  
1078 my $format = "%-25s %9s %9s %s\n";
1079  
1080 my @not_uptodate;
1081 my $no_version;
1082  
1083 my %seen;
1084 for my $mod (@$aref) {
1085 next if $mod->package_is_perl_core;
1086 next if $seen{ $mod->package }++;
1087  
1088  
1089 if( $mod->installed_file and not $mod->installed_version ) {
1090 $no_version++;
1091 next;
1092 }
1093  
1094 push @not_uptodate, $mod unless $mod->is_uptodate;
1095 }
1096  
1097 unless( @not_uptodate ) {
1098 my $string = $input
1099 ? "for $input"
1100 : '';
1101 print "All modules are up to date $string\n";
1102 return;
1103  
1104 } else {
1105 printf $format, ( 'Package namespace',
1106 'installed',
1107 'latest',
1108 'in CPAN file'
1109 );
1110 }
1111  
1112 for my $mod ( sort { $a->module cmp $b->module } @not_uptodate ) {
1113 printf $format, ( $mod->module,
1114 $mod->installed_version,
1115 $mod->version,
1116 $mod->path .'/'. $mod->package,
1117 );
1118 }
1119  
1120 print "$no_version installed modules have no (parsable) version number\n"
1121 if $no_version;
1122  
1123 return \@not_uptodate;
1124 }
1125  
1126 sub _pp_ls {
1127 my $self = shift;
1128 my $cb = $self->backend;
1129 my %hash = @_;
1130  
1131 my( $aref, $short, $class, $input );
1132 my $tmpl = {
1133 result => { required => 1, default => [], strict_type => 1,
1134 store => \$aref },
1135 short => { default => 0, store => \$short },
1136 class => { required => 1, store => \$class },
1137 input => { required => 1, store => \$input },
1138 };
1139  
1140 check( $tmpl, \%hash ) or return;
1141  
1142 ### should look something like this:
1143 #6272 2002-05-12 KANE/Acme-Comment-1.00.tar.gz
1144 #8171 2002-08-13 KANE/Acme-Comment-1.01.zip
1145 #7110 2002-09-04 KANE/Acme-Comment-1.02.tar.gz
1146 #7571 2002-09-08 KANE/Acme-Intraweb-1.01.tar.gz
1147 #6625 2001-08-23 KANE/Acme-POE-Knee-1.10.zip
1148 #3058 2003-10-05 KANE/Acme-Test-0.02.tar.gz
1149  
1150 ### don't know size or mtime
1151 #my $format = "%8d %10s %s/%s\n";
1152  
1153 for my $mod ( sort { $a->package cmp $b->package } @$aref ) {
1154 print "\t" . $mod->package . "\n";
1155 }
1156  
1157 return $aref;
1158 }
1159  
1160  
1161 #############################
1162 ### end pretty print subs ###
1163 #############################
1164  
1165  
1166 sub _bang {
1167 my $self = shift;
1168 my %hash = @_;
1169  
1170 my( $input );
1171 my $tmpl = {
1172 input => { required => 1, store => \$input },
1173 };
1174  
1175 check( $tmpl, \%hash ) or return;
1176  
1177 eval $input;
1178 warn $@ if $@;
1179  
1180 print "\n";
1181  
1182 return;
1183 }
1184  
1185 sub _help {
1186 print qq[
1187 Display Information
1188 a authors
1189 b string display bundles
1190 d or info distributions
1191 m /regex/ about modules
1192 i or anything of above
1193 r none reinstall recommendations
1194 u uninstalled distributions
1195  
1196 Download, Test, Make, Install...
1197 get download
1198 make make (implies get)
1199 test modules, make test (implies make)
1200 install dists, bundles make install (implies test)
1201 clean make clean
1202 look open subshell in these dists' directories
1203 readme display these dists' README files
1204  
1205 Other
1206 h,? display this menu ! perl-code eval a perl command
1207 o conf [opt] set and query options q quit the cpan shell
1208 reload cpan load CPAN.pm again reload index load newer indices
1209 autobundle Snapshot force cmd unconditionally do cmd
1210 ];
1211  
1212 }
1213  
1214  
1215  
1216 1;
1217 __END__