[Bps-public-commit] r12644 - in pie/branches/named-params: lib/PIE

clkao at bestpractical.com clkao at bestpractical.com
Fri May 23 09:04:22 EDT 2008


Author: clkao
Date: Fri May 23 09:04:22 2008
New Revision: 12644

Modified:
   pie/branches/named-params/lib/PIE/Builder.pm
   pie/branches/named-params/lib/PIE/Expression.pm
   pie/branches/named-params/t/01basic.t

Log:
fix builder's expression constructor.


Modified: pie/branches/named-params/lib/PIE/Builder.pm
==============================================================================
--- pie/branches/named-params/lib/PIE/Builder.pm	(original)
+++ pie/branches/named-params/lib/PIE/Builder.pm	Fri May 23 09:04:22 2008
@@ -11,13 +11,10 @@
     my ($self, $name, $args) = @_;
     my $class = "PIE::Expression::$name";
     $class->require;
-    if($class->can('meta')){
-        die unless $class->meta->does_role("PIE::Evaluatable");
-        return    $class->new( map { $_ => $self->build_expression( $args->{$_} ) } keys %$args );
-    }
-    else {
-        return PIE::Expression->new( name => $name, args => { map { $_ => $self->build_expression( $args->{$_} ) } keys %$args } );
-    }
+    $class = "PIE::Expression" unless $class->can('meta');
+
+    return $class->new( name => $name, args => { map { $_ => $self->build_expression( $args->{$_} ) } keys %$args } );
+
 }
 
 sub build_expression {

Modified: pie/branches/named-params/lib/PIE/Expression.pm
==============================================================================
--- pie/branches/named-params/lib/PIE/Expression.pm	(original)
+++ pie/branches/named-params/lib/PIE/Expression.pm	Fri May 23 09:04:22 2008
@@ -98,7 +98,9 @@
 
 sub evaluate {
     my ($self, $evaluator) = validate_pos(@_, { isa => 'PIE::Expression'}, { isa => 'PIE::Evaluator'}, );
+
     $evaluator->run($self->args->{condition});
+
     if ($evaluator->result->value) {
         $evaluator->run($self->args->{if_true});
         return $evaluator->result->value;

Modified: pie/branches/named-params/t/01basic.t
==============================================================================
--- pie/branches/named-params/t/01basic.t	(original)
+++ pie/branches/named-params/t/01basic.t	Fri May 23 09:04:22 2008
@@ -1,5 +1,5 @@
 use Test::More qw'no_plan';
-
+use strict;
 use_ok('PIE::Expression');
 use_ok('PIE::Evaluator');
 use_ok('PIE::Lambda');
@@ -65,34 +65,31 @@
 
 my $MATCH_REGEX = PIE::Lambda::Native->new(
     body => sub {
-        warn "HEY";
         my $args = shift;
         my $arg    = $args->{'tested-string'};
         my $regexp = $args->{'regexp'};
-
-        warn "REGEX CHECK: ". ($crg =~ m/$regexp/ )? 1 : 0;
         return ($arg =~ m/$regexp/ )? 1 : 0;
     },
 
     signature => {
         'tested-string' => PIE::FunctionArgument->new( name => 'tested-string' => type => 'Str'),
-        'regex' => PIE::FunctionArgument->new( name => 'regex', type => 'Str' )
+        'regexp' => PIE::FunctionArgument->new( name => 'regexp', type => 'Str' )
         }
 
 );
 
 $eval9->set_named( 'match-regexp' => $MATCH_REGEX );
-warn "ORZ";
+
 $eval9->apply_script(
     $MATCH_REGEX, 
     {   'tested-string' => PIE::Expression::String->new( args => {value => 'I do love software'} ),
-        'regex' => PIE::Expression::String->new( args => { value => 'software' })
+        'regexp' => PIE::Expression::String->new( args => { value => 'software' })
     }
 );
 
 ok( $eval9->result->success, $eval9->result->error );
 is( $eval9->result->value, 1 );
-__END__
+
 my $builder = PIE::Builder->new();
 my $eval10 = PIE::Evaluator->new();
 $eval10->set_named( 'match-regexp' => $MATCH_REGEX );
@@ -107,7 +104,7 @@
                     'condition' => {
                         name => 'match-regexp',
                         args => {
-                            regex           => 'software',
+                            regexp           => 'software',
                             'tested-string' => 'foo',
                         }
                     }



More information about the Bps-public-commit mailing list