[Bps-public-commit] r9881 - in bpsbuilder/BPB: examples lib/BPB/Source

sunnavy at bestpractical.com sunnavy at bestpractical.com
Tue Dec 11 08:17:40 EST 2007


Author: sunnavy
Date: Tue Dec 11 08:17:40 2007
New Revision: 9881

Modified:
   bpsbuilder/BPB/examples/config.yml
   bpsbuilder/BPB/lib/BPB/Script/Import.pm
   bpsbuilder/BPB/lib/BPB/Source/Base.pm
   bpsbuilder/BPB/lib/BPB/Source/CPAN.pm

Log:
better handle of map between module and dist

Modified: bpsbuilder/BPB/examples/config.yml
==============================================================================
--- bpsbuilder/BPB/examples/config.yml	(original)
+++ bpsbuilder/BPB/examples/config.yml	Tue Dec 11 08:17:40 2007
@@ -6,6 +6,7 @@
         directory: '/tmp'
         download_directory: '/tmp/download'
         min_perl_version: 5.008008
+        map_path: '/tmp/map.yml'
     build:
         build_directory: '/tmp/build'
         install_directory: '/tmp/install'

Modified: bpsbuilder/BPB/lib/BPB/Script/Import.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Script/Import.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Script/Import.pm	Tue Dec 11 08:17:40 2007
@@ -13,17 +13,17 @@
 
 sub options {
     (
-        'c|config=s'   => 'config',
-        'n|name=s'  => 'name',
-        'm|comment=s'  => 'comment',
-        's|source=s'   => 'source',
+        'c|config=s'  => 'config',
+        'n|name=s'    => 'name',
+        'm|comment=s' => 'comment',
+        's|source=s'  => 'source',
     );
 }
 
 sub run {
-    my $self = shift;
+    my $self   = shift;
     my $source = shift;
-    $self->source( $source ) if $source;
+    $self->source($source) if $source;
     my $bpb = BPB->new( config => $self->config, name => $self->name );
     $self->import_req( $self->source, $bpb );
     $bpb->backend->import( map { $_, $self->$_ } qw/comment source/ );
@@ -39,23 +39,32 @@
 
     if ( -e $require_file ) {
         my $req = BPB::Config::LoadFile($require_file);
+        my $map = {};
+
+        if ( -e $bpb->config->name->{source}{map_path} ) {
+            $map =
+                BPB::Config::LoadFile($bpb->config->name->{source}{map_path});
+        }
+
         opendir my $dir, $bpb->config->name->{source}{directory};
         my @sources = readdir $dir;
         close $dir;
 
         for my $module ( keys %$req ) {
-            $module =~ s/::/-/g;
-            unless ( $imported{$module} ) {
-                $imported{$module}++;
-                my $dir = ( grep { /^$module/ } @sources )[0];
-                warn "we don't have $module in source which is for "
+            my $dist = $map->{$module} || $module;
+            $dist =~ s/::/-/g;
+
+            unless ( $imported{$dist} ) {
+                $imported{$dist}++;
+                my $dir = ( grep { /^$dist/ } @sources )[0];
+                warn "we don't have $dist in source which is for "
                   . $self->source
                   unless $dir;
                 $self->import_req( $source, $bpb );
                 $bpb->backend->import(
-                    _deps => 1,
-                    comment  => 'deps for ' . $source,
-                    source   => File::Spec->catfile(
+                    _deps   => 1,
+                    comment => 'deps for ' . $source,
+                    source  => File::Spec->catfile(
                         $bpb->config->name->{source}{directory}, $dir
                     )
                 );

Modified: bpsbuilder/BPB/lib/BPB/Source/Base.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source/Base.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Source/Base.pm	Tue Dec 11 08:17:40 2007
@@ -10,35 +10,7 @@
 
 use base qw/Class::Accessor::Fast/;
 __PACKAGE__->mk_accessors(
-    qw/source directory download_directory follow min_perl_version/);
-
-our %MODULE = (
-    '^(LWP
-|File::Listing
-|HTML::Form
-|HTTP::Cookies
-|HTTP::Cookies::Microsoft
-|HTTP::Cookies::Netscape
-|HTTP::Daemon 
-|HTTP::Date 
-|HTTP::Headers
-|HTTP::Headers::Auth
-|HTTP::Headers::ETag
-|HTTP::Headers::Util
-|HTTP::Message   
-|HTTP::Negotiate
-|HTTP::Request 
-|HTTP::Request::Common   
-|HTTP::Response  
-|HTTP::Status   
-|Net::HTTP
-|Net::HTTP::Methods          
-|Net::HTTP::NB
-|Net::HTTPS  
-|WWW::RobotRules
-|WWW::RobotRules::AnyDBM_File    
-)' => 'libwww-perl',
-);
+    qw/source directory download_directory follow min_perl_version map_path/);
 
 =head2 new
 
@@ -72,6 +44,11 @@
     my $self         = shift;
     my $path         = shift;
     my $require_path = File::Spec->catfile( $path, '_require.yml' );
+    my $map          = {};
+
+    if ( -e $self->map_path ) {
+        $map = BPB::Config::LoadFile($self->map_path);
+    }
 
     # if not found, we'll create one according to META.yml
     if ( !-e $require_path ) {
@@ -89,9 +66,10 @@
                 delete $require->{$module};
                 next;
             }
+
             if (   Module::CoreList->first_release( $module, $version )
-                && Module::CoreList->first_release( $module, $version )
-                <= $self->min_perl_version ) 
+                && Module::CoreList->first_release( $module, $version ) <=
+                $self->min_perl_version )
             {
                 delete $require->{$module};
             }
@@ -99,13 +77,8 @@
                 opendir my $dir, $self->directory;
                 my @sources = readdir $dir;
                 close $dir;
-                my $name;
-
-                for ( keys %MODULE ) {
-                    $name = $MODULE{$_} if $module =~ /$_/x;
-                }
 
-                $name ||= $module;
+                my $name = $map->{$module} || $module;
                 $name =~ s/::/-/g;
 
                 unless ( grep { /^$name/ } @sources ) {
@@ -123,6 +96,22 @@
 
 }
 
+sub _make_maps {
+    my $self   = shift;
+    my $module = shift;
+    my $dist   = shift;
+
+    my $map = {};
+    if ( -e $self->map_path ) {
+        $map = BPB::Config::LoadFile( $self->map_path );
+    }
+    return if $map->{$module};
+
+    $map->{$module} = $dist;
+    BPB::Config::DumpFile( $self->map_path, $map );
+
+}
+
 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	Tue Dec 11 08:17:40 2007
@@ -21,7 +21,9 @@
     my $self = shift;
     $self->SUPER::run();
     my $compressed = BPB::Source::Compressed->new(%$self);
-    $compressed->run( '_require.yml' => $require_path );
+    $compressed->run(
+        '_require.yml' => $require_path,
+    );
 }
 
 sub _run {
@@ -33,6 +35,15 @@
 
     $self->_make_prereq($module);
 
+    my $dist    = CPAN::DistnameInfo->new( $module->cpan_file )->dist;
+    my $name    = $self->source;
+    my $moniker = $name;
+    $moniker =~ s/::/-/g;
+
+    if ( $dist ne $moniker ) {
+        $self->_make_maps( $name, $dist );
+    }
+
     $self->source(
         File::Spec->catfile(
             $CPAN::Config->{keep_source_where}, 'authors',



More information about the Bps-public-commit mailing list