[Bps-public-commit] r12674 - in pie/branches/named-params: lib/PIE pieplate/PIE-Plate/etc pieplate/PIE-Plate/lib/PIE/Plate
jesse at bestpractical.com
jesse at bestpractical.com
Sun May 25 01:01:44 EDT 2008
Author: jesse
Date: Sun May 25 01:01:43 2008
New Revision: 12674
Modified:
pie/branches/named-params/lib/PIE/Evaluator.pm
pie/branches/named-params/lib/PIE/Expression.pm
pie/branches/named-params/pieplate/PIE-Plate/etc/config.yml
pie/branches/named-params/pieplate/PIE-Plate/lib/PIE/Plate/View.pm
pie/branches/named-params/t/introspection.t
Log:
* clean up expressions with no args
* export function sigs to the client side
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 01:01:43 2008
@@ -98,35 +98,62 @@
return $self->result->value;
}
-sub builtin_signatures {
+sub core_expression_signatures {
my $self = shift;
my %signatures;
- foreach my $builtin ( $self->_enumerate_builtins() ) {
- my $sig = $self->_serialize_builtin_signature($builtin);
- $signatures{$builtin} = $sig;
+ foreach my $core_expression ( $self->_enumerate_core_expressions() ) {
+ my $sig = $self->_flatten_core_expression_signature($core_expression);
+ $signatures{$core_expression} = $sig;
}
return \%signatures;
}
-sub _enumerate_builtins {
+sub _enumerate_core_expressions {
my $self = shift;
no strict 'refs';
use PIE::Expression;
- my @builtins
+ my @core_expressions
= grep { $_ && $_->isa('PIE::Expression') }
map { /^(.*)::$/ ? 'PIE::Expression::' . $1 : '' }
keys %{'PIE::Expression::'};
- return @builtins;
+ return @core_expressions;
}
-sub _serialize_builtin_signature {
+sub _flatten_core_expression_signature {
my $self = shift;
- my $builtin = shift;
- my $signature = $builtin->new->signature;
+ my $core_expression = shift;
+ my $signature = $core_expression->signature;
return { map { $_->name => {type => $_->type}} values %$signature};
}
+sub symbol_signatures {
+ my $self = shift;
+ my %signatures;
+ foreach my $symbol ($self->_enumerate_symbols()) {
+ $signatures{$symbol} = $self->_flatten_symbol_signature( $symbol)
+ }
+ return \%signatures;
+}
+
+sub _enumerate_symbols() {
+ my $self = shift;
+ return keys %{$self->global_symbols};
+}
+
+
+sub _flatten_symbol_signature {
+ my $self = shift;
+ my $sym = shift;
+
+ my $x = $self->resolve_symbol_name($sym);
+ my $signature = $x->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 01:01:43 2008
@@ -33,8 +33,11 @@
package PIE::Expression::True;
use Moose;
+use MooseX::ClassAttribute;
extends 'PIE::Expression';
+
+class_has signature => ( is => 'ro', default => sub { { }});
sub evaluate {1}
package PIE::Expression::False;
@@ -116,10 +119,12 @@
}
package PIE::Expression::ProgN;
+use MooseX::ClassAttribute;
use Moose;
extends 'PIE::Expression';
+class_has signature => ( is => 'ro', default => sub { { }});
-has nodes => (
+ has nodes => (
is => 'rw',
isa => 'ArrayRef',
);
Modified: pie/branches/named-params/pieplate/PIE-Plate/etc/config.yml
==============================================================================
--- pie/branches/named-params/pieplate/PIE-Plate/etc/config.yml (original)
+++ pie/branches/named-params/pieplate/PIE-Plate/etc/config.yml Sun May 25 01:01:43 2008
@@ -41,8 +41,8 @@
-
OnlineDocs: {}
- -
- CompressedCSSandJS: {}
+# -
+# CompressedCSSandJS: {}
-
AdminUI: {}
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 01:01:43 2008
@@ -28,13 +28,31 @@
my $json_text = JSON->new->encode($ops);
my $evaluator = PIE::Evaluator->new();
+my $MATCH_REGEX = PIE::Lambda::Native->new(
+ body => sub {
+ my $args = shift;
+ my $arg = $args->{'tested-string'};
+ my $regexp = $args->{'regexp'};
+ return ($arg =~ m/$regexp/ )? 1 : 0;
+ },
+
+ signature => {
+ 'tested-string' => PIE::FunctionArgument->new( name => 'tested-string' => type => 'Str'),
+ 'regexp' => PIE::FunctionArgument->new( name => 'regexp', type => 'Str' )
+ }
-my $signatures_json = JSON->new->encode( $evaluator->builtin_signatures());
+);
+$evaluator->set_global_symbol( 'match-regexp' => $MATCH_REGEX );
+
+
+my $signatures_json = JSON->new->encode( $evaluator->core_expression_signatures());
+my $symbol_sigs = JSON->new->encode($evaluator->symbol_signatures());
outs_raw(qq{<script type="text/javascript">
-var builtins = $signatures_json;
+var core_expressions = $signatures_json;
+var symbols = $symbol_sigs;
jQuery(lorzy_show($json_text));
Modified: pie/branches/named-params/t/introspection.t
==============================================================================
--- pie/branches/named-params/t/introspection.t (original)
+++ pie/branches/named-params/t/introspection.t Sun May 25 01:01:43 2008
@@ -2,9 +2,10 @@
use Test::More qw/no_plan/;
use_ok('PIE::Evaluator');
+use_ok('PIE::Lambda::Native');
my $e = PIE::Evaluator->new();
-my $signatures = $e->builtin_signatures;
+my $signatures = $e->core_expression_signatures;
is_deeply($signatures->{'PIE::Expression::True'} , {});
is_deeply($signatures->{'PIE::Expression::IfThen'} , { if_true => { type => 'PIE::Evaluatable'},
if_false => {type => 'PIE::Evaluatable'},
@@ -12,6 +13,27 @@
});
+my $symbols = $e->symbol_signatures();
+is_deeply($symbols, {});
+my $MATCH_REGEX = PIE::Lambda::Native->new(
+ body => sub {
+ my $args = shift;
+ my $arg = $args->{'tested-string'};
+ my $regexp = $args->{'regexp'};
+ return ($arg =~ m/$regexp/ )? 1 : 0;
+ },
+
+ signature => {
+ 'tested-string' => PIE::FunctionArgument->new( name => 'tested-string' => type => 'Str'),
+ 'regexp' => PIE::FunctionArgument->new( name => 'regexp', type => 'Str' )
+ }
+
+);
+
+$e->set_global_symbol( 'match-regexp' => $MATCH_REGEX );
+
+$symbols = $e->symbol_signatures();
+is_deeply($e->symbol_signatures(), { 'match-regexp' => { regexp => { type => 'Str'}, 'tested-string' => { type => 'Str'}}});
More information about the Bps-public-commit
mailing list