[Bps-public-commit] r18459 - in Shipwright/trunk: lib/Shipwright/Script

sunnavy at bestpractical.com sunnavy at bestpractical.com
Thu Feb 19 00:51:16 EST 2009


Author: sunnavy
Date: Thu Feb 19 00:51:16 2009
New Revision: 18459

Modified:
   Shipwright/trunk/   (props changed)
   Shipwright/trunk/lib/Shipwright/Script/Import.pm

Log:
 r19956 at sunnavys-mb:  sunnavy | 2009-02-19 13:45:54 +0800
 we can import multiple sources with one cmd, e.g. import -r fs:/tmp/fs cpan:Jifty cpan:MojoMojo cpan:KiokuDB


Modified: Shipwright/trunk/lib/Shipwright/Script/Import.pm
==============================================================================
--- Shipwright/trunk/lib/Shipwright/Script/Import.pm	(original)
+++ Shipwright/trunk/lib/Shipwright/Script/Import.pm	Thu Feb 19 00:51:16 2009
@@ -44,8 +44,13 @@
 my ( %imported, $version );
 
 sub run {
-    my $self   = shift;
-    my $source = shift;
+    my $self    = shift;
+    my @sources = @_;
+    my $source;
+    $source = $sources[0];
+    confess "--name and --as args are not supported when importing multiple sources"
+      if @sources != 1 && $self->name;
+
     if ( $self->min_perl_version ) {
         require version;
         my $version = version->new( $self->min_perl_version );
@@ -109,124 +114,129 @@
             }
         }
 
-        my $shipwright = Shipwright->new(
-            repository          => $self->repository,
-            source              => $source,
-            name                => $self->name,
-            follow              => !$self->no_follow,
-            min_perl_version    => $self->min_perl_version,
-            skip                => $self->skip,
-            version             => $self->version,
-            skip_recommends     => $self->skip_recommends,
-            skip_all_recommends => $self->skip_all_recommends,
-        );
-
-        confess "cpan dists can't be branched"
-          if $shipwright->source->isa('Shipwright::Source::CPAN') && $self->as;
+        for my $source (@sources) {
+            my $shipwright = Shipwright->new(
+                repository          => $self->repository,
+                source              => $source,
+                name                => $self->name,
+                follow              => !$self->no_follow,
+                min_perl_version    => $self->min_perl_version,
+                skip                => $self->skip,
+                version             => $self->version,
+                skip_recommends     => $self->skip_recommends,
+                skip_all_recommends => $self->skip_all_recommends,
+            );
 
-        unless ( $self->overwrite ) {
+            confess "cpan dists can't be branched"
+              if $shipwright->source->isa('Shipwright::Source::CPAN')
+                  && $self->as;
+
+            unless ( $self->overwrite ) {
+
+                # skip already imported dists
+                $shipwright->source->skip(
+                    Hash::Merge::merge(
+                        $self->skip, $shipwright->backend->map || {}
+                    )
+                );
+            }
 
-            # skip already imported dists
-            $shipwright->source->skip(
-                Hash::Merge::merge(
-                    $self->skip, $shipwright->backend->map || {}
-                )
+            Shipwright::Util::DumpFile(
+                $shipwright->source->map_path,
+                $shipwright->backend->map || {},
             );
-        }
 
-        Shipwright::Util::DumpFile(
-            $shipwright->source->map_path,
-            $shipwright->backend->map || {},
-        );
-
-        Shipwright::Util::DumpFile(
-            $shipwright->source->url_path,
-            $shipwright->backend->source || {},
-        );
+            Shipwright::Util::DumpFile(
+                $shipwright->source->url_path,
+                $shipwright->backend->source || {},
+            );
 
-        $source = $shipwright->source->run(
-            copy => { '__require.yml' => $self->require_yml }, );
+            $source = $shipwright->source->run(
+                copy => { '__require.yml' => $self->require_yml }, );
 
-        $version =
-          Shipwright::Util::LoadFile( $shipwright->source->version_path );
+            $version =
+              Shipwright::Util::LoadFile( $shipwright->source->version_path );
 
-        my ($name) = $source =~ m{.*/(.*)$};
-        print "importing $name: ";
-        $imported{$name}++;
+            my ($name) = $source =~ m{.*/(.*)$};
+            print "importing $name: ";
+            $imported{$name}++;
 
-        my $base = $self->_parent_dir($source);
+            my $base = $self->_parent_dir($source);
 
-        my $script_dir;
-        if ( -e catdir( $base, '__scripts', $name ) ) {
-            $script_dir = catdir( $base, '__scripts', $name );
-        }
-        else {
+            my $script_dir;
+            if ( -e catdir( $base, '__scripts', $name ) ) {
+                $script_dir = catdir( $base, '__scripts', $name );
+            }
+            else {
 
      # Source part doesn't have script stuff, so we need to create by ourselves.
-            $script_dir = tempdir(
-                'shipwright_script_import_XXXXXX',
-                CLEANUP => 1,
-                TMPDIR  => 1,
-            );
+                $script_dir = tempdir(
+                    'shipwright_script_import_XXXXXX',
+                    CLEANUP => 1,
+                    TMPDIR  => 1,
+                );
+
+                if ( my $script = $self->build_script ) {
+                    copy( $self->build_script,
+                        catfile( $script_dir, 'build' ) );
+                }
+                else {
+                    $self->_generate_build( $source, $script_dir, $shipwright );
+                }
 
-            if ( my $script = $self->build_script ) {
-                copy( $self->build_script, catfile( $script_dir, 'build' ) );
-            }
-            else {
-                $self->_generate_build( $source, $script_dir, $shipwright );
             }
 
-        }
+            unless ( $self->no_follow ) {
+                $self->_import_req( $source, $shipwright, $script_dir );
 
-        unless ( $self->no_follow ) {
-            $self->_import_req( $source, $shipwright, $script_dir );
-
-            if ( -e catfile( $source, '__require.yml' ) ) {
-                move(
-                    catfile( $source,     '__require.yml' ),
-                    catfile( $script_dir, 'require.yml' )
-                ) or confess "move __require.yml failed: $!\n";
+                if ( -e catfile( $source, '__require.yml' ) ) {
+                    move(
+                        catfile( $source,     '__require.yml' ),
+                        catfile( $script_dir, 'require.yml' )
+                    ) or confess "move __require.yml failed: $!\n";
+                }
             }
-        }
 
-        my $branches =
-          Shipwright::Util::LoadFile( $shipwright->source->branches_path );
+            my $branches =
+              Shipwright::Util::LoadFile( $shipwright->source->branches_path );
 
-        $shipwright->backend->import(
-            source  => $source,
-            comment => $self->comment || 'import ' . $source,
-            overwrite => 1,                    # import anyway for the main dist
-            version   => $version->{$name},
-            as        => $self->as,
-            branches  => $branches->{$name},
-        );
+            $shipwright->backend->import(
+                source  => $source,
+                comment => $self->comment || 'import ' . $source,
+                overwrite => 1,                # import anyway for the main dist
+                version   => $version->{$name},
+                as        => $self->as,
+                branches => $branches->{$name},
+            );
 
-        $shipwright->backend->import(
-            source       => $source,
-            comment      => 'import scripts for ' . $source,
-            build_script => $script_dir,
-            overwrite    => 1,
-        );
+            $shipwright->backend->import(
+                source       => $source,
+                comment      => 'import scripts for ' . $source,
+                build_script => $script_dir,
+                overwrite    => 1,
+            );
 
-        # merge new map into map.yml in repo
-        my $new_map =
-          Shipwright::Util::LoadFile( $shipwright->source->map_path )
-          || {};
-        $shipwright->backend->map(
-            Hash::Merge::merge( $shipwright->backend->map || {}, $new_map ) );
-
-        my $new_url =
-          Shipwright::Util::LoadFile( $shipwright->source->url_path )
-          || {};
-        my $source_url = delete $new_url->{$name};
-
-        if ( $name !~ /^cpan-/ ) {
-            $shipwright->backend->source(
-                Hash::Merge::merge(
-                    $shipwright->backend->source || {},
-                    { $name => { $self->as || 'vendor' => $source_url } },
-                )
+            # merge new map into map.yml in repo
+            my $new_map =
+              Shipwright::Util::LoadFile( $shipwright->source->map_path )
+              || {};
+            $shipwright->backend->map(
+                Hash::Merge::merge( $shipwright->backend->map || {}, $new_map )
             );
+
+            my $new_url =
+              Shipwright::Util::LoadFile( $shipwright->source->url_path )
+              || {};
+            my $source_url = delete $new_url->{$name};
+
+            if ( $name !~ /^cpan-/ ) {
+                $shipwright->backend->source(
+                    Hash::Merge::merge(
+                        $shipwright->backend->source || {},
+                        { $name => { $self->as || 'vendor' => $source_url } },
+                    )
+                );
+            }
         }
 
 #        my $new_order = $shipwright->backend->fiddle_order;



More information about the Bps-public-commit mailing list