cvs commit: p5ee/App-Repository/lib/App/ValueDomain Repository.pm

[email protected] (Stephen Adkins)
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
cvsuser     05/08/09 11:48:45

  Modified:    App-Repository/lib/App/ValueDomain Repository.pm
  Log:
  add param value substitution
  
  Revision  Changes    Path
  1.3       +23 -5     p5ee/App-Repository/lib/App/ValueDomain/Repository.pm
  
  Index: Repository.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/lib/App/ValueDomain/Repository.pm,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Repository.pm	7 Jan 2005 13:39:40 -0000	1.2
  +++ Repository.pm	9 Aug 2005 18:48:45 -0000	1.3
  @@ -105,20 +105,38 @@
           my $table       = $self->{table};
           my $valuecolumn = $self->{valuecolumn};
           my $labelcolumn = $self->{labelcolumn};
  +        $labelcolumn = "" if ($labelcolumn eq $valuecolumn);
           my $params      = $self->{params} || {};
           my %params      = %$params;
  +        my ($key, $keyvalue, $wname, $wvalue);
  +        foreach my $key (keys %params) {
  +            $keyvalue = $params{$key};
  +            while ($keyvalue =~ /\{([A-Za-z0-9\._-]+)\}/) {
  +                $wname = $1;
  +                $wvalue = $context->so_get($wname);
  +                if (defined $wvalue) {
  +                    $keyvalue =~ s/\{$wname\}/$wvalue/g;
  +                }
  +                else {
  +                    $keyvalue =~ s/\{$wname\}/NULL/g;
  +                }
  +            }
  +            $params{$key} = $keyvalue;
  +        }
           $params{$valuecolumn} = $values_string if (defined $values_string && $values_string ne "");
   
  -        if ($rep && $table && $valuecolumn && $labelcolumn && $params) {
  -            $rows   = $rep->get_rows($table, \%params, [ $valuecolumn, $labelcolumn ]);
  +        if ($rep && $table && $valuecolumn && $params) {
  +            my @cols = ( $valuecolumn );
  +            push(@cols, $labelcolumn) if ($labelcolumn);
  +            $rows   = $rep->get_rows($table, \%params, \@cols);
               $values = [];
               $labels = {};
               foreach $row (@$rows) {
                   push(@$values, $row->[0]);
  -                $labels->{$row->[0]} = $row->[1];
  +                $labels->{$row->[0]} = $row->[1] if ($labelcolumn);
               }
               $self->{values} = $values;
  -            $self->{labels} = $labels;
  +            $self->{labels} = $labels if ($labelcolumn);
               $time = time();
               $self->{time} = $time;
               $self->{values_string} = $values_string;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.