Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Checked in initial version.

  • Loading branch information...
commit 99ba3cad0d72b299f59fa5a235d26050b97cd94b 0 parents
@chromatic authored
2  .gitignore
@@ -0,0 +1,2 @@
+!.gitignore
+^CPAN-Dark-*
2  Changes
@@ -0,0 +1,2 @@
+{{$NEXT}}
+ - first release to an unsuspecting but hopeful world
7 bin/darkpan-inject
@@ -0,0 +1,7 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use CPAN::Dark;
+CPAN::Dark->new->inject_files( @ARGV );
27 dist.ini
@@ -0,0 +1,27 @@
+name = CPAN-Dark
+author = chromatic <chromatic@wgz.org>
+license = Perl_5
+copyright_holder = chromatic <chromatic@wgz.org>
+copyright_year = 2011
+
+[@Basic]
+
+[AutoPrereqs]
+[PkgVersion]
+[NextRelease]
+
+[AutoVersion]
+format = 1.{{ cldr('yyyyMMdd') }}.{{ cldr('HHmm') }}
+
+[PodWeaver]
+finder = :InstallModules
+
+[@Git]
+changelog = Changes ; this is the default
+allow_dirty = dist.ini ; see Git::Check...
+allow_dirty = Changes ; ... and Git::Commit
+commit_msg = v%v%n%n%c ; see Git::Commit
+tag_format = %v ; see Git::Tag
+tag_message = %v ; see Git::Tag
+push_to = origin ; see Git::Push
+push_to = neworigin
109 lib/CPAN/Dark.pm
@@ -0,0 +1,109 @@
+package CPAN::Dark;
+# ABSTRACT: manages a DarkPAN installation
+
+use strict;
+use warnings;
+
+use Carp;
+use YAML 0.73;
+use File::Path 2.08;
+use Path::Class 0.24;
+use List::Util 1.20, 'first';
+use Archive::Tar 1.76;
+use Compress::Zlib 2.035;
+use CPAN::Mini::Inject 0.29;
+
+sub new
+{
+ bless { cpmi => CPAN::Mini::Inject->new->parsecfg }, shift;
+}
+
+sub create_darkpan
+{
+ my $self = shift;
+ my $cpmi = $self->{cpmi};
+
+ return unless my $repo = $self->should_create_repository;
+
+ File::Path::mkpath( [ dir( $repo, 'authors' ), dir( $repo, 'modules' ) ] );
+
+ $self->write_gz( file( $repo, 'authors', '01mailrc.txt.gz' ), '' );
+ $self->write_gz( file( $repo, 'modules', '02packages.details.txt.gz' ),
+ <<END_PACKAGE_HEADER );
+File: 02packages.details.txt
+URL: http://cpan.perl.org/modules/02packages.details.txt.gz
+Description: Package names found in directory \$CPAN/authors/id/
+Columns: package name, version, path
+Intended-For: Automated fetch routines, namespace documentation.
+Written-By: CPAN::Dark $CPAN::Dark::VERSION
+Line-Count: 0
+Last-Updated: ${ \localtime() }
+END_PACKAGE_HEADER
+
+}
+
+sub should_create_repository
+{
+ my $self = shift;
+ my $cpmi = $self->{cpmi};
+ my $repo = $cpmi->config->get( 'local' );
+
+ Carp::croak( "No DarkPAN configured!" ) unless $repo;
+
+ return $repo unless -d $repo;
+ return $repo unless -f file( $repo, 'authors', '01mailrc.txt.gz' );
+ return $repo unless -f
+ file( $repo, 'modules', '02packages.details.txt.gz' );
+
+ return;
+}
+
+sub write_gz
+{
+ my ($self, $file, $contents) = @_;
+
+ Carp::croak( "Cannot write to '$file': $!" )
+ unless my $fh = $file->open( '>' );
+
+ my $gz = Compress::Zlib::gzopen( $fh, 'wb' );
+ $gz->gzwrite( $contents );
+ $gz->gzclose;
+}
+
+sub inject_files
+{
+ my $self = shift;
+ $self->create_darkpan;
+
+ my $cpmi = $self->{cpmi};
+
+ for my $file (@_)
+ {
+ Carp::croak( "Cannot find '$file'" ) unless $file and -e $file;
+
+ 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},
+ );
+ }
+
+ $cpmi->writelist->inject;
+}
+
+sub load_metayaml
+{
+ my ($self, $file) = @_;
+
+ my $tar = Archive::Tar->new;
+ $tar->read( $file );
+
+ return unless my $meta_file = first { /META\.yml$/ } $tar->list_files;
+ return YAML::Load( $tar->get_content( $meta_file ) );
+}
+
+1;
14 t/create_repo.t
@@ -0,0 +1,14 @@
+#! perl
+
+use Test::More;
+
+main();
+exit;
+
+sub main
+{
+ my $module = 'CPAN::Dark';
+ use_ok( $module ) or exit;
+
+ done_testing();
+}
14 t/inject_dists.t
@@ -0,0 +1,14 @@
+#! perl
+
+use Test::More;
+
+main();
+exit;
+
+sub main
+{
+ my $module = 'CPAN::Dark';
+ use_ok( $module ) or exit;
+
+ done_testing();
+}
Please sign in to comment.
Something went wrong with that request. Please try again.