[Bps-public-commit] r12589 - in pie/branches/helloworldtest: . lib/PIE

jesse at bestpractical.com jesse at bestpractical.com
Wed May 21 03:42:04 EDT 2008


Author: jesse
Date: Wed May 21 03:42:02 2008
New Revision: 12589

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

Log:
 r31826 at 31b:  jesse | 2008-05-21 15:38:08 +0800
 * Added a failing test to start to think about very basic argument passing and returns


Modified: pie/branches/helloworldtest/lib/PIE/Builder.pm
==============================================================================
--- pie/branches/helloworldtest/lib/PIE/Builder.pm	(original)
+++ pie/branches/helloworldtest/lib/PIE/Builder.pm	Wed May 21 03:42:02 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/branches/helloworldtest/lib/PIE/Lambda.pm
==============================================================================
--- pie/branches/helloworldtest/lib/PIE/Lambda.pm	(original)
+++ pie/branches/helloworldtest/lib/PIE/Lambda.pm	Wed May 21 03:42:02 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/branches/helloworldtest/t/hello_world.t
==============================================================================
--- (empty file)
+++ pie/branches/helloworldtest/t/hello_world.t	Wed May 21 03:42:02 2008
@@ -0,0 +1,60 @@
+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'});
+
+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');
+
+1;



More information about the Bps-public-commit mailing list