[Bps-public-commit] Shipwright branch, master, updated. 2b8bac9573da0d1532d71b277c241e37ae2edbd1
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Sun Aug 9 22:51:19 EDT 2009
The branch, master has been updated
via 2b8bac9573da0d1532d71b277c241e37ae2edbd1 (commit)
from b12d4859873a30ca9fab74e18125113508a206f0 (commit)
Summary of changes:
lib/Shipwright/Source.pm | 43 +++++++++++++++++++++----------------------
1 files changed, 21 insertions(+), 22 deletions(-)
- Log -----------------------------------------------------------------
commit 2b8bac9573da0d1532d71b277c241e37ae2edbd1
Author: sunnavy <sunnavy at bestpractical.com>
Date: Mon Aug 10 10:51:08 2009 +0800
small refactor
diff --git a/lib/Shipwright/Source.pm b/lib/Shipwright/Source.pm
index 3bc6053..a6d0953 100644
--- a/lib/Shipwright/Source.pm
+++ b/lib/Shipwright/Source.pm
@@ -4,31 +4,11 @@ use warnings;
use strict;
use Carp;
use UNIVERSAL::require;
-use Hash::Merge qw/merge/;
use File::Temp qw/tempdir/;
use File::Spec::Functions qw/catfile catdir/;
use Shipwright::Util;
use File::Path qw/make_path/;
-Hash::Merge::set_behavior('RIGHT_PRECEDENT');
-
-our %DEFAULT = ( follow => 1, );
-
-$DEFAULT{directory} =
- tempdir( 'shipwright_source_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
-$DEFAULT{scripts_directory} = catdir( $DEFAULT{directory}, '__scripts' );
-$DEFAULT{download_directory} =
- catdir( Shipwright::Util->shipwright_user_root, 'downloads' );
-$DEFAULT{map_path} = catfile( $DEFAULT{directory}, 'map.yml' );
-$DEFAULT{url_path} = catfile( $DEFAULT{directory}, 'url.yml' );
-$DEFAULT{version_path} = catfile( $DEFAULT{directory}, 'version.yml' );
-$DEFAULT{branches_path} = catfile( $DEFAULT{directory}, 'branches.yml' );
-
-for (qw/map_path url_path version_path branches_path/) {
- open my $fh, '>', $DEFAULT{$_} or confess "can't write to $DEFAULT{$_}: $!";
- close $fh;
-}
-
=head1 NAME
Shipwright::Source - Source
@@ -45,7 +25,25 @@ Shipwright::Source - Source
sub new {
my $class = shift;
- my %args = %{ merge( \%DEFAULT, {@_} ) };
+ my %args = (
+ follow => 1,
+ directory =>
+ tempdir( 'shipwright_source_XXXXXX', CLEANUP => 1, TMPDIR => 1 ),
+ @_,
+ );
+
+ $args{scripts_directory} ||= catdir( $args{directory}, '__scripts' );
+ $args{download_directory} ||=
+ catdir( Shipwright::Util->shipwright_user_root, 'downloads' );
+ $args{map_path} ||= catfile( $args{directory}, 'map.yml' );
+ $args{url_path} ||= catfile( $args{directory}, 'url.yml' );
+ $args{version_path} ||= catfile( $args{directory}, 'version.yml' );
+ $args{branches_path} ||= catfile( $args{directory}, 'branches.yml' );
+
+ for (qw/map_path url_path version_path branches_path/) {
+ open my $fh, '>', $args{$_} or confess "can't write to $args{$_}: $!";
+ close $fh;
+ }
croak "need source arg" unless exists $args{source};
@@ -69,7 +67,8 @@ sub new {
sub type {
my $source = shift;
- _translate_source( $source );
+ _translate_source($source);
+
# prefix that can't be omitted
if ( $$source =~ /^file:.*\.(tar\.gz|tgz|tar\.bz2)$/ ) {
$$source =~ s/^file://i;
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list