File Coverage

lib/CPANPLUS.pm
Criterion Covered Total %
statement 50 50 100.0
branch 15 18 83.3
condition n/a
subroutine 12 12 100.0
pod 4 4 100.0
total 81 84 96.4


line stmt bran cond sub pod time code
1             package CPANPLUS;
2              
3 20     20   142 use strict;
  20         46  
  20         918  
4 20     20   166 use Carp;
  20         44  
  20         1603  
5              
6 20     20   169 use CPANPLUS::Error;
  20         35  
  20         1454  
7 20     20   8201 use CPANPLUS::Backend;
  20         86  
  20         1410  
8              
9 20     20   165 use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';
  20         38  
  20         124  
10              
11             BEGIN {
12 20     20   5744 use Exporter ();
  20         45  
  20         658  
13 20     20   106 use vars qw( @EXPORT @ISA $VERSION );
  20         38  
  20         1953  
14 20     20   180 @EXPORT = qw( shell fetch get install );
15 20         395 @ISA = qw( Exporter );
16 20         9481 $VERSION = "0.9916"; #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 4     4 1 47 my $cpan = CPANPLUS::Backend->new;
23 4 100       26 my $mod = shift or (
24             error(loc("No module specified!")), return
25             );
26              
27 3 100       9 if ( ref $mod ) {
28 1         6 error( loc( "You passed an object. Use %1 for OO style interaction",
29             'CPANPLUS::Backend' ));
30 1         15 return;
31              
32             } else {
33 2 50       8 my $obj = $cpan->module_tree($mod) or (
34             error(loc("No such module '%1'", $mod)),
35             return
36             );
37              
38 2         8 my $ok = $obj->install;
39              
40 2 100       27 $ok
41             ? msg(loc("Installing of %1 successful", $mod),1)
42             : msg(loc("Installing of %1 failed", $mod),1);
43              
44 2         45 return $ok;
45             }
46             }
47              
48             ### simply downloads a module and stores it
49             sub fetch {
50 8     8 1 133 my $cpan = CPANPLUS::Backend->new;
51              
52 8 100       54 my $mod = shift or (
53             error(loc("No module specified!")), return
54             );
55              
56 6 100       22 if ( ref $mod ) {
57 2         10 error( loc( "You passed an object. Use %1 for OO style interaction",
58             'CPANPLUS::Backend' ));
59 2         50 return;
60              
61             } else {
62 4 50       19 my $obj = $cpan->module_tree($mod) or (
63             error(loc("No such module '%1'", $mod)),
64             return
65             );
66              
67 4         17 my $ok = $obj->fetch( fetchdir => '.' );
68              
69 4 100       38 $ok
70             ? msg(loc("Fetching of %1 successful", $mod),1)
71             : msg(loc("Fetching of %1 failed", $mod),1);
72              
73 4         42 return $ok;
74             }
75             }
76              
77             ### alias to fetch() due to compatibility with cpan.pm ###
78 4     4 1 55 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 1     1 1 1406 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 1         3 eval { require CPANPLUS::Shell; CPANPLUS::Shell->import($option) };
  1         973  
  1         11  
90 1 50       5 die $@ if $@;
91              
92 1         15 my $cpan = CPANPLUS::Shell->new();
93              
94 1         34 $cpan->shell();
95             }
96              
97             1;
98              
99             __END__