Permalink
Browse files

Moved Repository class selection handling to A::B::MB, this allows fo…

…r proper constructor interitance for A::B::MB::R and subclasses
  • Loading branch information...
1 parent e637d98 commit d3435ce235ef68ab3e335fd6f71c15c34d4c261b @jberger jberger committed Mar 7, 2012
View
@@ -1,25 +1,40 @@
Build.PL
+examples/Alien-DontPanic/Build.PL
+examples/Alien-DontPanic/inc/dontpanic-1.01.tar.gz
+examples/Alien-DontPanic/lib/Alien/DontPanic.pm
+examples/Alien-DontPanic/MANIFEST
examples/Alien-GSL/Build.PL
examples/Alien-GSL/lib/Alien/GSL.pm
examples/Alien-GSL/MANIFEST
+examples/Ford-Prefect/Build.PL
+examples/Ford-Prefect/lib/Ford/Prefect.pm
+examples/Ford-Prefect/lib/Ford/Prefect.xs
+examples/Ford-Prefect/MANIFEST
lib/Alien/Base.pm
+lib/Alien/Base/Authoring.pod
lib/Alien/Base/ModuleBuild.pm
lib/Alien/Base/ModuleBuild/Cabinet.pm
lib/Alien/Base/ModuleBuild/File.pm
lib/Alien/Base/ModuleBuild/Repository.pm
lib/Alien/Base/ModuleBuild/Repository/FTP.pm
lib/Alien/Base/ModuleBuild/Repository/HTTP.pm
-lib/Alien/Base/ModuleBuild/Repository/TEST.pm
+lib/Alien/Base/ModuleBuild/Repository/Local.pm
+lib/Alien/Base/ModuleBuild/Repository/Test.pm
lib/Alien/Base/ModuleBuild/Utils.pm
+lib/Alien/Base/PkgConfig.pm
MANIFEST This list of files
README
t/cabinet.t
t/file.t
t/http.t
t/interpolate.t
+t/local_repo.t
+t/pkgconfig.t
t/pkgconfig/gsl.pc
+t/pkgconfig/test.pc
t/repository.t
t/utils.t
t/validation.t
t/version.t
+t/zz-example.t
TODO
@@ -16,7 +16,7 @@ L<Alien::Base::ModuleBuild> provides a base class, utility methods and configura
# file: Alien-MyLibrary/Build.PL
use Alien::Base::ModuleBuild;
- my $builder = Alien::Base::ModuleBuild->new({...});
+ my $builder = Alien::Base::ModuleBuild->new(...);
$builder->create_build_script;
This is just like you would do for L<Module::Build>, except that there will be a few additional configuration parameters (see L<Alien::Base::ModuleBuild::API>).
@@ -11,10 +11,25 @@ use File::Spec;
use Carp;
use Archive::Extract;
-use Alien::Base::ModuleBuild::Repository;
+use Alien::Base::PkgConfig;
use Alien::Base::ModuleBuild::Cabinet;
+use Alien::Base::ModuleBuild::Repository;
-use Alien::Base::PkgConfig;
+use Alien::Base::ModuleBuild::Repository::HTTP;
+use Alien::Base::ModuleBuild::Repository::FTP;
+use Alien::Base::ModuleBuild::Repository::Test;
+use Alien::Base::ModuleBuild::Repository::Local;
+
+# setup protocol specific classes
+# Alien:: author can override these defaults using alien_repository_class property
+our %Repository_Class;
+my %default_repository_class = (
+ default => 'Alien::Base::ModuleBuild::Repository',
+ http => 'Alien::Base::ModuleBuild::Repository::HTTP',
+ ftp => 'Alien::Base::ModuleBuild::Repository::FTP',
+ test => 'Alien::Base::ModuleBuild::Repository::Test',
+ local => 'Alien::Base::ModuleBuild::Repository::Local',
+);
our $VERSION = 0.01;
$VERSION = eval $VERSION;
@@ -65,8 +80,10 @@ __PACKAGE__->add_property( 'alien_provides_libs' );
# |-- [platform]*: hashref of above keys for specific case (overrides defaults)
# |
# |-- (non-api) connection: holder for Net::FTP-like object (needs cwd, ls, and get methods)
+__PACKAGE__->add_property( 'alien_repository' => {} );
__PACKAGE__->add_property( 'alien_repository_default' => {} );
-__PACKAGE__->add_property( 'alien_repository' );
+__PACKAGE__->add_property( 'alien_repository_class' => {} );
+
################
# ConfigData #
@@ -86,6 +103,12 @@ sub new {
my $install_dir = $args{alien_share_dir} || '_install';
my $cleanup_install_dir = 0;
+ # merge default and user-defined repository classes
+ foreach my $protocol (keys %default_repository_class) {
+ next if defined $args{alien_repository_class}{$protocol};
+ $args{alien_repository_class}{$protocol} = $default_repository_class{$protocol};
+ }
+
# initialize M::B property share_dir
if (! defined $args{share_dir}) {
# no share_dir property
@@ -138,8 +161,9 @@ sub alien_create_repositories {
}
$repo->{platform} = 'src' unless defined $repo->{platform};
+ my $protocol = $repo->{protocol} || 'default';
- push @repos, Alien::Base::ModuleBuild::Repository->new( $repo );
+ push @repos, $self->alien_repository_class($protocol)->new( $repo );
}
# check validation, including c compiler for src type
@@ -10,37 +10,11 @@ use Module::Loaded qw/is_loaded/;
use Alien::Base::ModuleBuild::File;
use Alien::Base::ModuleBuild::Utils qw/pattern_has_capture_groups/;
-use Alien::Base::ModuleBuild::Repository::HTTP;
-use Alien::Base::ModuleBuild::Repository::FTP;
-use Alien::Base::ModuleBuild::Repository::TEST;
-use Alien::Base::ModuleBuild::Repository::LOCAL;
-
-# setup protocol specific classes
-# Alien:: author can override these defaults using package variable
-our %Repository_Class;
-my %default_repository_class = (
- HTTP => 'Alien::Base::ModuleBuild::Repository::HTTP',
- FTP => 'Alien::Base::ModuleBuild::Repository::FTP',
- TEST => 'Alien::Base::ModuleBuild::Repository::TEST',
- LOCAL => 'Alien::Base::ModuleBuild::Repository::LOCAL',
-);
-foreach my $type (keys %default_repository_class) {
- $Repository_Class{$type} ||= $default_repository_class{$type};
-}
-
sub new {
my $class = shift;
- my ($self) = @_;
-
- my $protocol = $self->{protocol} = uc $self->{protocol};
- croak "Unsupported protocol: $protocol"
- unless exists $Repository_Class{$protocol};
+ my (%self) = ref $_[0] ? %{ shift() } : @_;
- my $obj = bless $self, $Repository_Class{$protocol};
-
- if ($obj->can('init')) {
- $obj->init;
- }
+ my $obj = bless \%self, $class;
return $obj;
}
@@ -1,4 +1,4 @@
-package Alien::Base::ModuleBuild::Repository::LOCAL;
+package Alien::Base::ModuleBuild::Repository::Local;
use strict;
use warnings;
@@ -10,8 +10,10 @@ use File::Spec;
use parent 'Alien::Base::ModuleBuild::Repository';
-sub init {
- my $self = shift;
+sub new {
+ my $class = shift;
+
+ my $self = $class->SUPER::new(@_);
# make location absolute
local $CWD = $self->location;
@@ -1,4 +1,4 @@
-package Alien::Base::ModuleBuild::Repository::TEST;
+package Alien::Base::ModuleBuild::Repository::Test;
use strict;
use warnings;
View
@@ -7,10 +7,9 @@ use File::Basename qw/fileparse/;
use File::Temp;
use File::chdir;
-use Alien::Base::ModuleBuild::Repository::LOCAL;
+use Alien::Base::ModuleBuild::Repository::Local;
-my $repo = bless { location => 't' }, 'Alien::Base::ModuleBuild::Repository::LOCAL';
-$repo->init; # this hack fixes the internal representation of location, usually called by Repository->new
+my $repo = Alien::Base::ModuleBuild::Repository::Local->new({ location => 't' });
my @files = $repo->list_files;
my $this_file = fileparse __FILE__;
View
@@ -2,7 +2,7 @@ use strict;
use warnings;
use Test::More;
-use_ok( 'Alien::Base::ModuleBuild::Repository' );
+use Alien::Base::ModuleBuild::Repository::Test;
my $default = {
protocol => 'test',
@@ -11,7 +11,7 @@ my $default = {
};
{
- my $repo = Alien::Base::ModuleBuild::Repository->new($default);
+ my $repo = Alien::Base::ModuleBuild::Repository::Test->new($default);
my @filenames = $repo->list_files;
@@ -24,7 +24,7 @@ my $default = {
{
my $pattern = qr/^gsl-[\d\.]+\.tar\.gz$/;
local $default->{pattern} = $pattern;
- my $repo = Alien::Base::ModuleBuild::Repository->new($default);
+ my $repo = Alien::Base::ModuleBuild::Repository::Test->new($default);
my @filenames = grep { $_ =~ $pattern } $repo->list_files;
@@ -38,7 +38,7 @@ my $default = {
{
my $pattern = qr/^gsl-([\d\.]+)\.tar\.gz$/;
local $default->{pattern} = $pattern;
- my $repo = Alien::Base::ModuleBuild::Repository->new($default);
+ my $repo = Alien::Base::ModuleBuild::Repository::Test->new($default);
my @filenames = grep { $_ =~ $pattern } $repo->list_files;

0 comments on commit d3435ce

Please sign in to comment.