File Coverage

blib/lib/WWW/Module.pm
Criterion Covered Total %
statement 49 112 43.7
branch 6 32 18.7
condition n/a
subroutine 12 14 85.7
pod 0 3 0.0
total 67 161 41.6


line stmt bran cond sub pod time code
1             package WWW::Module;
2 1     1   20476 use strict;
  1         3  
  1         35  
3 1     1   5 use warnings;
  1         1  
  1         25  
4              
5 1     1   4 use Carp;
  1         5  
  1         62  
6 1     1   983 use Data::Dumper;
  1         9277  
  1         60  
7 1     1   734 use File::HomeDir;
  1         6002  
  1         50  
8 1     1   7 use File::Spec;
  1         1  
  1         16  
9 1     1   5534 use CPAN;
  1         358794  
  1         698  
10              
11 1     1   45 use vars qw($VERSION);
  1         7  
  1         1362  
12             $VERSION = '1.00';
13              
14             my ($MAKE_LOG,$MAKE_ERR,$REQUIRE_ERR);
15             my $CPAN_HOME;
16              
17             BEGIN
18             {
19             sub do_conf{
20 0     0 0 0 my $build_dir = File::Spec->catfile($CPAN_HOME,'build');
21 0         0 my $histfile = File::Spec->catfile($CPAN_HOME,'histfile');
22 0         0 my $keep_source_where = File::Spec->catfile($CPAN_HOME,'sources');
23 0         0 my $conf = {
24             'build_cache' => q[10],
25             'build_dir' => $build_dir,
26             'cache_metadata' => q[1],
27             'commandnumber_in_prompt' => q[1],
28             'cpan_home' => $CPAN_HOME,
29             'ftp' => q[ftp],
30             'ftp_passive' => q[1],
31             'ftp_proxy' => q[],
32             'getcwd' => q[],
33             'gpg' => q[],
34             'gzip' => q[],
35             'histfile' => $histfile,
36             'histsize' => q[100],
37             'http_proxy' => q[],
38             'inactivity_timeout' => q[0],
39             'index_expire' => q[1],
40             'inhibit_startup_message' => q[1],
41             'keep_source_where' => $keep_source_where,
42             'lynx' => q[],
43             'make' => q[],
44             'make_arg' => q[],
45             'make_install_arg' => q[],
46             'make_install_make_command' => q[],
47             'makepl_arg' => q[],
48             'mbuild_arg' => q[],
49             'mbuild_install_arg' => q[],
50             'mbuild_install_build_command' => q[],
51             'mbuildpl_arg' => q[],
52             'ncftp' => q[],
53             'ncftpget' => q[],
54             'no_proxy' => q[],
55             'pager' => q[],
56             'prerequisites_policy' => q[follow],
57             'scan_cache' => q[atstart],
58             'shell' => q[],
59             'tar' => q[],
60             'term_is_latin' => q[],
61             'term_ornaments' => q[],
62             'unzip' => q[],
63             'urllist' => [q[ftp://ftp.mirrorservice.org/sites/ftp.funet.fi/pub/languages/perl/CPAN/],q[ftp://mirrors.ibiblio.org/pub/mirrors/CPAN]],
64             'wget' => q[],
65             };
66 0         0 return $conf;
67             }
68            
69             sub mk_cpan_pm {
70 1     1 0 30 my $user_cpan = File::Spec->catfile(File::HomeDir->my_home,'.cpan','CPAN');
71 1         312 $CPAN_HOME = File::Spec->catfile(File::Spec->tmpdir(),"cpan-". $>);
72 1 50       6 mk_path($CPAN_HOME) or return 0;
73              
74 1         10 my $cpanpm = File::Spec->catfile($user_cpan,'MyConfig.pm');
75 1 50       28 unless(-e $cpanpm){
76 0 0       0 mk_path($user_cpan) or return 0;
77 0         0 my $conf = do_conf();
78            
79 0 0       0 if(open(CPANPM,"> ". $cpanpm)){
80 0         0 print CPANPM Data::Dumper->Dump([$conf],['$CPAN::Config']);
81 0         0 print CPANPM "1;";
82             } else {
83 0         0 carp("Couldn't write ". $cpanpm. ": ". $!);
84 0         0 return 0;
85             }
86 0 0       0 close(CPANPM) or return 0;
87             }
88 1         8 return 1;
89             }
90            
91             sub mk_path{
92 1     1 0 6 my $path = shift;
93 1 50       32 unless(-e $path){
94 0         0 eval{File::Path::mkpath($path,0,0755)};
  0         0  
95 0 0       0 if ($@){
96 0         0 carp("Couldn't make path ". $path .": ". $@);
97 0         0 return 0;
98             }
99             }
100 1         6 return 1;
101             }
102              
103 1     1   11 mk_cpan_pm();
104 1         10 $MAKE_LOG = File::Spec->catfile($CPAN_HOME, 'make_log');
105 1         13 $MAKE_ERR = File::Spec->catfile($CPAN_HOME, 'make_err');
106 1         16 $REQUIRE_ERR = File::Spec->catfile($CPAN_HOME, 'require_err');
107 1 50       31 if(-e $MAKE_LOG){
108 0 0       0 unlink($MAKE_LOG) or carp("couldn't unlink ". $MAKE_LOG .": ". $!);
109             }
110 1 50       27 if(-e $MAKE_ERR){
111 0 0       0 unlink($MAKE_ERR) or carp("couldn't unlink ". $MAKE_ERR .": ". $!);
112             }
113 1 50       58 if(-r $REQUIRE_ERR){
114 0 0       0 unlink($REQUIRE_ERR) or carp("couldn't unlink ". $REQUIRE_ERR .": ". $!);
115             }
116             # SWITCH THESE OFF FOR CPAN DEBUGGING
117 1         3 $CPAN::Be_Silent = 1;
118 1         665 $ENV{PERL_MM_USE_DEFAULT}=1;
119             }
120              
121             sub _use
122             {
123 0     0   0 my $incname = my $modname = shift;
124 0         0 $incname =~ s/::/\//;
125 0         0 $incname .= '.pm';
126              
127 0         0 my $mod = CPAN::Shell->expand("Module",$modname);
128 0 0       0 unless ($mod->uptodate){
129             {
130 0         0 open(SAVED_OUT, ">&STDOUT");
  0         0  
131 0         0 open(SAVED_ERR, ">&STDERR");
132 0         0 close(STDOUT);
133 0         0 close(STDERR);
134              
135 0         0 open(STDOUT, ">> ". $MAKE_LOG);
136 0         0 open(STDERR, ">> ". $MAKE_ERR);
137 0         0 $mod->make();
138 0         0 close(STDOUT);
139 0         0 close(STDERR);
140              
141 0         0 open(STDOUT, ">&SAVED_OUT");
142 0         0 open(STDERR, ">&SAVED_ERR");
143 0         0 close(SAVED_OUT);
144 0         0 close(SAVED_ERR);
145             }
146 0         0 my $dist_dir = $mod->distribution()->dir();
147 0         0 unshift @INC, (File::Spec->catfile($dist_dir,'blib','arch'));
148 0         0 unshift @INC, (File::Spec->catfile($dist_dir,'blib','lib'));
149 0         0 unshift @INC, $dist_dir;
150              
151 0 0       0 if(exists $INC{$incname}){
152 0         0 carp($modname." already defined: trying to redefine");
153 0         0 delete $INC{$incname};
154             {
155 0         0 open(SAVED_OUT, ">&STDOUT");
  0         0  
156 0         0 open(SAVED_ERR, ">&STDERR");
157 0         0 close(STDOUT);
158 0         0 close(STDERR);
159            
160 0         0 open(STDOUT, ">> ". $REQUIRE_ERR);
161 0         0 open(STDERR, ">&STDOUT");
162              
163 0         0 eval("require ". $modname);
164              
165 0         0 close(STDOUT);
166 0         0 close(STDERR);
167            
168 0         0 open(STDOUT, ">&SAVED_OUT");
169 0         0 open(STDERR, ">&SAVED_ERR");
170 0         0 close(SAVED_OUT);
171 0         0 close(SAVED_ERR);
172              
173 0 0       0 carp($modname ." cannot be redefined: ". $@) if $@;
174             }
175             }
176             }
177             }
178              
179             sub import
180             {
181 1     1   19 my ($self,@imports) = @_;
182 1         4 $CPAN::Config->{cpan_home} = $CPAN_HOME;
183 1         13 $CPAN::Config->{build_dir} = File::Spec->catfile($CPAN_HOME,'build');
184 1         10 $CPAN::Config->{histfile} = File::Spec->catfile($CPAN_HOME,'histfile');
185 1         9 $CPAN::Config->{keep_source_where} = File::Spec->catfile($CPAN_HOME,'sources');
186 1         3 foreach my $module(@imports){
187 0         0 _use($module);
188             }
189 1         19 return 1;
190             }
191              
192             1;
193             __END__