[Bps-public-commit] r9785 - in bpsbuilder/BPB/lib/BPB: .
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Sun Dec 2 10:53:04 EST 2007
Author: sunnavy
Date: Sun Dec 2 10:52:59 2007
New Revision: 9785
Modified:
bpsbuilder/BPB/lib/BPB/Source.pm
bpsbuilder/BPB/lib/BPB/Source/Base.pm
bpsbuilder/BPB/lib/BPB/Source/CPAN.pm
bpsbuilder/BPB/lib/BPB/Source/Compressed.pm
bpsbuilder/BPB/lib/BPB/Source/FTP.pm
Log:
we can follow cpan modules' requirements now :)
Modified: bpsbuilder/BPB/lib/BPB/Source.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Source.pm Sun Dec 2 10:52:59 2007
@@ -5,13 +5,26 @@
use Carp;
use UNIVERSAL::require;
use Hash::Merge qw/merge/;
+#use BPB::Source::Base;
+#use BPB::Source::CPAN;
+#use BPB::Source::Compressed;
+#use BPB::Source::Directory;
+#use BPB::Source::HTTP;
+#use BPB::Source::FTP;
+
Hash::Merge::set_behavior('RIGHT_PRECEDENT');
our %DEFAULT = (
directory => '/tmp',
- command =>
- { compressed => 'tar', http => 'wget', ftp => 'wget', directory => 'cp' }
+ command => {
+ compressed => 'tar',
+ http => 'wget',
+ ftp => 'wget',
+ directory => 'cp',
+ },
+ follow => 1,
+ mini_perl_version => 5.008.008,
);
=head2 new
@@ -27,11 +40,9 @@
croak "need source option" unless $args{source};
my $module = 'BPB::Source::' . $type;
-
- $module->require or die $@;
-
+ print $module, "\n";
+ $module->require;
return $module->new(%args);
-
}
=head2 type
Modified: bpsbuilder/BPB/lib/BPB/Source/Base.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source/Base.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Source/Base.pm Sun Dec 2 10:52:59 2007
@@ -4,9 +4,13 @@
use strict;
use Carp;
use File::Spec;
-
-use base qw/Class::Accessor::Fast BPB::Source/;
-__PACKAGE__->mk_accessors(qw/source directory command download_directory/);
+use Module::CoreList;
+use BPB::Source;
+use BPB::Config;
+
+use base qw/Class::Accessor::Fast/;
+__PACKAGE__->mk_accessors(
+ qw/source directory command download_directory follow mini_perl_version/);
=head2 new
@@ -36,6 +40,44 @@
system($cmd);
}
+sub _follow {
+ my $self = shift;
+ my $path = shift;
+ $path = File::Spec->catfile( $path, '_require.yml' );
+
+ if ( -e $path ) {
+ if ( my $require = BPB::Config::LoadFile($path) ) {
+ while ( my ( $module, $version ) = each %$require ) {
+
+ # we don't want to require perl
+ if ( $module eq 'perl' ) {
+ delete $require->{$module};
+ next;
+ }
+ if ( Module::CoreList->first_release( $module, $version )
+ && Module::CoreList->first_release( $module, $version )
+ le $self->mini_perl_version )
+ {
+ delete $require->{$module};
+ }
+ else {
+ unless ( grep /$module/, glob $self->directory ) {
+ my $cpan =
+ BPB::Source->new( %$self, source => $module );
+ $cpan->run();
+ }
+ }
+ }
+
+ BPB::Config::DumpFile( $path, $require );
+ }
+ else {
+ croak "invalid _require.yml file: $path";
+ }
+ }
+
+}
+
1;
__END__
Modified: bpsbuilder/BPB/lib/BPB/Source/CPAN.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source/CPAN.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Source/CPAN.pm Sun Dec 2 10:52:59 2007
@@ -15,18 +15,24 @@
=cut
+my $require_path;
+
sub run {
my $self = shift;
$self->SUPER::run();
my $compressed = BPB::Source::Compressed->new(%$self);
- $compressed->run();
+ $compressed->run( '_require.yml' => $require_path );
}
sub _run {
my $self = shift;
+ return if $self->source eq 'perl'; # don't expand perl it self;
my $module = CPAN::Shell->expand( 'Module', $self->source );
+
croak 'invalid module name: ' . $self->source unless $module;
+ $self->_make_prereq($module);
+
$self->source(
File::Spec->catfile(
$CPAN::Config->{keep_source_where}, 'authors',
@@ -35,6 +41,26 @@
);
}
+sub _make_prereq {
+ my $self = shift;
+ my $module = shift;
+
+ $module->make;
+ $require_path =
+ File::Spec->catfile( $module->distribution->dir, '_require.yml' );
+
+ my $prereq = $module->distribution->prereq_pm || {};
+
+ BPB::Config::DumpFile(
+ $require_path,
+ {
+ %{ $prereq->{requires} || {} }, %{ $prereq->{build_requires} || {} }
+ }
+ );
+
+ $module->clean;
+}
+
1;
__END__
Modified: bpsbuilder/BPB/lib/BPB/Source/Compressed.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source/Compressed.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Source/Compressed.pm Sun Dec 2 10:52:59 2007
@@ -14,6 +14,8 @@
sub run {
my $self = shift;
$self->SUPER::run();
+ $self->_copy( @_ );
+ $self->_follow($self->path) if $self->follow;
}
=head2 path
@@ -39,6 +41,16 @@
return File::Spec->catfile( $self->directory, $paths[0] );
}
+sub _copy {
+ my $self = shift;
+ my %file = @_;
+ for ( keys %file ) {
+ my $cmd = join ' ', $self->command->{directory}, $file{$_},
+ File::Spec->catfile($self->path, $_);
+ system($cmd);
+ }
+}
+
sub _cmd {
my $self = shift;
my $arg;
Modified: bpsbuilder/BPB/lib/BPB/Source/FTP.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source/FTP.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Source/FTP.pm Sun Dec 2 10:52:59 2007
@@ -14,7 +14,6 @@
sub run {
my $self = shift;
- my $self = shift;
$self->SUPER::run();
my $compressed = BPB::Source::Compressed->new( %$self );
$compressed->run();
More information about the Bps-public-commit
mailing list