Author: spadkins
Date: Tue Nov 28 10:56:11 2006
New Revision: 8311
Modified:
p5ee/trunk/App-Repository/lib/App/Repository.pm
Log:
fixed bugs in evaluate_constant_expression()
Modified: p5ee/trunk/App-Repository/lib/App/Repository.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository.pm (original)
+++ p5ee/trunk/App-Repository/lib/App/Repository.pm Tue Nov 28 10:56:11 2006
@@ -2998,18 +2998,25 @@
sub evaluate_constant_expression {
&App::sub_entry if ($App::trace);
my ($self, $value) = @_;
- my $NUM = "-?[0-9.]+";
+ my $NUM = '-?[0-9\.]+';
- while ($value =~ /\([^()]*\)/) {
- $value =~ s/\(([^()]+)\)/$self->evaluate_constant_expression($1)/eg;
+ my ($val);
+ while ($value =~ /\(([^()]*)\)/) {
+ #print "EXPR: BEFORE $value\n";
+ $val = $self->evaluate_constant_expression($1);
+ $val = "undef" if (! defined $val);
+ $value =~ s/\([^()]+\)/$val/;
+ #print "EXPR: AFTER $value\n";
}
if ($value =~ m!^[-\+\*/0-9\.\s]+$!) { # all numeric expression
$value =~ s/\s+//g;
}
- while ($value =~ s!($NUM)\s*([\*/])\s*($NUM)!($2 eq "*") ? ($1 * $3) : ($3
? ($1 / $3) : "undef")!e) {
+ while ($value =~ s~($NUM)\s*([\*/])\s*($NUM)~(!defined $1 || !defined $3)
? "undef" : (($2 eq "*") ? ($1 * $3) : ($3 ? ($1 / $3) : "undef"))~e) {
+ #print "EXPR: $1 $2 $3 = $value\n";
# nothing else needed
}
- while ($value =~ s!($NUM)\s*([\+-])\s*($NUM)!($2 eq "+") ? ($1 + $3) : ($1
- $3)!e) {
+ while ($value =~ s~($NUM)\s*([\+-])\s*($NUM)~(!defined $1 || !defined $3)
? "undef" : (($2 eq "+") ? ($1 + $3) : ($1 - $3))~e) {
+ #print "EXPR: $1 $2 $3 = $value\n";
# nothing else needed
}
$value = undef if ($value =~ /undef/);