From: Matt S Trout Date: Tue, 11 Feb 2014 07:03:00 +0000 (+0000) Subject: separate scope setup in rule bodies into its own op X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=02ae4168791e6bc2bebed5f455325ae727601418;p=scpubgit%2FDKit.git separate scope setup in rule bodies into its own op --- diff --git a/lib/DX/Op/CallRule.pm b/lib/DX/Op/CallRule.pm index f3d1b4f..17deac0 100644 --- a/lib/DX/Op/CallRule.pm +++ b/lib/DX/Op/CallRule.pm @@ -26,9 +26,8 @@ sub run { my $invoke = DX::Op::FromCode->new( code => sub { my ($self, $state) = @_; - my ($names, $body) = @{$var->bound_value}; - my %new; @new{@$names} = @args; - $state->but(scope => {})->assign_vars(%new)->then($body); + my $call = $var->bound_value->but(args => \@args); + $state->but(scope => {})->then($call); } ); my $ret_op = DX::Op::SetScope->new( diff --git a/lib/DX/Op/SetupScope.pm b/lib/DX/Op/SetupScope.pm new file mode 100644 index 0000000..90c170d --- /dev/null +++ b/lib/DX/Op/SetupScope.pm @@ -0,0 +1,15 @@ +package DX::Op::SetupScope; + +use Moo; + +has arg_names => (is => 'ro', required => 1); + +with 'DX::Role::Op::WithArgs'; + +sub run { + my ($self, $state) = @_; + my %new; @new{@{$self->arg_names}} = @{$self->args}; + $state->assign_vars(%new)->then($self->next); +} + +1; diff --git a/lib/DX/Role/Op/WithArgs.pm b/lib/DX/Role/Op/WithArgs.pm new file mode 100644 index 0000000..69bc22d --- /dev/null +++ b/lib/DX/Role/Op/WithArgs.pm @@ -0,0 +1,9 @@ +package DX::Role::Op::WithArgs; + +use Moo::Role; + +has args => (is => 'ro'); + +with 'DX::Role::Op'; + +1; diff --git a/lib/DX/RuleSet.pm b/lib/DX/RuleSet.pm index 2ae880d..09a2ff5 100644 --- a/lib/DX/RuleSet.pm +++ b/lib/DX/RuleSet.pm @@ -1,6 +1,7 @@ package DX::RuleSet; use Moo; +use DX::Op::SetupScope; use DX::Op::CallRule; use DX::Op::MemberOf; use DX::Op::ApplyConstraint; @@ -27,7 +28,7 @@ sub add_rule { sub _make_rule { my ($self, $vars, @body) = @_; my $head = $self->expand_and_link(DX::Op::Return->new, @body); - [ $vars, $head ]; + DX::Op::SetupScope->new(arg_names => $vars, next => $head); } sub expand_and_link {