[Bps-public-commit] r12865 - in Shipwright/trunk: lib/Shipwright/Script
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Wed Jun 4 11:00:14 EDT 2008
Author: sunnavy
Date: Wed Jun 4 11:00:11 2008
New Revision: 12865
Modified:
Shipwright/trunk/ (props changed)
Shipwright/trunk/lib/Shipwright/Script/Delete.pm
Log:
r12947 at sunnavys-mb: sunnavy | 2008-06-04 22:54:24 +0800
refactor to reduce code redundancy
Modified: Shipwright/trunk/lib/Shipwright/Script/Delete.pm
==============================================================================
--- Shipwright/trunk/lib/Shipwright/Script/Delete.pm (original)
+++ Shipwright/trunk/lib/Shipwright/Script/Delete.pm Wed Jun 4 11:00:11 2008
@@ -47,7 +47,7 @@
my $order = $shipwright->backend->order;
die "no such dist: $name" unless grep { $_ eq $name } @$order;
-
+
$shipwright->backend->delete( path => "dists/$name" );
$shipwright->backend->delete( path => "scripts/$name" );
@@ -55,32 +55,17 @@
@$order = grep { $_ ne $name } @$order;
$shipwright->backend->order($order);
- # clean version.yml, map.yml, source.yml and flags.yml
- my $version = $shipwright->backend->version;
- for ( keys %$version ) {
- if ( $_ eq $name ) {
- delete $version->{$_};
- last;
- }
- }
-
+ # clean map.yml
for ( keys %$map ) {
delete $map->{$_} if $map->{$_} eq $name;
}
- my $source = $shipwright->backend->source || {};
-
- for ( keys %$source ) {
- if ( $_ eq $name ) {
- delete $source->{$_} if $_ eq $name;
- last;
- }
- }
+ # clean version.yml, source.yml and flags.yml
+ my $version = $shipwright->backend->version || {};
+ my $source = $shipwright->backend->source || {};
+ my $flags = $shipwright->backend->flags || {};
- my $flags = $shipwright->backend->flags;
- for ( keys %$flags ) {
- delete $flags->{$_} if $_ eq $name;
- }
+ $self->_clean_hash( $source, $flags, $version );
$shipwright->backend->version($version);
$shipwright->backend->map($map);
@@ -90,6 +75,21 @@
print "deleted $name with success\n";
}
+sub _clean_hash {
+ my $self = shift;
+ my @hashrefs = @_;
+ my $name = $self->name;
+
+ for my $hashref (@hashrefs) {
+ for ( keys %$hashref ) {
+ if ( $_ eq $name ) {
+ delete $hashref->{$_} if $_ eq $name;
+ last;
+ }
+ }
+ }
+}
+
1;
__END__
More information about the Bps-public-commit
mailing list