[Bps-public-commit] r19958 - Lorzy/trunk/lib/Lorzy/Expression
clkao at bestpractical.com
clkao at bestpractical.com
Wed Jun 10 07:43:38 EDT 2009
Author: clkao
Date: Wed Jun 10 07:43:36 2009
New Revision: 19958
Added:
Lorzy/trunk/lib/Lorzy/Expression/Apply.pm
Log:
apply construct.
Added: Lorzy/trunk/lib/Lorzy/Expression/Apply.pm
==============================================================================
--- (empty file)
+++ Lorzy/trunk/lib/Lorzy/Expression/Apply.pm Wed Jun 10 07:43:36 2009
@@ -0,0 +1,48 @@
+package Lorzy::Expression::Apply;
+use Moose;
+use MooseX::ClassAttribute;
+extends 'Lorzy::Expression';
+
+has lambda => (
+ is => 'rw',
+ isa => 'Lorzy::Evaluatable',
+);
+
+has apply_args => (
+ is => 'rw',
+ isa => 'HashRef[Lorzy::Expression]',
+ default => sub { {} },
+);
+
+class_has signature => (
+ is => 'ro',
+ default => sub {
+ return {
+ lambda => Lorzy::FunctionArgument->new(
+ name => 'lambda',
+ type => 'Lorzy::Evaluatable',
+ ),
+ };
+ }
+);
+
+sub BUILD {
+ my ($self, $params) = @_;
+ return unless $params->{builder};
+ my $apply_args = $params->{builder_args}{apply_args};
+ $self->apply_args->{$_} = $params->{builder}->build_expression($apply_args->{$_})
+ for keys %$apply_args;
+}
+
+sub evaluate {
+ my ($self, $evaluator) = @_;
+ my $lambda = $evaluator->evaluated_result($self->args->{lambda});
+
+ return $evaluator->apply_script($lambda, $self->apply_args);
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
+
More information about the Bps-public-commit
mailing list