blib/lib/CPAN/Mini/Inject.pm

filter: Statementstmt 99.1% 245 / 247 Branchbran 72.8% 67 / 92 Conditioncond 44.0% 11 / 25 MC/DCmcdc 14.2% 2 / 14 Subroutinesub 97.6% 41 / 42 Podpod 100% 14 / 14 totaltotal 87.5% 380 / 434 CC 64 SCAR 18.5
CC
64
Cov
89%
update_mirror
23.9
testremote
9.5
inject
8.2
CRAP 6.3
↑ Summary blib/lib/CPAN/Mini/Inject/Config.pm »
1 package CPAN::Mini::Inject;
2  
3 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 13 ▶use CPAN::Checksums qw( updatedir );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use CPAN::Mini;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use CPAN::Mini::Inject::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use Compress::Zlib;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use Env;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 13 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 13 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 13 ▶use File::Path qw( make_path );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 13 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 13 ▶use LWP::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 =head1 NAME
19  
20 CPAN::Mini::Inject - Inject modules into a CPAN::Mini mirror.
21  
22 =head1 VERSION
23  
24 Version 0.28_02
25  
26 =cut
27  
28 13 our $VERSION = '0.28_02';
29 13 our @ISA = qw( CPAN::Mini );
30  
31 =head1 Synopsis
32  
33 If you're not going to customize the way CPAN::Mini::Inject works you
34 probably want to look at the mcpani command instead.
35  
36 use CPAN::Mini::Inject;
37  
38 $mcpi=CPAN::Mini::Inject->new;
39 $mcpi->parsecfg('t/.mcpani/config');
40  
41 $mcpi->add( module => 'CPAN::Mini::Inject',
42 authorid => 'SSORICHE',
43 version => ' 0.01',
44 file => 'mymodules/CPAN-Mini-Inject-0.01.tar.gz' )
45  
46 $mcpi->writelist;
47 $mcpi->update_mirror;
48 $mcpi->inject;
49  
50 =head1 DESCRIPTION
51  
52 CPAN::Mini::Inject uses CPAN::Mini to build or update a local CPAN mirror
53 then adds modules from your repository to it, allowing the inclusion
54 of private modules in a minimal CPAN mirror.
55  
56 =head1 METHODS
57  
58 Each method in CPAN::Mini::Inject returns a CPAN::Mini::Inject object which
59 allows method chaining. For example:
60  
61 my $mcpi=CPAN::Mini::Inject->new;
62 $mcpi->parsecfg
63 ->update_mirror
64 ->inject;
65  
66 A C<CPAN::Mini::Inject> ISA L<CPAN::Mini>. Refer to the
67 L<documentation|CPAN::Mini> for that module for details of the interface
68 C<CPAN::Mini::Inject> inherits from it.
69  
70 =head2 C<new>
71  
72 Create a new CPAN::Mini::Inject object.
73  
74 =cut
75  
76 sub new {
77 17 ▶ return bless
Subroutine new: called CC=1 SCAR=0.0
Pod documented
78 { config_class => 'CPAN::Mini::Inject::Config' },
79 $_[0];
80 }
81  
82 =head2 C<< config_class( [CLASS] ) >>
83  
84 Returns the name of the class handling the configuration.
85  
86 With an argument, it sets the name of the class to handle
87 the config. To use that, you'll have to call it before you
88 load the configuration.
89  
90 =cut
91  
92 sub config_class {
93 16 ▶ my $self = shift;
Subroutine config_class: called CC=2 SCAR=7.6
Pod documented
94  
95 16 ▶ if ( @_ ) { $self->{config_class} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 16 16
96  
97 16 $self->{config_class};
98 }
99  
100 =head2 C<< config >>
101  
102 Returns the configuration object. This object should be from
103 the class returned by C<config_class> unless you've done something
104 wierd.
105  
106 =cut
107  
108 sub config {
109 89 ▶ my $self = shift;
Subroutine config: called CC=2 SCAR=6.9
Pod documented
110  
111 89 ▶ if ( @_ ) { $self->{config} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 7 82 89
112  
113 89 $self->{config};
114 }
115  
116 =head2 C<< loadcfg( [FILENAME] ) >>
117  
118  
119 This is a bridge to CPAN::Mini::Inject::Config's loadconfig. It sets the
120 filename for the configuration, or uses one of the defaults.
121  
122 =cut
123  
124 sub loadcfg {
125 12 ▶ my $self = shift;
Subroutine loadcfg: called CC=2 SCAR=6.9
Pod documented
126  
127 12 ▶ unless ( $self->{config} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"config"}) 9 3 12
128 9 $self->{config} = $self->config_class->new;
129 }
130  
131 12 $self->{cfgfile} = $self->{config}->load_config( @_ );
132  
133 11 return $self;
134 }
135  
136 =head2 C<< parsecfg() >>
137  
138 This is a bridge to CPAN::Mini::Inject::Config's parseconfig.
139  
140 =cut
141  
142 sub parsecfg {
143 15 ▶ my $self = shift;
Subroutine parsecfg: called CC=2 SCAR=6.9
Pod documented
144  
145 15 ▶ unless ( $self->{config} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"config"}) 7 8 15
146 7 $self->config( $self->config_class->new );
147 }
148  
149 15 $self->config->parse_config( @_ );
150  
151 14 return $self;
152 }
153  
154 =head2 C<< site( [SITE] ) >>
155  
156 Returns the CPAN site that CPAN::Mini::Inject chose from the
157 list specified in the C<remote> directive.
158  
159 =cut
160  
161 sub site {
162 13 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
163 8 ▶ my $self = shift;
Subroutine site: called CC=3 SCAR=11.0
Pod documented
164  
165 8 ▶ if ( @_ ) { $self->{site} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 5 8
166  
167 8 ▶ $self->{site} || '';
Branch: 1 branch
BranchTrueFalseTotal
$self->{"site"} or "" 3 5 8
168 }
169  
170 =head2 C<testremote>
171  
172 Test each site listed in the remote parameter of the config file by performing
173 a get on each site in order for authors/01mailrc.txt.gz. The first site to
174 respond successfully is set as the instance variable site.
175  
176 print "$mcpi->{site}\n"; # ftp://ftp.cpan.org/pub/CPAN
177  
178 C<testremote> accepts an optional parameter to enable verbose mode.
179  
180 =cut
181  
182 sub testremote {
183 2 ▶ my $self = shift;
Subroutine testremote: called CC=9 SCAR=22.5
Pod documented
184 2 my $verbose = shift;
185  
186 2 ▶ $self->site( undef ) if $self->site;
Branch: 1 branch
BranchTrueFalseTotal
if $self->site 1 1 2
187  
188 2 ▶ $ENV{FTP_PASSIVE} = 1 if ( $self->config->get( 'passive' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->config->get("passive") 2 0 2
189  
190 2 for my $site ( split( /\s+/, $self->config->get( 'remote' ) ) ) {
191  
192 3 ▶ $site .= '/' unless ( $site =~ m/\/$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $site =~ m[/$] 3 0 3
193  
194 3 ▶ print "Testing site: $site\n" if ( $verbose );
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 3 3
195  
196 3 ▶ if ( get( $site . 'authors/01mailrc.txt.gz' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&get($site . 'authors/01mailrc.txt.gz')) 2 1 3
197 2 $self->site( $site );
198  
199 2 ▶ print "\n$site selected.\n" if ( $verbose );
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 2 2
200 2 last;
201 }
202 }
203  
204 2 ▶ croak "Unable to connect to any remote site" unless $self->site;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->site 0 2 2
205  
206 2 return $self;
207 }
208  
209 =head2 C<update_mirror>
210  
211 This is a subclass of CPAN::Mini.
212  
213 =cut
214  
215 sub update_mirror {
216 1 ▶ my $self = shift;
Subroutine update_mirror: called CC=12 SCAR=31.7
Pod documented
217 1 my %options = @_;
218  
219 1 ▶ croak 'Can not write to local: ' . $self->config->get( 'local' )
Branch: 1 branch
BranchTrueFalseTotal
unless -w $self->config->get("local") 0 1 1
220 unless ( -w $self->config->get( 'local' ) );
221  
222 1 ▶ $ENV{FTP_PASSIVE} = 1 if $self->config->get( 'passive' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->config->get("passive") 1 0 1
223  
224 1 ▶ $options{local} ||= $self->config->get( 'local' );
Condition33%1/3
$options{"local"} ||= $self->config->get("local")
l!l&&r!l&&!r
100
MC/DC0%0/2
$options{"local"} ||= $self->config->get("local")
$options{"local"} $self->config->get("local")
Truth table33%1/3
A ||= B
A= $options{"local"}B= $self->config->get("local")
ABresult
1X1
011
000
225 1 ▶ $options{trace} ||= 0;
Condition50%1/2
$options{"trace"} ||= 0
l!l
01
MC/DC0%0/1
$options{"trace"} ||= 0
$options{"trace"}
Truth table50%1/2
A
A= $options{"trace"}
Aresult
11
00
226 1 ▶ $options{skip_perl} ||= $self->config->get( 'perl' ) || 1;
Condition40%2/5
$options{"skip_perl"} ||= $self->config->get("perl") || 1
l!l&&r!l&&!r
010
$self->config->get('perl') || 1
l!l
01
MC/DC0%0/2
$options{"skip_perl"} ||= $self->config->get("perl") || 1
$options{"skip_perl"} $self->config->get('perl')
Truth table0%0/3
A ||= B
A= $options{"skip_perl"}B= $self->config->get('perl')
ABresult
1X1
011
000
227  
228 $self->testremote( $options{trace} )
229 1 ▶ unless ( $self->site || $options{remote} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->site or $options{"remote"} 0 1 1
Condition33%1/3
$self->site or $options{"remote"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->site or $options{"remote"}
$self->site $options{"remote"}
Truth table33%1/3
A or B
A= $self->siteB= $options{"remote"}
ABresult
1X1
011
000
230 1 ▶ $options{remote} ||= $self->site;
Condition33%1/3
$options{"remote"} ||= $self->site
l!l&&r!l&&!r
100
MC/DC0%0/2
$options{"remote"} ||= $self->site
$options{"remote"} $self->site
Truth table33%1/3
A ||= B
A= $options{"remote"}B= $self->site
ABresult
1X1
011
000
231  
232 1 ▶ $options{dirmode} ||= oct( $self->config->get( 'dirmode' )
Condition33%2/6
$options{"dirmode"} ||= oct($self->config->get("dirmode") || sprintf("0%o", 511 & ~(umask)))
l!l&&r!l&&!r
010
$self->config->get('dirmode') || sprintf('0%o', 511 & ~(umask))
l!l&&r!l&&!r
100
MC/DC0%0/3
$options{"dirmode"} ||= oct($self->config->get("dirmode") || sprintf("0%o", 511 & ~(umask)))
$options{"dirmode"} $self->config->get('dirmode') sprintf('0%o', 511 & ~(umask))
Truth table0%0/4
A ||= B || C
A= $options{"dirmode"}B= $self->config->get('dirmode')C= sprintf('0%o', 511 & ~(umask))
ABCresult
1XX1
01X1
0011
0000
233 || sprintf( '0%o', 0777 & ~umask ) );
234  
235 1 CPAN::Mini->update_mirror( %options );
236 }
237  
238 =head2 C<add>
239  
240 Add a new module to the repository. The add method copies the module
241 file into the repository with the same structure as a CPAN site. For
242 example CPAN-Mini-Inject-0.01.tar.gz is copied to
243 MYCPAN/authors/id/S/SS/SSORICHE. add creates the required directory
244 structure below the repository.
245  
246  
247 =over 4
248  
249 =item * module
250  
251 The name of the module to add.
252  
253 =item * authorid
254  
255 CPAN author id. This does not have to be a real author id.
256  
257 =item * version
258  
259 The modules version number.
260  
261 =item * file
262  
263 The tar.gz of the module.
264  
265 =back
266  
267 =head3 Example
268  
269 add( module => 'Module::Name',
270 authorid => 'AUTHOR',
271 version => 0.01,
272 file => './Module-Name-0.01.tar.gz' );
273  
274 =cut
275  
276 sub add {
277 7 ▶ my $self = shift;
Subroutine add: called CC=7 SCAR=19.5
Pod documented
278 7 my %options = @_;
279  
280 7 my $optionchk
281 = _optionchk( \%options, qw/module authorid version file/ );
282  
283 7 ▶ croak "Required option not specified: $optionchk" if $optionchk;
Branch: 1 branch
BranchTrueFalseTotal
if $optionchk 1 6 7
284 6 ▶ croak "No repository configured"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->config->get("repository") 1 5 6
285 unless ( $self->config->get( 'repository' ) );
286 5 ▶ croak "Can not write to repository: "
Branch: 1 branch
BranchTrueFalseTotal
unless -w $self->config->get("repository") 0 5 5
287 . $self->config->get( 'repository' )
288 unless ( -w $self->config->get( 'repository' ) );
289  
290 croak "Can not read module file: $options{file}"
291 5 ▶ unless -r $options{file};
Branch: 1 branch
BranchTrueFalseTotal
unless -r $options{"file"} 1 4 5
292  
293 4 my $modulefile = basename( $options{file} );
294 4 ▶ $self->readlist unless exists( $self->{modulelist} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"modulelist"} 1 3 4
295  
296 4 $options{authorid} = uc( $options{authorid} );
297 $self->{authdir} = $self->_authordir( $options{authorid},
298 4 $self->config->get( 'repository' ) );
299  
300 my $target
301 = $self->config->get( 'repository' )
302 . '/authors/id/'
303 . $self->{authdir} . '/'
304 4 . basename( $options{file} );
305  
306 4 ▶ copy( $options{file}, dirname( $target ) )
Branch: 1 branch
BranchTrueFalseTotal
copy($options{"file"}, dirname($target)) or croak("Copy failed: $!") 0 4 4
307 or croak "Copy failed: $!";
308  
309 4 $self->_updperms( $target );
310  
311 # remove old version from the list
312 4 @{ $self->{modulelist} }
313 4 = grep { $_ !~ m/\A$options{module}\s+/ } @{ $self->{modulelist} };
314  
315 push(
316 4 @{ $self->{modulelist} },
317 _fmtmodule(
318 $options{module}, File::Spec::Unix->catfile( File::Spec->splitdir( $self->{authdir} ), $modulefile ),
319 $options{version}
320 )
321 4 );
322  
323 4 return $self;
324 }
325  
326 =head2 C<inject>
327  
328 Insert modules from the repository into the local CPAN::Mini mirror. inject
329 copies each module into the appropriate directory in the CPAN::Mini mirror
330 and updates the CHECKSUMS file.
331  
332 Passing a value to C<inject> enables verbose mode, which lists each module
333 as it's injected.
334  
335 =cut
336  
337 sub inject {
338 1 ▶ my $self = shift;
Subroutine inject: called CC=8 SCAR=21.1
Pod documented
339 1 my $verbose = shift;
340  
341 1 ▶ my $dirmode = oct( $self->config->get( 'dirmode' ) )
Branch: 1 branch
BranchTrueFalseTotal
if $self->config->get("dirmode") 1 0 1
342 if ( $self->config->get( 'dirmode' ) );
343  
344 1 ▶ $self->readlist unless ( exists( $self->{modulelist} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"modulelist"} 0 1 1
345  
346 1 my %updatedir;
347 1 for my $modline ( @{ $self->{modulelist} } ) {
348 1 my ( $module, $version, $file ) = split( /\s+/, $modline );
349 1 my $target = $self->config->get( 'local' ) . '/authors/id/' . $file;
350 1 my $source
351 = $self->config->get( 'repository' ) . '/authors/id/' . $file;
352  
353 1 $updatedir{ dirname( $file ) } = 1;
354  
355 1 my $tdir = dirname $target;
356 1 ▶ _make_path( $tdir, defined $dirmode ? { mode => $dirmode } : {} );
Branch: 1 branch
BranchTrueFalseTotal
defined $dirmode ? : 1 0 1
357 1 ▶ copy( $source, $tdir )
Branch: 1 branch
BranchTrueFalseTotal
copy($source, $tdir) or croak("Copy $source to $tdir failed: $!") 0 1 1
358 or croak "Copy $source to $tdir failed: $!";
359  
360 1 $self->_updperms( $target );
361 1 ▶ print "$target ... injected\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 1 1
362 }
363  
364 1 for my $dir ( keys( %updatedir ) ) {
365 1 my $authdir = $self->config->get( 'local' ) . "/authors/id/$dir";
366  
367 1 updatedir( $authdir );
368 1 $self->_updperms( "$authdir/CHECKSUMS" );
369 }
370  
371 1 $self->updpackages;
372 1 $self->updauthors;
373  
374 1 return $self;
375 }
376  
377 =head2 C<updpackages>
378  
379 Update the CPAN::Mini mirror's modules/02packages.details.txt.gz with the
380 injected module information.
381  
382 =cut
383  
384 sub updpackages {
385 1 ▶ my $self = shift;
Subroutine updpackages: called CC=1 SCAR=0.0
Pod documented
386  
387 1 my @modules = sort( @{ $self->{modulelist} } );
388  
389 1 my $packages = $self->_readpkgs;
390  
391 1 $packages = _uniq( $packages, \@modules );
392  
393 1 $self->_writepkgs( $packages );
394  
395 }
396  
397 =head2 C<updauthors>
398  
399 Update the CPAN::Mini mirror's authors/01mailrc.txt.gz with
400 stub information should the author not actually exist on CPAN
401  
402 =cut
403  
404 sub updauthors {
405 1 ▶ my $self = shift;
Subroutine updauthors: called CC=4 SCAR=13.9
Pod documented
406  
407 1 my $repo_authors = $self->_readauthors;
408 my %author_ids_in_repo = map {
409 1 my ( $id ) = $_ =~ /alias \s+ (\S+)/xms;
410 4 $id => 1;
411 } @$repo_authors;
412  
413 1 my @authors;
414 my %authors_added;
415 AUTHOR:
416 1 for my $modline ( @{ $self->{modulelist} } ) {
417 1 my ( $module, $version, $file ) = split( /\s+/, $modline );
418  
419 # extract the author from the path
420 1 my @dirs = File::Spec->splitdir( $file );
421 1 my $author = $dirs[2];
422  
423 1 ▶ next AUTHOR if defined $author_ids_in_repo{$author};
Branch: 1 branch
BranchTrueFalseTotal
if defined $author_ids_in_repo{$author} 0 1 1
424 1 ▶ next AUTHOR if defined $authors_added{$author};
Branch: 1 branch
BranchTrueFalseTotal
if defined $authors_added{$author} 0 1 1
425  
426 1 push @$repo_authors,
427 sprintf( 'alias %-10s "Custom Non-CPAN author <CENSORED>"',
428 $author );
429 1 $authors_added{$author} = 1;
430 }
431  
432 1 $self->_writeauthors( $repo_authors );
433  
434 }
435  
436 =head2 C<readlist>
437  
438 Load the repository's modulelist.
439  
440 =cut
441  
442 sub _repo_file {
443 6 ▶ File::Spec->catfile( shift->config->get( 'repository' ), @_ );
Subroutine _repo_file: called CC=1 SCAR=0.0
444 }
445  
446 6 ▶sub _modulelist { shift->_repo_file( 'modulelist' ) }
Subroutine _modulelist: called CC=1 SCAR=0.0
447  
448 sub readlist {
449 6 ▶ my $self = shift;
Subroutine readlist: called CC=4 SCAR=13.9
Pod documented
450  
451 6 $self->{modulelist} = undef;
452  
453 6 my $ml = $self->_modulelist;
454 6 ▶ return $self unless -e $ml;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $ml 3 3 6
455  
456 3 ▶ open MODLIST, '<', $ml or croak "Can not read module list: $ml ($!)";
Branch: 1 branch
BranchTrueFalseTotal
open MODLIST, "<", $ml or croak("Can not read module list: $ml ($!)") 1 2 3
457 2 ▶ while ( <MODLIST> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline MODLIST)) 6 2 8
458 6 chomp;
459 6 push @{ $self->{modulelist} }, $_;
460 }
461 2 close MODLIST;
462  
463 2 return $self;
464 }
465  
466 =head2 C<writelist>
467  
468 Write to the repository modulelist.
469  
470 =cut
471  
472 sub writelist {
473 3 ▶ my $self = shift;
Subroutine writelist: called CC=5 SCAR=16.1
Pod documented
474  
475 croak 'Can not write module list: '
476 . $self->config->get( 'repository' )
477 . "/modulelist ERROR: $!"
478 unless ( -w $self->{config}{repository} . '/modulelist'
479 3 ▶ || -w $self->{config}{repository} );
Branch: 1 branch
BranchTrueFalseTotal
unless -w $self->{"config"}{"repository"} . '/modulelist' or -w $self->{"config"}{"repository"} 1 2 3
Condition100%3/3
-w $self->{"config"}{"repository"} . '/modulelist' or -w $self->{"config"}{"repository"}
l!l&&r!l&&!r
111
MC/DC100%2/2
-w $self->{"config"}{"repository"} . '/modulelist' or -w $self->{"config"}{"repository"}
-w $self->{"config"}{"repository"} . '/modulelist' -w $self->{"config"}{"repository"}
Truth table100%3/3
A or B
A= -w $self->{"config"}{"repository"} . '/modulelist'B= -w $self->{"config"}{"repository"}
ABresult
1X1
011
000
480 2 ▶ return $self unless defined( $self->{modulelist} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"modulelist"} 0 2 2
481  
482 2 open( MODLIST,
483 '>' . $self->config->get( 'repository' ) . '/modulelist' );
484 2 for ( sort( @{ $self->{modulelist} } ) ) {
485 5 chomp;
486 5 print MODLIST "$_\n";
487 }
488 2 close( MODLIST );
489  
490 2 $self->_updperms(
491 $self->config->get( 'repository' ) . '/modulelist' );
492  
493 2 return $self;
494 }
495  
496 sub _updperms {
497 8 ▶ my ( $self, $file ) = @_;
Subroutine _updperms: called CC=2 SCAR=7.2
498  
499 8 ▶ chmod oct( $self->config->get( 'dirmode' ) ) & 06666, $file
Branch: 1 branch
BranchTrueFalseTotal
if $self->config->get("dirmode") 8 0 8
500 if $self->config->get( 'dirmode' );
501 }
502  
503 sub _optionchk {
504 7 ▶ my ( $options, @list ) = @_;
Subroutine _optionchk: called CC=3 SCAR=11.0
505 7 my @missing;
506  
507 7 for my $option ( @list ) {
508 push @missing, $option
509 28 ▶ unless defined $$options{$option};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options->{$option} 1 27 28
510 }
511  
512 7 return join ' ', @missing;
513 }
514  
515 sub _make_path {
516 5 ▶ my $um = umask 0;
Subroutine _make_path: called CC=1 SCAR=0.0
517 5 make_path( @_ );
518 5 umask $um;
519 }
520  
521 sub _authordir {
522 4 ▶ my ( $self, $author, $dir ) = @_;
Subroutine _authordir: called CC=2 SCAR=7.0
523  
524 my @author
525 4 = ( substr( $author, 0, 1 ), substr( $author, 0, 2 ), $author );
526  
527 4 my $dm = $self->config->get( 'dirmode' );
528 my @new
529 4 ▶ = _make_path( File::Spec->catdir( $dir, 'authors', 'id', @author ),
Branch: 1 branch
BranchTrueFalseTotal
defined $dm ? : 4 0 4
530 defined $dm ? { mode => oct $dm } : {} );
531  
532 4 return return File::Spec->catdir( @author );
533 }
534  
535 sub _fmtmodule {
536 6 ▶ my ( $module, $file, $version ) = @_;
Subroutine _fmtmodule: called CC=2 SCAR=6.9
537 6 my $fw = 38 - length $version;
538 6 ▶ $fw = length $module if $fw < length $module;
Branch: 1 branch
BranchTrueFalseTotal
if $fw < length $module 1 5 6
539 6 return sprintf "%-${fw}s %s %s", $module, $version, $file;
540 }
541  
542 0 ▶sub _cfg { $_[0]->{config}{ $_[1] } }
Subroutine _cfg: not called CC=1 SCAR=6.9
543  
544 sub _readpkgs {
545 1 ▶ my $self = shift;
Subroutine _readpkgs: called CC=5 SCAR=16.1
546  
547 1 ▶ my $gzread = gzopen(
Branch: 1 branch
BranchTrueFalseTotal
my $gzread = &gzopen($self->config->get("local") . '/modules/02packages.details.txt.gz', "rb") or croak("Cannot open local 02packages.details.txt.gz: $CPAN::Mini::Inject::gzerrno") 0 1 1
548 $self->config->get( 'local' )
549 . '/modules/02packages.details.txt.gz', 'rb'
550 ) or croak "Cannot open local 02packages.details.txt.gz: $gzerrno";
551  
552 1 my $inheader = 1;
553 1 my @packages;
554 my $package;
555  
556 1 ▶ while ( $gzread->gzreadline( $package ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gzread->gzreadline($package)) 14 1 15
557 14 ▶ if ( $inheader ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inheader) 9 5 14
558 9 ▶ $inheader = 0 unless $package =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $package =~ /\S/ 1 8 9
559 9 next;
560 }
561 5 chomp( $package );
562 5 push( @packages, $package );
563 }
564  
565 1 $gzread->gzclose;
566  
567 1 return \@packages;
568 }
569  
570 sub _writepkgs {
571 1 ▶ my $self = shift;
Subroutine _writepkgs: called CC=3 SCAR=11.0
572 1 my $pkgs = shift;
573  
574 1 ▶ my $gzwrite = gzopen(
Branch: 1 branch
BranchTrueFalseTotal
my $gzwrite = &gzopen($self->config->get("local") . '/modules/02packages.details.txt.gz', "wb") or croak("Can't open local 02packages.details.txt.gz for writing: $CPAN::Mini::Inject::gzerrno") 0 1 1
575 $self->config->get( 'local' )
576 . '/modules/02packages.details.txt.gz', 'wb'
577 )
578 or croak
579 "Can't open local 02packages.details.txt.gz for writing: $gzerrno";
580  
581 1 $gzwrite->gzwrite( "File: 02packages.details.txt\n" );
582 1 $gzwrite->gzwrite(
583 "URL: http://www.perl.com/CPAN/modules/02packages.details.txt\n"
584 );
585 1 $gzwrite->gzwrite(
586 'Description: Package names found in directory $CPAN/authors/id/'
587 . "\n" );
588 1 $gzwrite->gzwrite( "Columns: package name, version, path\n" );
589 1 $gzwrite->gzwrite(
590 "Intended-For: Automated fetch routines, namespace documentation.\n"
591 );
592 1 $gzwrite->gzwrite( "Written-By: CPAN::Mini::Inject $VERSION\n" );
593 1 $gzwrite->gzwrite( "Line-Count: " . scalar( @$pkgs ) . "\n" );
594 # Last-Updated: Sat, 19 Mar 2005 19:49:10 GMT
595 1 $gzwrite->gzwrite( "Last-Updated: " . _fmtdate() . "\n\n" );
596  
597 1 $gzwrite->gzwrite( "$_\n" ) for ( @$pkgs );
598  
599 1 $gzwrite->gzclose;
600  
601 }
602  
603 sub _readauthors {
604 1 ▶ my $self = shift;
Subroutine _readauthors: called CC=3 SCAR=11.0
605 1 ▶ my $gzread
Branch: 1 branch
BranchTrueFalseTotal
my $gzread = &gzopen($self->config->get("local") . '/authors/01mailrc.txt.gz', "rb") or croak('Cannot open ' . $self->config->get("local") . "/authors/01mailrc.txt.gz: $CPAN::Mini::Inject::gzerrno") 0 1 1
606 = gzopen( $self->config->get( 'local' ) . '/authors/01mailrc.txt.gz',
607 'rb' )
608 or croak "Cannot open "
609 . $self->config->get( 'local' )
610 . "/authors/01mailrc.txt.gz: $gzerrno";
611  
612 1 my @authors;
613 my $author;
614  
615 1 ▶ while ( $gzread->gzreadline( $author ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gzread->gzreadline($author)) 4 1 5
616 4 chomp( $author );
617 4 push( @authors, $author );
618 }
619  
620 1 $gzread->gzclose;
621  
622 1 return \@authors;
623 }
624  
625 sub _writeauthors {
626 1 ▶ my $self = shift;
Subroutine _writeauthors: called CC=3 SCAR=11.1
627 1 my $authors = shift;
628  
629 1 ▶ my $gzwrite
Branch: 1 branch
BranchTrueFalseTotal
my $gzwrite = &gzopen($self->config->get("local") . '/authors/01mailrc.txt.gz', "wb") or croak("Can't open local authors/01mailrc.txt.gz for writing: $CPAN::Mini::Inject::gzerrno") 0 1 1
630 = gzopen( $self->config->get( 'local' ) . '/authors/01mailrc.txt.gz',
631 'wb' )
632 or croak
633 "Can't open local authors/01mailrc.txt.gz for writing: $gzerrno";
634  
635 1 $gzwrite->gzwrite( "$_\n" ) for ( sort @$authors );
636  
637 1 $gzwrite->gzclose;
638  
639 }
640  
641 sub _uniq {
642 1 ▶ my ( $list1, $list2 ) = @_;
Subroutine _uniq: called CC=1 SCAR=0.0
643  
644 1 my %combined = map { $_, undef } @$list1, @$list2;
645  
646 1 my @fulllist = sort( keys( %combined ) );
647 # return \@{sort(keys(%combined))};
648 1 return \@fulllist;
649 }
650  
651 sub _fmtdate {
652 1 ▶ my @date = split( /\s+/, scalar( gmtime ) );
Subroutine _fmtdate: called CC=1 SCAR=0.0
653 1 return "$date[0], $date[2] $date[1] $date[4] $date[3] GMT";
654 }
655  
656 =head1 See Also
657  
658 L<CPAN::Mini>
659  
660 =head1 Current Maintainer
661  
662 Christian Walde C<< <walde.christian@googlemail.com> >>
663  
664 =head1 Original Author
665  
666 Shawn Sorichetti, C<< <ssoriche@cpan.org> >>
667  
668 =head1 Acknowledgements
669  
670 Special thanks to David Bartle, for bringing this module up
671 to date, and resolving the reported bugs.
672  
673 Thanks to Jozef Kutej <jozef@kutej.net> for numerous patches.
674  
675 =head1 Bugs
676  
677 Please report any bugs or feature requests to
678 C<bug-cpan-mini-inject@rt.cpan.org>, or through the web interface at
679 L<http://rt.cpan.org>. I will be notified, and then you'll automatically
680 be notified of progress on your bug as I make changes.
681  
682 =head1 Copyright & License
683  
684 Copyright 2008-2009 Shawn Sorichetti, Andy Armstrong, All Rights Reserved.
685  
686 This program is free software; you can redistribute it and/or modify it
687 under the same terms as Perl itself.
688  
689 =cut
690  
691 13 1; # End of CPAN::Mini::Inject
↑ Summary blib/lib/CPAN/Mini/Inject/Config.pm »