Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

move more things into Solve method and make code more abstract

  • Loading branch information...
commit 36032f8b5b0d0a886ef32a30fb1c14d1a2eb8ecf 1 parent 4909e16
@ruz ruz authored
Showing with 36 additions and 31 deletions.
  1. +36 −31 lib/RT/Condition/Complex.pm
View
67 lib/RT/Condition/Complex.pm
@@ -170,54 +170,62 @@ my %op_handler = (
sub IsApplicable {
my $self = shift;
- my ($tree, @errors) = $self->ParseCode;
- unless ( $tree ) {
- $RT::Logger->error(
- "Couldn't parse complex condition, errors:\n"
- . join("\n", map "\t* $_", @errors)
- . "\nCODE:\n"
- . $self->ScripObj->CustomIsApplicableCode
- );
- return 0;
- }
- return $self->Solve( $tree );
+
+ return ($self->Solve(
+ '' => $self->TransactionObj,
+ Ticket => $self->TicketObj,
+ @_,
+ ))[0];
}
my $solver = sub {
my $cond = shift;
- my $self = $_[0];
+ my $self = shift;
+ my $res;
if ( $cond->{'op'} ) {
- return $self->SolveCondition(
- Field => $cond->{'lhs'},
- Operator => $cond->{'op'},
- Value => $self->GetValue( $cond->{'rhs'}, @_ ),
- Transaction => $_[1],
- Ticket => $_[2],
+ $res = $self->SolveCondition(
+ Field => $cond->{'lhs'},
+ Operator => $cond->{'op'},
+ Value => $self->GetValue( $cond->{'rhs'}, @_ ),
+ Arguments => \@_,
);
}
elsif ( $cond->{'module'} ) {
my $module = 'RT::Condition::'. $cond->{'module'};
eval "require $module;1" || die "Require of $module failed.\n$@\n";
+ my %rest = @_;
my $obj = $module->new (
- TransactionObj => $_[1],
- TicketObj => $_[2],
+ TransactionObj => $rest{'Transaction'},
+ TicketObj => $rest{'Ticket'},
Argument => $cond->{'argument'},
CurrentUser => $RT::SystemUser,
);
- return $obj->IsApplicable;
+ $res = $obj->IsApplicable;
} else {
die "Boo";
}
+ return undef unless $res;
+ return $res;
};
sub Solve {
my $self = shift;
- my $tree = shift;
+ my %args = @_%2? (Tree => @_) : (@_);
- my $txn = $self->TransactionObj;
- my $ticket = $self->TicketObj;
+ my ($tree, @errors) = $self->ParseCode( $args{'Tree'} );
+ unless ( $tree ) {
+ $RT::Logger->error(
+ "Couldn't parse complex condition, errors:\n"
+ . join("\n", map "\t* $_", @errors)
+ . "\nCODE:\n" . $args{'Tree'}
+ );
+ return 0;
+ }
+
+ my $solution = $parser->partial_solve( $tree, $solver, $self, %args );
+ return $solution unless ref $solution;
- return $parser->solve( $tree, $solver, $self, $txn, $ticket );
+ return (0, $solution, $self->DescribeTree( $solution ));
}
sub SolveCondition {
@@ -227,13 +235,10 @@ sub SolveCondition {
my $op_handler = $self->OpHandler( $args{'Operator'} );
my $value = $args{'Value'};
my $checker = sub { return $op_handler->( $_[0], $value ) };
-
+
return RT::Extension::ColumnMap->Check(
- String => $args{'Field'},
- Objects => {
- '' => $args{'Transaction'},
- 'Ticket' => $args{'Ticket'},
- },
+ String => $args{'Field'},
+ Objects => { @{ $args{'Arguments'} } },
Checker => $checker,
);
}
Please sign in to comment.
Something went wrong with that request. Please try again.