Skip to content

Commit

Permalink
Merge pull request #4 from Getty/master
Browse files Browse the repository at this point in the history
Added possibility to inject as a specific authorid
  • Loading branch information
chromatic committed Dec 8, 2011
2 parents f3e5c72 + 1e596ac commit b1839f1
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 16 deletions.
45 changes: 44 additions & 1 deletion 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<CPAN::Dark> 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<CPAN::Dark>
=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.
52 changes: 37 additions & 15 deletions lib/CPAN/Dark.pm
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -152,6 +160,13 @@ The contents of this file must conform to the described file format, with one
additional parameter. Provide the C<author> 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:
Expand All @@ -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<inject_files_as( $author, @tarballs )>
The same function as I<inject_files>, but you can use a different author, then
given via L<CPAN::Mini::Inject> configuration.
=head2 C<create_darkpan()>
This method will create the DarkPAN represented by the current configuration,
Expand All @@ -178,6 +198,8 @@ file permissions if this happens.
=head1 SEE ALSO
L<darkpan-inject>
L<CPAN::Mini>
L<CPAN::Mini::Inject>
Expand Down

0 comments on commit b1839f1

Please sign in to comment.