Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
1  Build.PL
@@ -6,7 +6,6 @@ use Module::Build;
my $builder = Module::Build->new(
module_name => 'Alien::Base',
dist_abstract => 'A base class for Alien:: modules',
- license => 'perl',
dist_author => 'Joel A. Berger <joel.a.berger@gmail.com>',
license => 'perl',
requires => {
View
32 lib/Alien/Base/ModuleBuild.pm
@@ -40,15 +40,33 @@ sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
- my @repos =
- ( (ref $self->{alien_repository} || '') eq 'ARRAY')
- ? @{ $self->{alien_repository} }
- : $self->{alien_repository};
+ #my @repos =
+ # ( (ref $self->{alien_repository} || '') eq 'ARRAY')
+ # ? @{ $self->{alien_repository} }
+ # : $self->{alien_repository};
+
+ my $base_repo = Alien::Base::ModuleBuild::Repository->new(
+ protocol => delete $self->{alien_repository}{protocol},
+ host => delete $self->{alien_repository}{host},
+ folder => delete $self->{alien_repository}{folder},
+ pattern => delete $self->{alien_repository}{pattern},
+ );
+
+ my @platforms = keys %{ $self->{alien_repository} };
+
+ my @repos;
+ if ( @platforms ) {
+ # if plaform specifics exist, use base to build repos
+ @repos =
+ map { $base_repo->new( platform => $_, %{$self->{alien_repository}{$_}}) }
+ @platforms;
+ } else {
+ # if no platform specifics, convert base to full repo and push
+ $default_repo->{platform} = 'src';
+ push @repos, $base_repo;
+ }
# map repository constructs to A::B::MB::R objects
- @repos =
- map { Alien::Base::ModuleBuild::Repository->new($_) }
- @repos;
$self->{alien_repository} = \@repos;
View
31 lib/Alien/Base/ModuleBuild/Repository.pm
@@ -12,8 +12,23 @@ use Alien::Base::ModuleBuild::Repository::TEST;
use Alien::Base::ModuleBuild::File;
sub new {
- my $class = shift;
- my $self = ref $_[0] ? shift : { @_ };
+ 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;
+ # default to 'src' platform if not otherwise given
+ $self->{platform} = 'src' unless $self->{platform};
+
+ } else {
+ # if first arg was not an object, only use specific
+ $self = $spec;
+ }
my $protocol = $self->{protocol} = uc $self->{protocol};
croak "Unsupported protocol: $protocol"
@@ -40,16 +55,8 @@ sub folder {
sub probe {
my $self = shift;
- my $platform = shift;
-
- if (defined $platform) {
- croak "Unknown platform $platform"
- unless exists $self->{$platform};
- } else {
- $platform = 'src';
- }
- my $pattern = $self->{$platform}{pattern};
+ my $pattern = $self->{pattern};
my @files = $self->list_files();
@@ -61,7 +68,7 @@ sub probe {
@files = map { +{
repository => $self,
- platform => $platform,
+ platform => $self->{platform},
filename => $_,
} } @files;
View
8 t/repository.t
@@ -20,11 +20,11 @@ my @filenames = $repo->list_files;
}
my $pattern = qr/^gsl-[\d\.]+\.tar\.gz$/;
-$repo->{src}{pattern} = $pattern;
+my $repo_pattern = $repo->new( pattern => $pattern );
@filenames = grep { $_ =~ $pattern } @filenames;
{
- my @files = $repo->probe();
+ my @files = $repo_pattern->probe();
is( scalar @files, scalar @filenames, 'with pattern, probe returns an object for each matching file');
isa_ok( $files[0], 'Alien::Base::ModuleBuild::File' );
@@ -32,10 +32,10 @@ $repo->{src}{pattern} = $pattern;
}
$pattern = qr/^gsl-([\d\.])+\.tar\.gz$/;
-$repo->{src}{pattern} = $pattern;
+my $repo_pattern_capture = $repo->new( pattern => $pattern );
{
- my @files = $repo->probe();
+ my @files = $repo_pattern_capture->probe();
is( scalar @files, scalar @filenames, 'with pattern, probe returns an object for each matching file');
isa_ok( $files[0], 'Alien::Base::ModuleBuild::File' );

No commit comments for this range

Something went wrong with that request. Please try again.