Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Event test

  • Loading branch information...
commit fe0cf45959b576feed0ac210f36c31f23176f2c2 1 parent ce8ee1c
hakim authored
View
30 scratch/perl/kiokupipe/lib/Event.pm
@@ -0,0 +1,30 @@
+package Event;
+use Moose;
+use MooseX::Types::DateTime;
+
+has 'user' => (
+ is => 'ro',
+ isa => 'Maybe[Object]',
+);
+
+has action => (
+ is => 'ro',
+ isa => 'Str',
+);
+
+has datestamp => (
+ is => 'ro',
+ isa => 'DateTime',
+ default => sub { DateTime->now() },
+);
+
+has subject => (
+ is => 'ro',
+ isa => 'Maybe[Object]',
+);
+has object => (
+ is => 'ro',
+ isa => 'Any',
+);
+
+1;
View
8 scratch/perl/kiokupipe/lib/List.pm
@@ -88,6 +88,10 @@ sub Foldr {
$self->tail->Foldr( $f, $init )
);
}
+sub cycle {
+ my ($self, $list) = @_;
+ return List->node ($self->head, sub { $self->tail->cycle($list || $self) });
+}
sub concat {
my ($self, $list) = @_;
@@ -144,5 +148,9 @@ sub Foldr {
my ($self, $f, $init) = @_;
return $init;
}
+sub cycle {
+ my ($self, $list) = @_;
+ return $list->cycle();
+}
1;
View
9 scratch/perl/kiokupipe/lib/Module.pm
@@ -0,0 +1,9 @@
+package Module;
+use KiokuDB::Class;
+
+has id => (
+ isa => 'Num',
+ is => 'ro',
+);
+
+1;
View
9 scratch/perl/kiokupipe/lib/User.pm
@@ -0,0 +1,9 @@
+package User;
+use KiokuDB::Class;
+
+has id => (
+ isa => 'Num',
+ is => 'ro',
+);
+
+1;
View
1  scratch/perl/kiokupipe/test.pl
@@ -36,4 +36,5 @@
warn $grep->Foldr( sub { $_[0] + $_[1] }, 0 );
warn Dumper( [ $grep->concat($map2)->take(20) ] );
+ warn Dumper( [ $grep->cycle->take(20) ] );
}
View
63 scratch/perl/kiokupipe/test2.pl
@@ -0,0 +1,63 @@
+#!/usr/bin/perl
+
+use strict; use warnings;
+use List;
+use Data::Dumper;
+local $Data::Dumper::Indent = 1;
+local $Data::Dumper::Maxdepth = 2;
+
+# dummy modules for things we want to run feeds about
+use Event;
+use User;
+use Module;
+use DateTime;
+
+use KiokuDB;
+
+{
+ my @modules = map { Module->new(id=>$_) } 1..10;
+ my @users = map { User ->new(id=>$_) } 1..10;
+
+ sub make_event {
+ my $date = shift || DateTime->now;
+ my $event = Event->new(
+ datestamp => $date,
+ user => $users[ int(rand(10)) ],
+ subject => $modules[ int(rand(10)) ],
+
+ ((rand > 0.5) ?
+ (
+ action => 'completed',
+ object => int(rand(100)),
+ )
+ :
+ (
+ action => 'started',
+ ))
+ );
+ return List->node(
+ $event,
+ sub { make_event($date->clone->subtract( days => 1)) }
+ );
+ }
+}
+
+
+{
+ my $kioku = KiokuDB->connect('hash');
+ my $scope = $kioku->new_scope;
+
+ my $list = make_event();
+ # this is an infinite list, to test that our functions are properly lazy :-)
+
+ $kioku->store(list => $list);
+
+ my $completions = $kioku->lookup('list')->Grep( sub { $_[0]->action eq 'completed' } );
+ my $high_score = $completions->Grep( sub { $_[0]->object >= 80 } );
+
+ $kioku->store(high_scores => $high_score);
+
+ my $h2 = $kioku->lookup( 'high_scores' );
+
+ warn Dumper( [ $h2->take(10) ] );
+}
Please sign in to comment.
Something went wrong with that request. Please try again.