[Bps-public-commit] r12591 - in pie/trunk: . t

jesse at bestpractical.com jesse at bestpractical.com
Wed May 21 03:43:11 EDT 2008


Author: jesse
Date: Wed May 21 03:43:11 2008
New Revision: 12591

Added:
   pie/trunk/t/hello_world.t
Modified:
   pie/trunk/   (props changed)
   pie/trunk/lib/PIE/Builder.pm
   pie/trunk/lib/PIE/Lambda.pm

Log:
- Merge //mirror/bps-public/pie/branches/helloworldtest to //mirror/bps-public/pie/trunk

Modified: pie/trunk/lib/PIE/Builder.pm
==============================================================================
--- pie/trunk/lib/PIE/Builder.pm	(original)
+++ pie/trunk/lib/PIE/Builder.pm	Wed May 21 03:43:11 2008
@@ -2,6 +2,9 @@
 package PIE::Builder;
 use Moose;
 
+use PIE::Lambda;
+use PIE::Expression;
+
 sub build_op_expression {
     my ($self, $name, $args) = @_;
     my $class = "PIE::Expression::$name";

Modified: pie/trunk/lib/PIE/Lambda.pm
==============================================================================
--- pie/trunk/lib/PIE/Lambda.pm	(original)
+++ pie/trunk/lib/PIE/Lambda.pm	Wed May 21 03:43:11 2008
@@ -17,10 +17,8 @@
 sub evaluate {
     my $self = shift;
     my $evaluator = shift;
-#    my %args = validate(@_, { context => 1});
     foreach my $node (@{$self->nodes}) {
         $evaluator->run($node);
-        
     }
     
 }

Added: pie/trunk/t/hello_world.t
==============================================================================
--- (empty file)
+++ pie/trunk/t/hello_world.t	Wed May 21 03:43:11 2008
@@ -0,0 +1,76 @@
+use Test::More qw/no_plan/;
+
+
+use_ok('PIE::Evaluator');
+use_ok('PIE::Builder');
+
+package Hello;
+
+use Moose;
+
+has 'evaluator' => (
+    is => 'rw',
+    isa => 'PIE::Evaluator',
+    lazy => 1,
+    default => sub { return PIE::Evaluator->new()},
+);
+
+has 'rules' => (
+    is => 'rw',
+    isa => 'ArrayRef',
+
+    );
+
+
+
+
+sub run { 
+    my $self = shift;
+    my $name = shift;
+
+    for (@{$self->rules||[]}) {
+        $self->evaluator->run($_, name => $name);
+        last unless ($self->evaluator->result->success);
+        $name =  $self->evaluator->result->value;
+    }   
+
+    return "Hello $name";
+}
+
+
+
+
+package main;
+
+is (Hello->new->run('jesse'),'Hello jesse');
+
+my $hello = Hello->new;
+isa_ok($hello => 'Hello');
+
+
+$hello->evaluator->set_named('make-fred', sub { my $name = shift; return 'fred'});
+$hello->evaluator->set_named('make-bob', sub { my $name = shift; return 'bob'});
+
+my $tree = [ 'make-fred'];
+my $builder = PIE::Builder->new();
+my $script = $builder->build_expressions($tree);
+$hello->rules([ $script]);
+can_ok($hello->rules->[0], 'evaluate');
+is ($hello->run('jesse'),'Hello fred');
+
+
+
+$hello->rules([ $builder->build_expressions([qw/make-bob make-fred/]) ]);
+can_ok($hello->rules->[0], 'evaluate');
+is ($hello->run('jesse'),'Hello fred');
+
+$hello->rules([ $builder->build_expressions([qw/make-bob/]),
+                $builder->build_expressions([qw/make-bob/])  ]);
+can_ok($hello->rules->[0], 'evaluate');
+can_ok($hello->rules->[1], 'evaluate');
+is ($hello->run('jesse'),'Hello fred');
+
+
+
+
+1;



More information about the Bps-public-commit mailing list