[Bps-public-commit] Prophet branch, master, updated. 34269c59de1d6850d5f88f382914a0df654c3f07

jesse jesse at bestpractical.com
Wed Apr 15 03:50:43 EDT 2009


The branch, master has been updated
       via  34269c59de1d6850d5f88f382914a0df654c3f07 (commit)
      from  c62e3b05120fa209443030284caef5cd5bd75097 (commit)

Summary of changes:
 lib/Prophet/ReplicaFeedExporter.pm |   48 ++++++++++++++++++++++++++++-------
 1 files changed, 38 insertions(+), 10 deletions(-)

- Log -----------------------------------------------------------------
commit 34269c59de1d6850d5f88f382914a0df654c3f07
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Wed Apr 15 15:50:38 2009 +0800

    Made the feed replica exporter able to write to files

diff --git a/lib/Prophet/ReplicaFeedExporter.pm b/lib/Prophet/ReplicaFeedExporter.pm
index 80d7a49..626c253 100644
--- a/lib/Prophet/ReplicaFeedExporter.pm
+++ b/lib/Prophet/ReplicaFeedExporter.pm
@@ -1,29 +1,57 @@
 package Prophet::ReplicaFeedExporter;
 use Any::Moose;
+use IO::Handle;
 extends 'Prophet::ReplicaExporter';
 
+has output_handle => (
+    is => 'rw',
+    lazy => 1,
+    default => sub {
+        my $self = shift;
+        if ($self->has_target_path) {
+            open(my $outs, ">", $self->target_path) || die $!;
+            $outs->autoflush(1);
+            return $outs;
+        } else {
+            return <STDOUT>;
+        }
+
+    }
+
+);
+
+
 my $feed_updated;
 
+
+sub output {
+    my $self = shift;
+    my $content = shift;
+   $self->output_handle->print( $content);
+
+
+}
+
 sub export {
     my $self = shift;
 
-    print $self->feed_header();
+    $self->output( $self->feed_header());
     $self->source_replica->resolution_db_handle->traverse_changesets(
         after    => 0,
         callback => sub {
             my $cs = shift;
-            $self->output_resolution_changeset($cs);
+            $self->output( $self->format_resolution_changeset($cs));
         }
     );
     $self->source_replica->traverse_changesets(
         after    => 0,
         callback => sub {
             my $cs = shift;
-            $self->output_changeset($cs);
+            $self->output( $self->format_changeset($cs));
         }
     );
-    print tag( 'updated', $feed_updated );
-    print "</feed>";
+    $self->output( tag( 'updated', $feed_updated ));
+    $self->output( "</feed>");
 }
 
 sub feed_header {
@@ -41,12 +69,12 @@ sub feed_header {
     );
 }
 
-sub output_resolution_changeset {
+sub format_resolution_changeset {
     my $self = shift;
     my $cs   = shift;
 
     $feed_updated = $cs->created_as_rfc3339;
-    print tag(
+    return tag(
         'entry', undef,
         sub {
             my $output =
@@ -64,19 +92,19 @@ sub output_resolution_changeset {
                 . tag('prophet:resolution')
                 . tag( 'prophet:sequence' => $cs->sequence_no )
                 . output_changes($cs)
-                . '</content>';
+                . "</content>"."\n";
             return $output;
 
         }
     );
 }
 
-sub output_changeset {
+sub format_changeset {
     my $self = shift;
     my $cs   = shift;
 
     $feed_updated = $cs->created_as_rfc3339;
-    print tag(
+    return tag(
         'entry', undef,
         sub {
             my $output =

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list