Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #4 from Getty/master

Added possibility to inject as a specific authorid
  • Loading branch information...
commit b1839f19d260e794e7931c070608734eb1c940b5 2 parents f3e5c72 + 1e596ac
chromatic authored

Showing 2 changed files with 81 additions and 16 deletions. Show diff stats Hide diff stats

  1. +44 1 bin/darkpan-inject
  2. +37 15 lib/CPAN/Dark.pm
45 bin/darkpan-inject
... ... @@ -1,7 +1,50 @@
1 1 #!/usr/bin/perl
  2 +# ABSTRACT: Generate and inject files into your darkpan
2 3
3 4 use strict;
4 5 use warnings;
5 6
6 7 use CPAN::Dark;
7   -CPAN::Dark->new->inject_files( @ARGV );
  8 +use Getopt::Long 2.38;
  9 +
  10 +my $author;
  11 +GetOptions("as=s" => \$author);
  12 +
  13 +my $darkpan = CPAN::Dark->new;
  14 +
  15 +$author ? $darkpan->inject_files_as( $author, @ARGV ) : $darkpan->inject_files( @ARGV );
  16 +
  17 +__END__
  18 +
  19 +=pod
  20 +
  21 +=head1 NAME
  22 +
  23 +darkpan-inject - Generate and inject files into your darkpan
  24 +
  25 +=head1 SYNOPSIS
  26 +
  27 + # Inject files as the default author given in the configuration
  28 + darkpan-inject MyDistribution-0.001.tar.gz MyOtherDistribution-0.010.tar.gz
  29 +
  30 + # Inject files as a specific author, only one can be given
  31 + darkpan-inject --as GETTY MyDistribution-Web-0.020.tar.gz MyOtherDistribution-Web-1.200.tar.gz
  32 +
  33 +=head1 DESCRIPTION
  34 +
  35 +Please read L<CPAN::Dark> first to understand the concept of a DarkPAN and
  36 +for getting the information how to configure those commands so that you can
  37 +use them to startup your own DarkPAN.
  38 +
  39 +=head1 SEE ALSO
  40 +
  41 +L<CPAN::Dark>
  42 +
  43 +=head1 AUTHOR
  44 +
  45 +chromatic C<< chromatic at wgz dot org >>
  46 +
  47 +=head1 COPYRIGHT & LICENSE
  48 +
  49 +Copyright (c) 2011, chromatic. Redistribution and modification permitted under
  50 +the terms of the Artistic License 2.0.
52 lib/CPAN/Dark.pm
@@ -73,26 +73,33 @@ sub write_gz
73 73 sub inject_files
74 74 {
75 75 my $self = shift;
76   - $self->create_darkpan;
  76 + $self->inject_file_as($self->{cpmi}->config->{author},$_) for (@_);
  77 +}
77 78
78   - my $cpmi = $self->{cpmi};
  79 +sub inject_files_as
  80 +{
  81 + my $self = shift;
  82 + my $author = shift;
  83 + $self->inject_file_as($author,$_) for (@_);
  84 +}
79 85
80   - for my $file (@_)
81   - {
82   - Carp::croak( "Cannot find '$file'" ) unless $file and -e $file;
  86 +sub inject_file_as
  87 +{
  88 + my ($self, $author, $file) = @_;
  89 + $self->create_darkpan;
  90 + Carp::croak( "Cannot find '$file'" ) unless $file and -e $file;
83 91
84   - my $meta = $self->load_metayaml( $file );
85   - (my $module = $meta->{name}) =~ s/-/::/g;
  92 + my $meta = $self->load_metayaml( $file );
  93 + (my $module = $meta->{name}) =~ s/-/::/g;
86 94
87   - $cpmi->add(
88   - file => $file,
89   - module => $module,
90   - version => $meta->{version},
91   - authorid => $cpmi->config->{author},
92   - );
93   - }
  95 + $self->{cpmi}->add(
  96 + file => $file,
  97 + module => $module,
  98 + version => $meta->{version},
  99 + authorid => $author,
  100 + );
94 101
95   - $cpmi->writelist->inject;
  102 + $self->{cpmi}->writelist->inject;
96 103 }
97 104
98 105 sub load_metayaml
@@ -120,6 +127,7 @@ CPAN::Dark - manage a DarkPAN installation
120 127
121 128 use CPAN::Dark;
122 129 CPAN::Dark->new->inject_files( @list_of_dist_tarballs );
  130 + CPAN::Dark->new->inject_files_as( $author, @list_of_dist_tarballs );
123 131
124 132 =head1 DESCRIPTION
125 133
@@ -152,6 +160,13 @@ The contents of this file must conform to the described file format, with one
152 160 additional parameter. Provide the C<author> configuration to set a default
153 161 author for all injected DarkPAN distributions.
154 162
  163 +Example:
  164 +
  165 + local: /home/larry/darkpan
  166 + remote: http://localhost/
  167 + author: LWALL
  168 + repository: /home/larry/tmp
  169 +
155 170 =head1 METHODS
156 171
157 172 This module provides three public methods:
@@ -170,6 +185,11 @@ created and initialized, this method will attempt to create it. This method
170 185 will also throw an exception if any of the given files do not exist or are not
171 186 readable.
172 187
  188 +=head2 C<inject_files_as( $author, @tarballs )>
  189 +
  190 +The same function as I<inject_files>, but you can use a different author, then
  191 +given via L<CPAN::Mini::Inject> configuration.
  192 +
173 193 =head2 C<create_darkpan()>
174 194
175 195 This method will create the DarkPAN represented by the current configuration,
@@ -178,6 +198,8 @@ file permissions if this happens.
178 198
179 199 =head1 SEE ALSO
180 200
  201 +L<darkpan-inject>
  202 +
181 203 L<CPAN::Mini>
182 204
183 205 L<CPAN::Mini::Inject>

0 comments on commit b1839f1

Please sign in to comment.
Something went wrong with that request. Please try again.