Permalink
Browse files

Extract some code from new() to identify_distros(). This so that cons…

…tructor

deals only with validation of minicpan's existence.  Add
t/002_identify_distros.t to test this method.  Add MANIFEST.SKIP.
  • Loading branch information...
1 parent 74bbc8b commit 32ae020e69e6890f103518eba8efc70b0bd28cc1 @jkeenan committed Feb 20, 2010
Showing with 139 additions and 76 deletions.
  1. +7 −5 MANIFEST
  2. +33 −0 MANIFEST.SKIP
  3. +14 −12 lib/CPAN/Mini/Visit/Simple.pm
  4. +0 −59 t/001_new.t
  5. +85 −0 t/002_identify_distros.t
View
12 MANIFEST
@@ -1,8 +1,10 @@
-MANIFEST
-README
-LICENSE
-Todo
Changes
-Makefile.PL
lib/CPAN/Mini/Visit/Simple.pm
+LICENSE
+Makefile.PL
+MANIFEST
+MANIFEST.SKIP
+README
t/001_new.t
+t/002_identify_distros.t
+Todo
View
33 MANIFEST.SKIP
@@ -0,0 +1,33 @@
+^blib/
+^Makefile$
+^Makefile\.[a-z]+$
+^pm_to_blib$
+CVS/.*
+,v$
+^tmp/
+\.old$
+\.bak$
+\.tmp$
+\.swp$
+~$
+^#
+\.shar$
+\.tar$
+\.tgz$
+\.tar\.gz$
+\.zip$
+\.DS_Store$
+_uu$
+\.svn
+bug/
+cover_db/
+coverage/
+html/
+research/
+superseded/
+svndiff/
+^.cvsignore
+^init
+^results
+^htmlify
+^.git
View
26 lib/CPAN/Mini/Visit/Simple.pm
@@ -19,7 +19,6 @@ sub new {
if ( ! $args->{minicpan} ) {
my %config = CPAN::Mini->read_config;
if ( $config{local} ) {
-# print STDERR Dumper \%config;
$data{minicpan} = $config{local};
}
}
@@ -32,34 +31,37 @@ sub new {
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;
+ $data{id_dir} = $id_dir->stringify;
+
+ my $self = bless \%data, $class;
+ return $self;
+}
+
+sub identify_distros {
+ my ($self, $args) = @_;
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};
+ $self->{list} = $args->{list};
}
- if ( ! exists $data{list} ) {
+ if ( ! exists $self->{list} ) {
if ( defined $args->{start_dir} ) {
croak "Directory $args->{start_dir} not found"
unless (-d $args->{start_dir} );
- croak "Directory $args->{start_dir} must be subdirectory of $data{id_dir}"
- unless ( $args->{start_dir} =~ m/$data{id_dir}/ );
- $data{start_dir} = $args->{start_dir};;
+ croak "Directory $args->{start_dir} must be subdirectory of $self->{id_dir}"
+ unless ( $args->{start_dir} =~ m/$self->{id_dir}/ );
+ $self->{start_dir} = $args->{start_dir};;
}
else {
- $data{start_dir} = $data{minicpan};
+ $self->{start_dir} = $self->{minicpan};
}
}
-
- my $self = bless \%data, $class;
- return $self;
}
1;
-# The preceding line will help the module return a true value
=head1 NAME
View
59 t/001_new.t
@@ -36,62 +36,3 @@ like($@, qr/Directory $phony_minicpan not found/,
"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" );
-
-{
- $tdir = tempdir();
- ok( -d $tdir, "tempdir directory created for testing" );
- $id_dir = dir($tdir, qw/authors id/);
- make_path($id_dir, { mode => 0711 });
- ok( -d $id_dir, "'authors/id' directory created for testing" );
- my $phony_start_dir = dir($tdir, qw/foo bar/);
- make_path($phony_start_dir, { mode => 0711 });
- ok( -d $phony_start_dir, "'start_dir' directory created for testing" );
- eval {
- $self = CPAN::Mini::Visit::Simple->new({
- minicpan => $tdir,
- start_dir => $phony_start_dir,
- });
- };
- like($@, qr/Directory $phony_start_dir must be subdirectory of $id_dir/,
- "Got expected error message for 'start_dir' that is not subdir of authors/id/" );
-}
-
-{
- $tdir = tempdir();
- ok( -d $tdir, "tempdir directory created for testing" );
- $id_dir = dir($tdir, qw/authors id/);
- make_path($id_dir, { mode => 0711 });
- ok( -d $id_dir, "'authors/id' directory created for testing" );
- my $start_dir = dir($id_dir, qw/foo bar/);
- make_path($start_dir, { mode => 0711 });
- ok( -d $start_dir, "'start_dir' directory created for testing" );
- $self = CPAN::Mini::Visit::Simple->new({
- minicpan => $tdir,
- start_dir => $start_dir,
- });
- isa_ok ($self, 'CPAN::Mini::Visit::Simple');
-}
-
View
85 t/002_identify_distros.t
@@ -0,0 +1,85 @@
+# -*- perl -*-
+
+# t/00_identify_distros.t - check module loading and create testing directory
+
+use Carp;
+#use Data::Dumper;
+use File::Path qw( make_path );
+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, $phony_minicpan, $tdir, $id_dir );
+
+$self = CPAN::Mini::Visit::Simple->new({});
+isa_ok ($self, 'CPAN::Mini::Visit::Simple');
+
+eval {
+ $self->identify_distros({
+ list => {},
+ });
+};
+like($@, qr/Value of 'list' must be array reference/,
+ "Got expected error message for bad 'list' value -- must be array ref" );
+
+eval {
+ $self->identify_distros({
+ list => [],
+ });
+};
+like($@, qr/Value of 'list' must be non-empty/,
+ "Got expected error message for bad 'list' value -- must be non-empty array ref" );
+
+$phony_minicpan = '/foo/bar';
+eval {
+ $self->identify_distros({
+ start_dir => $phony_minicpan,
+ });
+};
+like($@, qr/Directory $phony_minicpan not found/,
+ "Got expected error message for bad 'start_dir' value" );
+
+{
+ $tdir = tempdir();
+ ok( -d $tdir, "tempdir directory created for testing" );
+ $id_dir = dir($tdir, qw/authors id/);
+ make_path($id_dir, { mode => 0711 });
+ ok( -d $id_dir, "'authors/id' directory created for testing" );
+ my $phony_start_dir = dir($tdir, qw/foo bar/);
+ make_path($phony_start_dir, { mode => 0711 });
+ ok( -d $phony_start_dir, "'start_dir' directory created for testing" );
+ $self = CPAN::Mini::Visit::Simple->new({
+ minicpan => $tdir,
+ });
+ isa_ok ($self, 'CPAN::Mini::Visit::Simple');
+ eval {
+ $self->identify_distros({
+ start_dir => $phony_start_dir,
+ });
+ };
+ like($@, qr/Directory $phony_start_dir must be subdirectory of $id_dir/,
+ "Got expected error message for 'start_dir' that is not subdir of authors/id/" );
+}
+
+{
+ $tdir = tempdir();
+ ok( -d $tdir, "tempdir directory created for testing" );
+ $id_dir = dir($tdir, qw/authors id/);
+ make_path($id_dir, { mode => 0711 });
+ ok( -d $id_dir, "'authors/id' directory created for testing" );
+ my $start_dir = dir($id_dir, qw/foo bar/);
+ make_path($start_dir, { mode => 0711 });
+ ok( -d $start_dir, "'start_dir' directory created for testing" );
+ $self = CPAN::Mini::Visit::Simple->new({
+ minicpan => $tdir,
+ });
+ isa_ok ($self, 'CPAN::Mini::Visit::Simple');
+ $self->identify_distros({
+ start_dir => $start_dir->stringify,
+ });
+ is( $self->{'start_dir'}, $start_dir->stringify,
+ "'start_dir' was defined" );
+}
+

0 comments on commit 32ae020

Please sign in to comment.