diff --git a/bin/darkpan-inject b/bin/darkpan-inject index afa9789..bb14eed 100644 --- a/bin/darkpan-inject +++ b/bin/darkpan-inject @@ -1,7 +1,50 @@ #!/usr/bin/perl +# ABSTRACT: Generate and inject files into your darkpan use strict; use warnings; use CPAN::Dark; -CPAN::Dark->new->inject_files( @ARGV ); +use Getopt::Long 2.38; + +my $author; +GetOptions("as=s" => \$author); + +my $darkpan = CPAN::Dark->new; + +$author ? $darkpan->inject_files_as( $author, @ARGV ) : $darkpan->inject_files( @ARGV ); + +__END__ + +=pod + +=head1 NAME + +darkpan-inject - Generate and inject files into your darkpan + +=head1 SYNOPSIS + + # Inject files as the default author given in the configuration + darkpan-inject MyDistribution-0.001.tar.gz MyOtherDistribution-0.010.tar.gz + + # Inject files as a specific author, only one can be given + darkpan-inject --as GETTY MyDistribution-Web-0.020.tar.gz MyOtherDistribution-Web-1.200.tar.gz + +=head1 DESCRIPTION + +Please read L first to understand the concept of a DarkPAN and +for getting the information how to configure those commands so that you can +use them to startup your own DarkPAN. + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +chromatic C<< chromatic at wgz dot org >> + +=head1 COPYRIGHT & LICENSE + +Copyright (c) 2011, chromatic. Redistribution and modification permitted under +the terms of the Artistic License 2.0. diff --git a/lib/CPAN/Dark.pm b/lib/CPAN/Dark.pm index 2216913..10eaafa 100644 --- a/lib/CPAN/Dark.pm +++ b/lib/CPAN/Dark.pm @@ -73,26 +73,33 @@ sub write_gz sub inject_files { my $self = shift; - $self->create_darkpan; + $self->inject_file_as($self->{cpmi}->config->{author},$_) for (@_); +} - my $cpmi = $self->{cpmi}; +sub inject_files_as +{ + my $self = shift; + my $author = shift; + $self->inject_file_as($author,$_) for (@_); +} - for my $file (@_) - { - Carp::croak( "Cannot find '$file'" ) unless $file and -e $file; +sub inject_file_as +{ + my ($self, $author, $file) = @_; + $self->create_darkpan; + Carp::croak( "Cannot find '$file'" ) unless $file and -e $file; - my $meta = $self->load_metayaml( $file ); - (my $module = $meta->{name}) =~ s/-/::/g; + my $meta = $self->load_metayaml( $file ); + (my $module = $meta->{name}) =~ s/-/::/g; - $cpmi->add( - file => $file, - module => $module, - version => $meta->{version}, - authorid => $cpmi->config->{author}, - ); - } + $self->{cpmi}->add( + file => $file, + module => $module, + version => $meta->{version}, + authorid => $author, + ); - $cpmi->writelist->inject; + $self->{cpmi}->writelist->inject; } sub load_metayaml @@ -120,6 +127,7 @@ CPAN::Dark - manage a DarkPAN installation use CPAN::Dark; CPAN::Dark->new->inject_files( @list_of_dist_tarballs ); + CPAN::Dark->new->inject_files_as( $author, @list_of_dist_tarballs ); =head1 DESCRIPTION @@ -152,6 +160,13 @@ The contents of this file must conform to the described file format, with one additional parameter. Provide the C configuration to set a default author for all injected DarkPAN distributions. +Example: + + local: /home/larry/darkpan + remote: http://localhost/ + author: LWALL + repository: /home/larry/tmp + =head1 METHODS This module provides three public methods: @@ -170,6 +185,11 @@ created and initialized, this method will attempt to create it. This method will also throw an exception if any of the given files do not exist or are not readable. +=head2 C + +The same function as I, but you can use a different author, then +given via L configuration. + =head2 C This method will create the DarkPAN represented by the current configuration, @@ -178,6 +198,8 @@ file permissions if this happens. =head1 SEE ALSO +L + L L