[Bps-public-commit] r14407 - in Prophet/trunk: . lib/Prophet/CLI/Command

sartak at bestpractical.com sartak at bestpractical.com
Tue Jul 22 22:21:56 EDT 2008


Author: sartak
Date: Tue Jul 22 22:21:56 2008
New Revision: 14407

Added:
   Prophet/trunk/lib/Prophet/CLI/PublishCommand.pm
Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/lib/Prophet/CLI/Command/Publish.pm

Log:
 r64771 at onn:  sartak | 2008-07-22 22:21:51 -0400
 Factor out the rsync bits from publish into a role so we can reuse and improve it


Modified: Prophet/trunk/lib/Prophet/CLI/Command/Publish.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Publish.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Publish.pm	Tue Jul 22 22:21:56 2008
@@ -1,9 +1,7 @@
 package Prophet::CLI::Command::Publish;
 use Moose;
 extends 'Prophet::CLI::Command::Export';
-
-use File::Temp 'tempdir';
-use File::Rsync;
+with 'Prophet::CLI::PublishCommand';
 
 before run => sub {
     my $self = shift;
@@ -12,13 +10,7 @@
 
 before run => sub {
     my $self = shift;
-    my $dir = tempdir(CLEANUP => 1);
-
-    my $uuid = $self->app_handle->handle->db_uuid;
-    $dir .= "/$uuid";
-    mkdir $dir;
-
-    $self->set_arg(path => $dir);
+    $self->set_arg(path => $self->tempdir);
 };
 
 after run => sub {
@@ -26,16 +18,10 @@
     my $from = $self->arg('path');
     my $to   = $self->arg('to');
 
-    my $rsync = File::Rsync->new;
-    $rsync->exec({
-        src       => $from,
-        dst       => $to,
-        recursive => 1,
-        verbose   => $self->has_arg('verbose'),
-    });
-
-    warn $_ for $rsync->err;
-    print $_ for $rsync->out;
+    $self->publish_dir(
+        from => $from,
+        to   => $to,
+    );
 
     print "Publish complete.\n";
 };

Added: Prophet/trunk/lib/Prophet/CLI/PublishCommand.pm
==============================================================================
--- (empty file)
+++ Prophet/trunk/lib/Prophet/CLI/PublishCommand.pm	Tue Jul 22 22:21:56 2008
@@ -0,0 +1,39 @@
+package Prophet::CLI::PublishCommand;
+use Moose::Role;
+
+use File::Temp ();
+use File::Rsync;
+
+sub tempdir {
+    my $self = shift;
+    my $dir = File::Temp::tempdir(CLEANUP => 1);
+
+    my $uuid = $self->app_handle->handle->db_uuid;
+    $dir .= "/$uuid";
+    mkdir $dir;
+
+    return $dir;
+}
+
+sub publish_dir {
+    my $self = shift;
+    my %args = @_;
+
+    my $rsync = File::Rsync->new;
+    $rsync->exec({
+        src       => $args{from},
+        dst       => $args{to},
+        recursive => 1,
+        verbose   => $self->has_arg('verbose'),
+    });
+
+    warn $_ for $rsync->err;
+    print $_ for $rsync->out;
+
+    return $rsync;
+}
+
+no Moose::Role;
+
+1;
+



More information about the Bps-public-commit mailing list