[Bps-public-commit] r12672 - in pie/branches/named-params: lib/PIE pieplate/PIE-Plate/lib/PIE/Plate

jesse at bestpractical.com jesse at bestpractical.com
Sun May 25 00:30:44 EDT 2008


Author: jesse
Date: Sun May 25 00:30:43 2008
New Revision: 12672

Added:
   pie/branches/named-params/t/introspection.t
Modified:
   pie/branches/named-params/lib/PIE/Evaluator.pm
   pie/branches/named-params/lib/PIE/Expression.pm
   pie/branches/named-params/pieplate/PIE-Plate/lib/PIE/Plate/View.pm

Log:
* introspection of builtins, exported to the js layer 

Modified: pie/branches/named-params/lib/PIE/Evaluator.pm
==============================================================================
--- pie/branches/named-params/lib/PIE/Evaluator.pm	(original)
+++ pie/branches/named-params/lib/PIE/Evaluator.pm	Sun May 25 00:30:43 2008
@@ -98,4 +98,35 @@
     return $self->result->value;
 }
 
+sub builtin_signatures {
+    my $self = shift;
+    my %signatures;
+    foreach my $builtin ( $self->_enumerate_builtins() ) {
+        my $sig = $self->_serialize_builtin_signature($builtin);
+        $signatures{$builtin} =  $sig;
+    }
+
+    return \%signatures;
+}
+
+sub _enumerate_builtins {
+    my $self = shift;
+    no strict 'refs';
+    use PIE::Expression;
+    my @builtins
+        = grep { $_ && $_->isa('PIE::Expression') }
+        map { /^(.*)::$/ ? 'PIE::Expression::' . $1 : '' }
+        keys %{'PIE::Expression::'};
+    return @builtins;
+}
+
+
+sub _serialize_builtin_signature {
+    my $self    = shift;
+    my $builtin = shift;
+    my $signature = $builtin->new->signature;
+    return { map { $_->name =>  {type => $_->type}}   values %$signature};
+
+}
+
 1;

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	Sun May 25 00:30:43 2008
@@ -1,5 +1,6 @@
 
 package PIE::Expression;
+use PIE::FunctionArgument;
 use Moose;
 
 with 'PIE::Evaluatable';    
@@ -53,24 +54,6 @@
     return ! $self->SUPER::evaluate();
 
 }
-
-package PIE::Expression::Loop;
-use Moose;
-extends 'PIE::Expression';
-
-has signature => (
-    is => 'ro',
-    default => sub {  items => PIE::FunctionArgument->new(name => 'items', type => 'ArrayRef[PIE::Evaluatable]'),
-                      block => PIE::FunctionARgument->new(name => 'block', type => 'PIE::Evaluatable')}
-
-);
-
-
-sub evaluate {
-    my $self = shift;
-
-}
-
 package PIE::Expression::IfThen;
 use Moose;
 extends 'PIE::Expression';
@@ -82,14 +65,14 @@
          {
             condition => PIE::FunctionArgument->new(
                 name => 'condition',
-                isa  => 'PIE::Evaluatable'),
+                type  => 'PIE::Evaluatable'),
 
             if_true => PIE::FunctionArgument->new(
                 name => 'if_true',
-                isa  => 'PIE::Evaluatable'),
+                type  => 'PIE::Evaluatable'),
            if_false => PIE::FunctionArgument->new(
                 name => 'if_false',
-                isa  => 'PIE::Evaluatable'
+                type  => 'PIE::Evaluatable'
                 )
             }
     }

Modified: pie/branches/named-params/pieplate/PIE-Plate/lib/PIE/Plate/View.pm
==============================================================================
--- pie/branches/named-params/pieplate/PIE-Plate/lib/PIE/Plate/View.pm	(original)
+++ pie/branches/named-params/pieplate/PIE-Plate/lib/PIE/Plate/View.pm	Sun May 25 00:30:43 2008
@@ -1,3 +1,5 @@
+use warnings;
+use strict;
 package PIE::Plate::View;
 use Jifty::View::Declare -base;
 use JSON;
@@ -25,9 +27,15 @@
 
 my $json_text   = JSON->new->encode($ops);
 
+my $evaluator = PIE::Evaluator->new();
+
+my $signatures_json = JSON->new->encode(    $evaluator->builtin_signatures());
+
 
 outs_raw(qq{<script type="text/javascript">
 
+var builtins = $signatures_json;
+
 jQuery(lorzy_show($json_text));
 
 </script>});

Added: pie/branches/named-params/t/introspection.t
==============================================================================
--- (empty file)
+++ pie/branches/named-params/t/introspection.t	Sun May 25 00:30:43 2008
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+
+use Test::More qw/no_plan/;
+use_ok('PIE::Evaluator');
+my $e = PIE::Evaluator->new();
+
+my $signatures =  $e->builtin_signatures;
+is_deeply($signatures->{'PIE::Expression::True'} , {});
+is_deeply($signatures->{'PIE::Expression::IfThen'} , { if_true => { type => 'PIE::Evaluatable'},
+                                                    if_false => {type => 'PIE::Evaluatable'},
+                                                    condition => {type => 'PIE::Evaluatable'}
+    
+    
+    });
+
+
+



More information about the Bps-public-commit mailing list