Skip to content

Commit

Permalink
Can now load other Project::/VC:: modules from @inc if bundled module…
Browse files Browse the repository at this point in the history
…s fail
  • Loading branch information
jbarratt committed Feb 27, 2010
1 parent b741ca6 commit 2039723
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/ShipIt/ProjectType.pm
Expand Up @@ -2,6 +2,7 @@ package ShipIt::ProjectType;
use strict;
use ShipIt::ProjectType::Perl;
use ShipIt::ProjectType::AutoConf;
use ShipIt::Util qw(find_subclasses);

=head1 NAME
Expand Down Expand Up @@ -37,6 +38,12 @@ sub new {
$pt = ShipIt::ProjectType::AutoConf->new;
return $pt if $pt;

for my $class (grep {!/::(Perl|AutoConf)$/} find_subclasses($class)) {
eval "CORE::require $class";
$pt = $class->new;
return $pt if $pt;
}

die "Unknown project type. Can't find Makefile.PL, Build.PL, configure.ac, etc..";
}

Expand Down
16 changes: 15 additions & 1 deletion lib/ShipIt/Util.pm
Expand Up @@ -4,7 +4,7 @@ use Carp qw(croak confess);
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(slurp write_file bool_prompt edit_file $term make_var tempdir_obj
in_dir);
find_subclasses in_dir);
use Term::ReadLine ();
use File::Temp ();
use File::Path ();
Expand Down Expand Up @@ -62,6 +62,20 @@ sub make_var {
return $1;
}

sub find_subclasses {
# search for any other custom project type modules
my $class = shift;
my @classes = ();
for my $dir (@INC) {
for my $file (glob("$dir/" . join("/", split(/::/, $class)) . "/*.pm")) {
if($file =~ /\/(\w+)\.pm/) {
push(@classes, "$class" . "::" . "$1");
}
}
}
return @classes;
}

# returns either $obj or ($obj->dir, $obj), when in list context.
# when $obj goes out of scope, all temp directory contents are wiped.
sub tempdir_obj {
Expand Down
8 changes: 8 additions & 0 deletions lib/ShipIt/VC.pm
Expand Up @@ -41,6 +41,14 @@ sub new {
return ShipIt::VC::Git->new($conf) if -e ".git";
return ShipIt::VC::Mercurial->new($conf) if -e ".hg";
return ShipIt::VC::SVK->new($conf) if $class->is_svk_co;

# look for any custom modules with an expensive search after exhausting the known ones
for my $class (grep {!/::(SVN|Git|Mercurial|SVK)$/} find_subclasses($class)) {
eval "CORE::require $class";
my $vc = $class->new($conf);
return $vc if $vc;
}

die "Unknown/undetected version control system. Currently only svn/svk/git/hg are supported.";
}

Expand Down

0 comments on commit 2039723

Please sign in to comment.