[svn:dbi] r14148 - in dbi/trunk: lib/DBD t

[email protected]
Newsgroups perl.dbi.changes
Message-ID <[email protected]>
Author: REHSACK
Date: Tue Jun 15 02:04:28 2010
New Revision: 14148

Modified:
   dbi/trunk/lib/DBD/File.pm
   dbi/trunk/t/49dbd_file.t

Log:
Add ability to set multiple meta data for one or more tables (with test)


Modified: dbi/trunk/lib/DBD/File.pm
==============================================================================
--- dbi/trunk/lib/DBD/File.pm	(original)
+++ dbi/trunk/lib/DBD/File.pm	Tue Jun 15 02:04:28 2010
@@ -554,6 +554,7 @@
 	return &$gstm ($dbh, $table, $attr);
 	}
     else {
+	ref $table or $table = [ $table ];
 	ref $attr or $attr = [ $attr ];
 	"ARRAY" eq ref $table or
 	    croak "Invalid argument for \$table - SCALAR, Regexp or ARRAY expected but got " . ref $table;
@@ -573,7 +574,7 @@
 	}
     } # get_file_meta
 
-sub set_file_meta
+sub set_single_table_meta
 {
     my ($dbh, $table, $attr, $value) = @_;
     my $meta;
@@ -585,7 +586,44 @@
     $class =~ s/::db$/::Table/;
     (undef, $meta) = $class->get_table_meta ($dbh, $table, 1);
     $meta or croak "No such table '$table'";
-    return $class->set_table_meta_attr ($meta, $attr, $value);
+    $class->set_table_meta_attr ($meta, $attr, $value);
+
+    return $dbh;
+    } # set_single_table_meta
+
+sub set_file_meta
+{
+    my ($dbh, $table, $attr, $value) = @_;
+
+    my $sstm = $dbh->{ImplementorClass}->can ("set_single_table_meta");
+
+    $table eq "*" and
+	$table = [ ".", keys %{$dbh->{f_meta}} ];
+    $table eq "+" and
+	$table = [ grep { m/^[_A-Za-z0-9]+$/ } keys %{$dbh->{f_meta}} ];
+    ref ($table) eq "Regexp" and
+	$table = [ grep { $_ =~ $table } keys %{$dbh->{f_meta}} ];
+
+    unless (ref ($table) or ref ($attr)) {
+	return &$sstm ($dbh, $table, $attr, $value);
+	}
+    else {
+	ref $table or $table = [ $table ];
+	ref $attr or $attr = { $attr => $value };
+	"ARRAY" eq ref $table or
+	    croak "Invalid argument for \$table - SCALAR, Regexp or ARRAY expected but got " . ref $table;
+	"HASH" eq ref $attr or
+	    croak "Invalid argument for \$attr - SCALAR or HASH expected but got " . ref $attr;
+
+	foreach my $tname (@{$table}) {
+	    my %tattrs;
+	    while (my ($aname, $aval) = each %$attr) {
+		&$sstm ($dbh, $tname, $aname, $aval);
+		}
+	    }
+
+	return $dbh;
+	}
     } # set_file_meta
 
 sub clear_file_meta

Modified: dbi/trunk/t/49dbd_file.t
==============================================================================
--- dbi/trunk/t/49dbd_file.t	(original)
+++ dbi/trunk/t/49dbd_file.t	Tue Jun 15 02:04:28 2010
@@ -120,6 +120,14 @@
 my @layer = grep { $_ eq "encoding($encoding)" } @tfhl;
 is (scalar @layer, 1, "encoding shows in layer");
 
+SKIP: {
+    $using_dbd_gofer and skip "modifying meta data doesn't work with Gofer-AutoProxy", 4;
+    ok ($dbh->f_set_meta ($tbl, "f_dir", $dir), "set single meta datum");
+    is ($tbl_file, $dbh->f_get_meta ($tbl, "f_fqfn"), "verify set single meta datum");
+    ok ($dbh->f_set_meta ($tbl, { f_dir => $dir }), "set multiple meta data");
+    is ($tbl_file, $dbh->f_get_meta ($tbl, "f_fqfn"), "verify set multiple meta attributes");
+    }
+
 ok ($sth = $dbh->prepare ("select * from $tbl"), "Prepare select * from $tbl");
 $rowidx = 0;
 SKIP: {
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.