Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Cvs P5ee > [svn:p5ee] r110...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 685 of 694
Post > Topic >>

[svn:p5ee] r11051 - p5ee/trunk/App-Repository/lib/App

by spadkins@[EMAIL PROTECTED] Apr 4, 2008 at 07:27 AM

Author: spadkins
Date: Fri Apr  4 07:27:34 2008
New Revision: 11051

Modified:
   p5ee/trunk/App-Repository/lib/App/Repository.pm

Log:
get_index()/get_unique_index() works for arrays as well as hashrefs. can
load table metadata from external .pl file

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	Fri Apr  4 07:27:34
2008
@[EMAIL PROTECTED]
 -1538,7 +1538,15 @[EMAIL PROTECTED]
     my $index = {};
     my $is_array_of_arrays = ($#$rows > -1 && ref($rows->[0]) eq "ARRAY")
? 1 : 0;
     if ($is_array_of_arrays) {
-        # TBD
+        foreach my $row (@[EMAIL PROTECTED]
) {
+            $key = join(",", @[EMAIL PROTECTED]
);  # must be indexes
+            if ($index->{$key}) {
+                push(@[EMAIL PROTECTED]
>{$key}}, $row);
+            }
+            else {
+                $index->{$key} = [ $row ];
+            }
+        }
     }
     else {
         foreach my $row (@[EMAIL PROTECTED]
) {
@[EMAIL PROTECTED]
 -1564,7 +1572,10 @[EMAIL PROTECTED]
     my $unique_index = {};
     my $is_array_of_arrays = ($#$rows > -1 && ref($rows->[0]) eq "ARRAY")
? 1 : 0;
     if ($is_array_of_arrays) {
-        # TBD
+        foreach my $row (@[EMAIL PROTECTED]
) {
+            $key = join(",", @[EMAIL PROTECTED]
);
+            $unique_index->{$key} = $row;
+        }
     }
     else {
         foreach my $row (@[EMAIL PROTECTED]
) {
@[EMAIL PROTECTED]
 -3830,15 +3841,15 @[EMAIL PROTECTED]
         if ($value =~ m!^[-\+\*/0-9\.\s]+$!) {  # all numeric expression
             $value =~ s/\s+//g;
         }
-        while ($value =~ s~($NUM)\s*([\*/])\s*($NUM)~(!defined $1 ||
!defined $3) ? "undef" : (($2 eq "*") ? ($1 * $3) : (($3 && $3 != 0.0) ?
($1 / $3) : "undef"))~e) {
+        while ($value =~ s~($NUM)\s*([\*/])\s*($NUM)~(($2 eq "*") ? ($1 *
$3) : (($3 && $3 != 0.0) ? ($1 / $3) : "undef"))~e) {
             #print "EXPR: $1 $2 $3 = $value\n";
             # nothing else needed
         }
-        while ($value =~ s~($NUM)\s*([\+-])\s*($NUM)~(!defined $1 ||
!defined $3) ? "undef" : (($2 eq "+") ? ($1 + $3) : ($1 - $3))~e) {
+        while ($value =~ s~($NUM)\s*([\+-])\s*($NUM)~(($2 eq "+") ? ($1 +
$3) : ($1 - $3))~e) {
             #print "EXPR: $1 $2 $3 = $value\n";
             # nothing else needed
         }
-        while ($value =~ s~($NUM)\s*(!=|=|<|<=|>|>=)\s*($NUM)~(!defined
$1 || !defined $3) ? "undef" :
$self->evaluate_boolean_expression($1,$2,$3)~e) {
+        while ($value =~
s~($NUM)\s*(!=|=|<|<=|>|>=)\s*($NUM)~$self->evaluate_boolean_expression($1,$2,$3)~e)
{
             #print "EXPR: $1 $2 $3 = $value\n";
             # nothing else needed
         }
@[EMAIL PROTECTED]
 -4107,23 +4118,29 @[EMAIL PROTECTED]
     my ($self, $table) = @[EMAIL PROTECTED]
 
     # if it's already been loaded, don't do it again
-    return if (defined $self->{table}{$table}{loaded});
+    if (defined $self->{table}{$table}{loaded}) {
+        &App::sub_exit() if ($App::trace);
+        return;
+    }
 
     my ($table_def, $columns, $column, $column_def, $idx,
$native_column);
 
-    $table_def = $self->{table}{$table};
-    if (!$table_def) {
-        my $options = $self->{options};
+    $table_def = $self->{table}{$table} || {};
+    if (!%$table_def) {
+        my $context = $self->{context};
+        my $options = $context->{options};
         my $prefix = $options->{prefix};
         my $conf_type = $options->{conf_type} || "pl";
         my $table_file =
"$prefix/etc/app/Repository/$self->{name}/$table.$conf_type";
         if (-r $table_file) {
-            $table_def = App::Conf::File->create({ conf_file =>
$table_file });
+            $table_def = do $table_file;
             if ($table_def->{overlay}) {
                 delete $table_def->{overlay};
-                App::Reference->overlay($self->{context}{conf},
$table_def); # Caution. Use with care.
+                # Caution. Overlays the entire conf, not just the
table_def. Use with care.
+                App::Reference->overlay($self->{context}{conf},
$table_def);
             }
             else {
+                # Normal. Replaces the table_def.
                 $self->{table}{$table} = $table_def;
             }
         }
@[EMAIL PROTECTED]
 -4131,7 +4148,10 @[EMAIL PROTECTED]
 
     $self->{table}{$table}{loaded} = 1;   # mark it as having been loaded
 
-    return if (!defined $table_def);
+    if (!defined $table_def) {
+        &App::sub_exit() if ($App::trace);
+        return;
+    }
 
     # load up all additional information from the native metadata
     $self->_load_table_metadata_from_source($table);




 1 Posts in Topic:
[svn:p5ee] r11051 - p5ee/trunk/App-Repository/lib/App
spadkins@[EMAIL PROTECTED  2008-04-04 07:27:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu May 15 1:17:35 CDT 2008.