Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

latest changes to kiokupipe

  • Loading branch information...
commit f6f51bf352f2e196f213967a54371d71c56a0a9b 1 parent d91c071
authored
20  scratch/perl/kiokupipe/lib/Feed.pm
@@ -36,16 +36,22 @@ has from_root_up_to => (
36 36
     isa => 'Maybe[Event]',
37 37
 );
38 38
 
39  
-sub add_event {
40  
-    my ($self, $event) = @_;
41  
-    $self->list( $self->list->prepend($event) );
42  
-}
  39
+sub create {
  40
+    my ($class, $kioku, %params) = @_;
43 41
 
44  
-sub store {
45  
-    my ($self, $kioku) = @_;
  42
+    my $self = $class->new(%params);
46 43
 
47 44
     my $store_as = $self->store_as or return;
48 45
     $kioku->store( $store_as, $self );
  46
+
  47
+    $self->update($kioku);
  48
+    return $self;
  49
+}
  50
+
  51
+
  52
+sub add_event {
  53
+    my ($self, $event) = @_;
  54
+    $self->list( $self->list->prepend($event) );
49 55
 }
50 56
 
51 57
 sub up_to_date {
@@ -78,6 +84,8 @@ sub update {
78 84
     $self->list($whole_list);
79 85
     $self->from_feed_up_to( $from->list->head );
80 86
     $self->from_root_up_to( $root->list->head );
  87
+
  88
+    $kioku->store($self) if $self->store_as;
81 89
 }
82 90
 
83 91
 1;
23  scratch/perl/kiokupipe/test3.pl
@@ -50,12 +50,15 @@
50 50
     my $kioku = KiokuDB->connect('hash');
51 51
     my $scope = $kioku->new_scope;
52 52
 
53  
-    my $list = make_event_list()->Take(20); 
  53
+    my $list = make_event_list()->Take(40); 
54 54
 
55  
-    my $root_list = Feed->new( list => $list, store_as => 'root' );
56  
-    $root_list->store($kioku);
  55
+    my $root_list = Feed->create( 
  56
+        $kioku,
  57
+        list => $list, 
  58
+        store_as => 'root' );
57 59
 
58  
-    my $completions = Feed->new(
  60
+    my $completions = Feed->create(
  61
+        $kioku,
59 62
         store_as => 'completions',
60 63
         from_feed => 'root',
61 64
         make_list => sub {
@@ -63,10 +66,9 @@
63 66
             $root->Grep( sub { $_[0]->action eq 'completed' } );
64 67
         },
65 68
     );
66  
-    $completions->update($kioku);
67  
-    $completions->store($kioku);
68 69
 
69  
-    my $high_score = Feed->new(
  70
+    my $high_score = Feed->create(
  71
+        $kioku,
70 72
         store_as => 'high_score',
71 73
         from_feed => 'completions',
72 74
         make_list => sub {
@@ -74,8 +76,6 @@
74 76
             $completions->Grep( sub { $_[0]->object >= 80 } );
75 77
         }
76 78
     );
77  
-    $high_score->update($kioku);
78  
-    $high_score->store($kioku);
79 79
 
80 80
     my $h2 = $kioku->lookup( 'high_score' );
81 81
     warn Dumper( [ $h2->list->take(2) ] );
@@ -85,7 +85,8 @@
85 85
     for (1..10) {
86 86
         $root_list->add_event( make_event() );
87 87
     }
  88
+    $h2->update($kioku);
88 89
 
89  
-    $high_score->update($kioku);
90  
-    warn Dumper( [ $h2->list->take(5) ] ); # may be different from above
  90
+    my $h3 = $kioku->lookup( 'high_score' );
  91
+    warn Dumper( [ $h3->list->take(5) ] ); # may be different from above
91 92
 }

0 notes on commit f6f51bf

Please sign in to comment.
Something went wrong with that request. Please try again.