[Bps-public-commit] r9762 - in bpsbuilder/BPB/lib/BPB: .

sunnavy at bestpractical.com sunnavy at bestpractical.com
Thu Nov 29 09:55:58 EST 2007


Author: sunnavy
Date: Thu Nov 29 09:55:56 2007
New Revision: 9762

Added:
   bpsbuilder/BPB/lib/BPB/Source/FTP.pm
   bpsbuilder/BPB/lib/BPB/Source/HTTP.pm
Modified:
   bpsbuilder/BPB/lib/BPB/Source.pm

Log:
added support http and ftp as the source

Modified: bpsbuilder/BPB/lib/BPB/Source.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Source.pm	Thu Nov 29 09:55:56 2007
@@ -8,8 +8,10 @@
 
 Hash::Merge::set_behavior('RIGHT_PRECEDENT');
 
-our %DEFAULT =
-  ( directory => '/tmp', command => { compressed => 'tar', http => 'wget' } );
+our %DEFAULT = (
+    directory => '/tmp',
+    command   => { compressed => 'tar', http => 'wget', ftp => 'wget' }
+);
 
 =head2 new
 

Added: bpsbuilder/BPB/lib/BPB/Source/FTP.pm
==============================================================================
--- (empty file)
+++ bpsbuilder/BPB/lib/BPB/Source/FTP.pm	Thu Nov 29 09:55:56 2007
@@ -0,0 +1,100 @@
+package BPB::Source::FTP;
+
+use warnings;
+use strict;
+use Carp;
+
+use BPB::Source::Compressed;
+
+use base qw/Class::Accessor::Fast BPB::Source/;
+__PACKAGE__->mk_accessors(qw/source directory command/);
+
+=head2 new
+
+=cut
+
+sub new {
+    my $class = shift;
+    bless {@_}, $class;
+}
+
+=head2 run
+
+=cut
+
+sub run {
+    my $self = shift;
+    my $cmd  = $self->_cmd;
+    $self->_run($cmd);
+    my $compressed = BPB::Source::Compressed->new( %$self );
+    $compressed->run();
+}
+
+
+=head2 _cmd
+
+=cut
+
+sub _cmd {
+    my $self = shift;
+    my $source = $self->source;
+    my $file;
+    if ( $source =~ m{.*/(.+\.(tar\.gz|tgz|tar\.bz2))$} ) {
+        $file = $1;
+        my $src_dir = File::Spec->catfile( $self->directory, 'src' );
+        mkdir $src_dir unless -e $src_dir;
+        $self->source( File::Spec->catfile( $src_dir, $file ) );
+        return join ' ', $self->command->{ftp}, $source, '-O', $self->source;
+    }
+    else {
+        croak "invalid source: $source";
+    }
+}
+
+sub _run {
+    my $self = shift;
+    my $cmd  = shift;
+    system($cmd);
+}
+
+
+1;
+
+__END__
+
+=head1 NAME
+
+BPB::Source::FTP - 
+
+
+=head1 DESCRIPTION
+
+
+=head1 INTERFACE 
+
+
+=head1 DEPENDENCIES
+
+None.
+
+
+=head1 INCOMPATIBILITIES
+
+None reported.
+
+
+=head1 BUGS AND LIMITATIONS
+
+No bugs have been reported.
+
+=head1 AUTHOR
+
+sunnavy  C<< <sunnavy at bestpractical.com> >>
+
+
+=head1 LICENCE AND COPYRIGHT
+
+Copyright 2007 Best Practical Solutions.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.

Added: bpsbuilder/BPB/lib/BPB/Source/HTTP.pm
==============================================================================
--- (empty file)
+++ bpsbuilder/BPB/lib/BPB/Source/HTTP.pm	Thu Nov 29 09:55:56 2007
@@ -0,0 +1,103 @@
+package BPB::Source::HTTP;
+
+use warnings;
+use strict;
+use Carp;
+use File::Spec;
+use BPB::Source::Compressed;
+
+use base qw/Class::Accessor::Fast BPB::Source/;
+__PACKAGE__->mk_accessors(qw/source directory command/);
+
+=head2 new
+
+=cut
+
+sub new {
+    my $class = shift;
+    bless {@_}, $class;
+}
+
+=head2 run
+
+=cut
+
+sub run {
+    my $self = shift;
+    my $cmd  = $self->_cmd;
+    $self->_run($cmd);
+    my $compressed = BPB::Source::Compressed->new( %$self );
+    $compressed->run();
+}
+
+
+=head2 _cmd
+
+=cut
+
+sub _cmd {
+    my $self = shift;
+    my $source = $self->source;
+    my $file;
+    if ( $source =~ m{.*/(.+\.(tar\.gz|tgz|tar\.bz2))$} ) {
+        $file = $1;
+        my $src_dir = File::Spec->catfile( $self->directory, 'src' );
+        mkdir $src_dir unless -e $src_dir;
+        $self->source( File::Spec->catfile( $src_dir, $file ) );
+        return join ' ', $self->command->{http}, $source, '-O', $self->source;
+    }
+    else {
+        croak "invalid source: $source";
+    }
+}
+
+sub _run {
+    my $self = shift;
+    my $cmd  = shift;
+    system($cmd);
+}
+
+
+1;
+
+__END__
+
+=head1 NAME
+
+BPB::Source::HTTP - 
+
+
+=head1 SYNOPSIS
+
+  
+=head1 DESCRIPTION
+
+
+=head1 INTERFACE 
+
+
+=head1 DEPENDENCIES
+
+None.
+
+
+=head1 INCOMPATIBILITIES
+
+None reported.
+
+
+=head1 BUGS AND LIMITATIONS
+
+No bugs have been reported.
+
+=head1 AUTHOR
+
+sunnavy  C<< <sunnavy at bestpractical.com> >>
+
+
+=head1 LICENCE AND COPYRIGHT
+
+Copyright 2007 Best Practical Solutions.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.



More information about the Bps-public-commit mailing list