Author: spadkins
Date: Tue Jul 10 19:53:16 2007
New Revision: 9723
Modified:
p5ee/trunk/App-Repository/lib/App/Repository.pm
Log:
add expr defaults
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 Jul 10 19:53:16 2007
@@ -919,6 +919,7 @@
&App::sub_entry if ($App::trace);
my ($self, $table, $cols, $options) = @_;
my (%colidx, $expr_columns, $expr, $extended, $col);
+ my $OPTIONAL_DEFAULT = ':?([-0-9\.]+)?';
# Take note of which columns are alread in the list of requested columns.
for (my $i = 0; $i <= $#$cols; $i++) {
$col = $cols->[$i];
@@ -937,8 +938,8 @@
elsif ($column_defs->{$col}{expr}) {
$expr = $column_defs->{$col}{expr};
$expr =~ s/^[^\{\}]*\{//;
- $expr =~ s/\}[^\{\}]*$//;
- $expr_columns = [ split(/\}[^\{\}]*\{/, $expr) ];
+ $expr =~ s/$OPTIONAL_DEFAULT\}[^\{\}]*$//;
+ $expr_columns = [ split(/$OPTIONAL_DEFAULT\}[^\{\}]*\{/, $expr) ];
$column_defs->{$col}{expr_columns} = $expr_columns;
}
else {
@@ -3362,37 +3363,44 @@
sub evaluate_expression {
&App::sub_entry if ($App::trace);
my ($self, $expr, $values, $validx, $column_defs) = @_;
+ my $OPTIONAL_DEFAULT = ':?([-0-9\.]+)?';
my $value = $expr;
if ($values) {
- my ($col, $val, $idx);
+ my ($col, $val, $idx, $default);
if (ref($values) eq "ARRAY") {
- while ($value =~ /\{([^{}]+)\}/) {
+ while ($value =~ /\{([^{}:]+)$OPTIONAL_DEFAULT\}/) {
$col = $1;
+ $default = $2;
$idx = $validx->{$col};
if (defined $idx) {
$val = $values->[$idx];
$val = $column_defs->{$col}{expr} if (!defined $val);
- $val = $column_defs->{$col}{default} if (!defined $val);
+ if (!defined $val) {
+ $val = ($default ne "") ? $default :
$column_defs->{$col}{default};
+ }
$val = "undef" if (!defined $val);
$val = "($val)" if ($val =~ /[-\+\*\/]/);
}
else {
$val = "undef";
}
- $value =~ s/\{$col\}/$val/g || last;
+ $value =~ s/\{$col$OPTIONAL_DEFAULT\}/$val/g || last;
}
}
else {
- while ($value =~ /\{([^{}]+)\}/) {
+ while ($value =~ /\{([^{}:]+)$OPTIONAL_DEFAULT\}/) {
$col = $1;
+ $default = $2;
$val = $values->{$col};
$val = App::Reference->get($col, $values) if (!defined $val &&
$col =~ /[\[\]\{\}\.]/);
$val = $column_defs->{$col}{expr} if (!defined $val);
- $val = $column_defs->{$col}{default} if (!defined $val);
+ if (!defined $val) {
+ $val = ($default ne "") ? $default :
$column_defs->{$col}{default};
+ }
$val = "undef" if (!defined $val);
$val = "($val)" if ($val =~ /[-\+\*\/]/);
- $value =~ s/\{$col\}/$val/g || last;
+ $value =~ s/\{$col$OPTIONAL_DEFAULT\}/$val/g || last;
}
}
}