blib/lib/CPAN/Mini/Inject.pm

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