Permalink
Browse files

remove cascading repository constructor and fixed affected tests. Thi…

…s paves the way for a true constructor for subclasses of A::B::MB::Repository
  • Loading branch information...
1 parent 4d44b36 commit e637d98f94b844a2588533054d28174ea135ae01 @jberger jberger committed Mar 7, 2012
Showing with 22 additions and 28 deletions.
  1. +2 −15 lib/Alien/Base/ModuleBuild/Repository.pm
  2. +20 −13 t/repository.t
@@ -29,21 +29,8 @@ foreach my $type (keys %default_repository_class) {
}
sub new {
- my $base = shift;
- my $self;
-
- # allow building from a base object
- my $spec = ref $_[0] ? shift : { @_ };
- if (ref $base) {
- # if first arg was an object, use it for generics
- $self = $base;
- # then override with specifics
- $self->{$_} = $spec->{$_} for keys %$spec;
-
- } else {
- # if first arg was not an object, only use specific
- $self = $spec;
- }
+ my $class = shift;
+ my ($self) = @_;
my $protocol = $self->{protocol} = uc $self->{protocol};
croak "Unsupported protocol: $protocol"
View
@@ -4,38 +4,45 @@ use warnings;
use Test::More;
use_ok( 'Alien::Base::ModuleBuild::Repository' );
-my $repo = Alien::Base::ModuleBuild::Repository->new({
+my $default = {
protocol => 'test',
host => 'ftp.gnu.org',
location => '/gnu/gsl',
-});
-
-my @filenames = $repo->list_files;
+};
{
+ my $repo = Alien::Base::ModuleBuild::Repository->new($default);
+
+ my @filenames = $repo->list_files;
+
my @files = $repo->probe();
is( scalar @files, scalar @filenames, 'without pattern, probe returns an object for each file');
isa_ok( $files[0], 'Alien::Base::ModuleBuild::File' );
}
-my $pattern = qr/^gsl-[\d\.]+\.tar\.gz$/;
-my $repo_pattern = $repo->new( pattern => $pattern );
-@filenames = grep { $_ =~ $pattern } @filenames;
-
{
- my @files = $repo_pattern->probe();
+ my $pattern = qr/^gsl-[\d\.]+\.tar\.gz$/;
+ local $default->{pattern} = $pattern;
+ my $repo = Alien::Base::ModuleBuild::Repository->new($default);
+
+ my @filenames = grep { $_ =~ $pattern } $repo->list_files;
+
+ my @files = $repo->probe();
is( scalar @files, scalar @filenames, 'with pattern, probe returns an object for each matching file');
isa_ok( $files[0], 'Alien::Base::ModuleBuild::File' );
ok( ! defined $files[0]->version, 'without capture, no version information is available');
}
-$pattern = qr/^gsl-([\d\.]+)\.tar\.gz$/;
-my $repo_pattern_capture = $repo->new( pattern => $pattern );
-
{
- my @files = $repo_pattern_capture->probe();
+ my $pattern = qr/^gsl-([\d\.]+)\.tar\.gz$/;
+ local $default->{pattern} = $pattern;
+ my $repo = Alien::Base::ModuleBuild::Repository->new($default);
+
+ my @filenames = grep { $_ =~ $pattern } $repo->list_files;
+
+ my @files = $repo->probe();
is( scalar @files, scalar @filenames, 'with pattern, probe returns an object for each matching file');
isa_ok( $files[0], 'Alien::Base::ModuleBuild::File' );

0 comments on commit e637d98

Please sign in to comment.