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

sunnavy at bestpractical.com sunnavy at bestpractical.com
Sun Dec 30 11:40:43 EST 2007


Author: sunnavy
Date: Sun Dec 30 11:40:43 2007
New Revision: 10200

Modified:
   bpsbuilder/BPB/lib/BPB.pm
   bpsbuilder/BPB/lib/BPB/Source/Base.pm
   bpsbuilder/BPB/lib/BPB/Source/Compressed.pm
   bpsbuilder/BPB/lib/BPB/Source/Directory.pm

Log:
added name property for source object

Modified: bpsbuilder/BPB/lib/BPB.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB.pm	(original)
+++ bpsbuilder/BPB/lib/BPB.pm	Sun Dec 30 11:40:43 2007
@@ -51,6 +51,7 @@
                 %{ $self->config->name->{source} },
                 follow => $args{follow},
                 source => $args{source},
+                name => $args{source_name},
             )
         ) if $args{source};
 

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 30 11:40:43 2007
@@ -11,7 +11,7 @@
 use base qw/Class::Accessor::Fast/;
 __PACKAGE__->mk_accessors(
     qw/source directory download_directory follow min_perl_version map_path
-      skip map keep_recommends/
+      skip map keep_recommends name/
 );
 
 =head2 new
@@ -120,12 +120,18 @@
                 if (   $require->{$module}{source}
                     && $require->{$module}{source} ne 'CPAN' )
                 {
-                    $s =
-                      BPB::Source->new( %$self,
-                        source => $require->{$module}{source} );
+                    $s = BPB::Source->new(
+                        %$self,
+                        source => $require->{$module}{source},
+                        name   => $module
+                    );
                 }
                 else {
-                    $s = BPB::Source->new( %$self, source => $module );
+                    $s = BPB::Source->new(
+                        %$self,
+                        source => $module,
+                        name   => $module
+                    );
                 }
                 $s->run();
             }
@@ -181,7 +187,8 @@
     my %file = @_;
     for ( keys %file ) {
         my $cmd = join ' ', 'cp', $file{$_},
-          File::Spec->catfile( $self->path, $_ );
+          File::Spec->catfile( $self->directory, $self->name || $self->path,
+            $_ );
         system($cmd);
     }
 }

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 30 11:40:43 2007
@@ -13,9 +13,11 @@
 
 sub run {
     my $self = shift;
-    my $ret = $self->SUPER::run(@_);
-    $self->_follow($self->path) if $self->follow;
-    return $self->path;
+    my $ret  = $self->SUPER::run(@_);
+    $self->_follow(
+        File::Spec->catfile( $self->directory, $self->name || $self->path ) )
+      if $self->follow;
+    return File::Spec->catfile( $self->directory, $self->name || $self->path );
 }
 
 =head2 path
@@ -26,7 +28,7 @@
 
 sub path {
     my $self     = shift;
-    my $source = $self->source;
+    my $source   = $self->source;
     my @contents = `tar -t -f $source`;
     my %path;
 
@@ -37,10 +39,9 @@
     my @paths = keys %path;
     croak 'only support compressed file which contains only one directory'
       unless @paths == 1;
-    return File::Spec->catfile( $self->directory, $paths[0] );
+    return $paths[0];
 }
 
-
 sub _cmd {
     my $self = shift;
     my $arg;
@@ -54,10 +55,17 @@
     else {
         croak "I've no idea what the cmd is";
     }
-    return join ' ', 'tar', $arg, $self->source, '-C',
-      $self->directory;
-}
 
+    my @cmds;
+    push @cmds, join ' ', 'tar', $arg, $self->source, '-C', $self->directory;
+
+    if ( $self->name && $self->name ne $self->path ) {
+        push @cmds, join ' ', 'mv',
+          File::Spec->catfile( $self->directory, $self->path ),
+          File::Spec->catfile( $self->directory, $self->name );
+    }
+    return @cmds;
+}
 
 1;
 

Modified: bpsbuilder/BPB/lib/BPB/Source/Directory.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source/Directory.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Source/Directory.pm	Sun Dec 30 11:40:43 2007
@@ -25,19 +25,21 @@
 sub run {
     my $self = shift;
     $self->SUPER::run(@_);
-    $self->_follow($self->path) if $self->follow;
-    return $self->path;
+    $self->_follow(
+        File::Spec->catfile( $self->directory, $self->name || $self->path ) )
+      if $self->follow;
+    return File::Spec->catfile( $self->directory, $self->name || $self->path );
 }
 
 sub path {
     my $self = shift;
-    return File::Spec->catfile($self->directory, basename $self->source);
+    return basename $self->source;
 }
 
 sub _cmd {
     my $self = shift;
     return join ' ', 'cp', '-r', $self->source,
-      $self->directory;
+      File::Spec->catfile( $self->directory, $self->name || $self->path );
 }
 
 1;



More information about the Bps-public-commit mailing list