Permalink
Browse files

Initial commit for CPAN-Mini-Visit-Simple. Partially complete constru…

…ctor and corresponding tests. No other methods yet.
  • Loading branch information...
0 parents commit 008f2eec1266c432bda4f7733f7e8efefacf2055 @jkeenan committed Feb 19, 2010
Showing with 595 additions and 0 deletions.
  1. +6 −0 Changes
  2. +383 −0 LICENSE
  3. +8 −0 MANIFEST
  4. +19 −0 Makefile.PL
  5. +11 −0 README
  6. +5 −0 Todo
  7. +104 −0 lib/CPAN/Mini/Visit/Simple.pm
  8. +59 −0 t/001_new.t
@@ -0,0 +1,6 @@
+Revision history for Perl module CPAN::Mini::Visit::Simple
+
+0.01 Thu Feb 18 20:19:30 2010
+ - original version; created by ExtUtils::ModuleMaker 0.51
+
+
Oops, something went wrong.
@@ -0,0 +1,8 @@
+MANIFEST
+README
+LICENSE
+Todo
+Changes
+Makefile.PL
+lib/CPAN/Mini/Visit/Simple.pm
+t/001_new.t
@@ -0,0 +1,19 @@
+
+
+use ExtUtils::MakeMaker;
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
+# the contents of the Makefile that is written.
+WriteMakefile(
+ NAME => 'CPAN::Mini::Visit::Simple',
+ VERSION_FROM => 'lib/CPAN/Mini/Visit/Simple.pm', # finds \$VERSION
+ AUTHOR => 'James E Keenan (jkeenan@cpan.org)',
+ ABSTRACT => 'Lightweight traversal of a minicpan repository',
+ PREREQ_PM => {
+ 'CPAN::Mini' => 0,
+ 'File::Find' => 0,
+ 'File::Temp' => 0.14,
+ 'Path::Class' => 0,
+ 'Scalar::Util' => 0,
+ 'Test::Simple' => 0.44,
+ },
+);
@@ -0,0 +1,11 @@
+README for Perl extension CPAN-Mini-Visit-Simple
+
+CPAN::Mini::Visit::Simple - Lightweight traversal of a minicpan repository.
+This is a variant on David Golden's App-CPAN-Mini-Visit.
+
+perl Makefile.PL
+make
+make test
+make install
+
+If you are on a windows box you should use 'nmake' rather than 'make'.
@@ -0,0 +1,5 @@
+TODO list for Perl module CPAN::Mini::Visit::Simple
+
+Almost everything! Constructor is incomplete; no other methods yet written.
+
+
@@ -0,0 +1,104 @@
+package CPAN::Mini::Visit::Simple;
+use 5.010;
+use strict;
+use warnings;
+
+our $VERSION = '0.001';
+$VERSION = eval $VERSION; ## no critic
+
+use Carp;
+use CPAN::Mini ();
+use File::Find;
+use Data::Dumper;$Data::Dumper::Indent=1;
+use Path::Class qw/ dir file /;
+use Scalar::Util qw/ reftype /;
+
+sub new {
+ my ($class, $args) = @_;
+ my %data = ();
+ if ( ! $args->{minicpan} ) {
+ my %config = CPAN::Mini->read_config;
+ if ( $config{local} ) {
+# print STDERR Dumper \%config;
+ $data{minicpan} = $config{local};
+ }
+ }
+ else {
+ $data{minicpan} = $args->{minicpan};
+ }
+ croak "Directory $data{minicpan} not found"
+ unless (-d $data{minicpan});
+
+ my $id_dir = dir($data{minicpan}, qw/authors id/);
+ croak "Absence of $id_dir implies no valid minicpan"
+ unless -d $id_dir;
+ $data{id_dir} = $id_dir;
+
+ if ( defined $args->{list} ) {
+ croak "Value of 'list' must be array reference"
+ unless reftype($args->{list}) eq 'ARRAY';
+ croak "Value of 'list' must be non-empty"
+ unless scalar(@{$args->{list}});
+ $data{list} = $args->{list};
+ }
+ if ( ! exists $data{list} ) {
+ if ( defined $args->{start_dir} ) {
+ croak "Directory $args->{start_dir} not found"
+ unless (-d $args->{start_dir} );
+ }
+ else {
+ $data{start_dir} = $data{minicpan};
+ }
+ }
+
+ my $self = bless \%data, $class;
+ return $self;
+}
+
+1;
+# The preceding line will help the module return a true value
+
+=head1 NAME
+
+CPAN::Mini::Visit::Simple - Lightweight traversal of a minicpan repository
+
+=head1 SYNOPSIS
+
+ use CPAN::Mini::Visit::Simple;
+ blah blah blah
+
+
+=head1 DESCRIPTION
+
+This is a variant on David Golden's App-CPAN-Mini-Visit.
+
+=head1 USAGE
+
+=head1 BUGS
+
+=head1 SUPPORT
+
+=head1 AUTHOR
+
+ James E Keenan
+ CPAN ID: jkeenan
+ Perl Seminar NY
+ jkeenan@cpan.org
+ http://thenceforward.net/perl/modules/CPAN-Mini-Visit-Simple/
+
+=head1 COPYRIGHT
+
+This program is free software; you can redistribute
+it and/or modify it under the same terms as Perl itself.
+
+The full text of the license can be found in the
+LICENSE file included with this module.
+
+
+=head1 SEE ALSO
+
+perl(1). App-CPAN-Mini-Visit.
+
+=cut
+
+
@@ -0,0 +1,59 @@
+# -*- perl -*-
+
+# t/001_new.t - check module loading and create testing directory
+
+use Carp;
+use File::Temp qw( tempdir );
+use Path::Class qw( dir );
+use Test::More qw(no_plan); # tests => 3;
+
+BEGIN { use_ok( 'CPAN::Mini::Visit::Simple' ); }
+
+my $self;
+
+$self = CPAN::Mini::Visit::Simple->new({});
+isa_ok ($self, 'CPAN::Mini::Visit::Simple');
+
+my $phony_minicpan = '/foo/bar';
+eval {
+ $self = CPAN::Mini::Visit::Simple->new({
+ minicpan => $phony_minicpan,
+ });
+};
+like($@, qr/Directory $phony_minicpan not found/,
+ "Got expected error message for non-existent minicpan directory" );
+
+my $tdir = tempdir();
+my $id_dir = dir($tdir, qw/authors id/);
+eval {
+ $self = CPAN::Mini::Visit::Simple->new({
+ minicpan => $tdir,
+ });
+};
+like($@, qr/Absence of $id_dir implies no valid minicpan/,
+ "Got expected error message for malformed minicpan repository" );
+
+eval {
+ $self = CPAN::Mini::Visit::Simple->new({
+ list => {},
+ });
+};
+like($@, qr/Value of 'list' must be array reference/,
+ "Got expected error message for bad 'list' value -- must be array ref" );
+
+eval {
+ $self = CPAN::Mini::Visit::Simple->new({
+ list => [],
+ });
+};
+like($@, qr/Value of 'list' must be non-empty/,
+ "Got expected error message for bad 'list' value -- must be non-empty array ref" );
+
+eval {
+ $self = CPAN::Mini::Visit::Simple->new({
+ start_dir => $phony_minicpan,
+ });
+};
+like($@, qr/Directory $phony_minicpan not found/,
+ "Got expected error message for bad 'start_dir' value" );
+

0 comments on commit 008f2ee

Please sign in to comment.