blib/lib/CPANPLUS.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 12 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 93 SCAR 37.4
CC
6
Cov
0%
install
12.0
fetch
12.0
shell
6.0
CRAP 42.0
1 package CPANPLUS;
2  
3 use strict;
4 use Carp;
5  
6 use CPANPLUS::Error;
7 use CPANPLUS::Backend;
8  
9 use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';
10  
11 BEGIN {
12 use Exporter ();
13 use vars qw( @EXPORT @ISA $VERSION );
14 @EXPORT = qw( shell fetch get install );
15 @ISA = qw( Exporter );
16 $VERSION = "0.9912"; #have to hardcode or cpan.org gets unhappy
17 }
18  
19 ### purely for backward compatibility, so we can call it from the commandline:
20 ### perl -MCPANPLUS -e 'install Net::SMTP'
21 sub install {
22 my $cpan = CPANPLUS::Backend->new;
23 my $mod = shift or (
24 error(loc("No module specified!")), return
25 );
26  
27 if ( ref $mod ) {
28 error( loc( "You passed an object. Use %1 for OO style interaction",
29 'CPANPLUS::Backend' ));
30 return;
31  
32 } else {
33 my $obj = $cpan->module_tree($mod) or (
34 error(loc("No such module '%1'", $mod)),
35 return
36 );
37  
38 my $ok = $obj->install;
39  
40 $ok
41 ? msg(loc("Installing of %1 successful", $mod),1)
42 : msg(loc("Installing of %1 failed", $mod),1);
43  
44 return $ok;
45 }
46 }
47  
48 ### simply downloads a module and stores it
49 sub fetch {
50 my $cpan = CPANPLUS::Backend->new;
51  
52 my $mod = shift or (
53 error(loc("No module specified!")), return
54 );
55  
56 if ( ref $mod ) {
57 error( loc( "You passed an object. Use %1 for OO style interaction",
58 'CPANPLUS::Backend' ));
59 return;
60  
61 } else {
62 my $obj = $cpan->module_tree($mod) or (
63 error(loc("No such module '%1'", $mod)),
64 return
65 );
66  
67 my $ok = $obj->fetch( fetchdir => '.' );
68  
69 $ok
70 ? msg(loc("Fetching of %1 successful", $mod),1)
71 : msg(loc("Fetching of %1 failed", $mod),1);
72  
73 return $ok;
74 }
75 }
76  
77 ### alias to fetch() due to compatibility with cpan.pm ###
78 sub get { fetch(@_) }
79  
80  
81 ### purely for backwards compatibility, so we can call it from the commandline:
82 ### perl -MCPANPLUS -e 'shell'
83 sub shell {
84 my $option = shift;
85  
86 ### since the user can specify the type of shell they wish to start
87 ### when they call the shell() function, we have to eval the usage
88 ### of CPANPLUS::Shell so we can set up all the checks properly
89 eval { require CPANPLUS::Shell; CPANPLUS::Shell->import($option) };
90 die $@ if $@;
91  
92 my $cpan = CPANPLUS::Shell->new();
93  
94 $cpan->shell();
95 }
96  
97 1;
98  
99 __END__