Author: REHSACK
Date: Mon May 24 01:54:39 2010
New Revision: 14018

Modified:
   dbi/trunk/lib/DBD/DBM.pm
   dbi/trunk/lib/DBD/File.pm
   dbi/trunk/t/50dbm_simple.t

Log:
move dbm_lockfile attribute and behaviour from DBD::DBM into
DBD::File as f_lockfile


Modified: dbi/trunk/lib/DBD/DBM.pm
==============================================================================
--- dbi/trunk/lib/DBD/DBM.pm    (original)
+++ dbi/trunk/lib/DBD/DBM.pm    Mon May 24 01:54:39 2010
@@ -78,7 +78,7 @@
     #    });
     my $this = $drh->SUPER::connect( $dbname, $user, $auth, $attr );
 
-    $this->STORE( 'dbm_lockfile', '.lck' );
+    $this->STORE( 'f_lockfile', '.lck' );
     $this->STORE( 'Active', 1 );
     return $this;
 }
@@ -114,31 +114,32 @@
        # carp "Usage of '$attrib' is depreciated, use 'dbm_$attrib' instead" 
if( $^W );
         $attrib = "dbm_" . $attrib;    # backward compatibility - would like 
to carp here
     }
-    if( $attrib eq "dbm_ext" )
+    if( $attrib eq "dbm_ext" or $attrib eq "dbm_lockfile" )
     {
-       # carp "Attribute 'dbm_ext' is depreciated, use 'f_ext' instead" if( 
$^W );
-       $attrib = 'f_ext';
+       ( my $newattrib = $attrib ) =~ s/^dbm_/f_/g
+       # carp "Attribute '$attrib' is depreciated, use '$newattrib' instead" 
if( $^W );
+       $attrib = $newattrib;
     }
     return $dbh->SUPER::STORE( $attrib, $value ) unless ( 0 == index( $attrib, 
'dbm_' ) );
 
     # throw an error if it has our prefix but isn't a valid attr name
     #
     if (
-        $attrib ne 'dbm_valid_attrs'    # gotta start somewhere :-)
-        and !$dbh->{dbm_valid_attrs}->{$attrib}
+        $dbh->{dbm_valid_attrs}->{$attrib}
+        or $attrib eq 'dbm_valid_attrs'    # gotta start somewhere :-)
        )
     {
-        return $dbh->set_err( $DBI::stderr, "Invalid attribute '$attrib'!" );
-    }
-    else
-    {
-
         # check here if you need to validate values
         # or conceivably do other things as well
         #
         $dbh->{$attrib} = $value;
         return 1;
     }
+    else
+    {
+       # throw an error if it has our prefix but isn't a valid attr name
+        return $dbh->set_err( $DBI::stderr, "Invalid attribute '$attrib'!" );
+    }
 }
 
 # and FETCH is done similar to STORE
@@ -151,25 +152,29 @@
     {
         $attrib = "dbm_" . $attrib;    # backward compatibility - would like 
to carp here
     }
+    if( $attrib eq "dbm_ext" or $attrib eq "dbm_lockfile" )
+    {
+       ( my $newattrib = $attrib ) =~ s/^dbm_/f_/g
+       # carp "Attribute '$attrib' is depreciated, use '$newattrib' instead" 
if( $^W );
+       $attrib = $newattrib;
+    }
     return $dbh->SUPER::FETCH($attrib) unless ( 0 == index( $attrib, 'dbm_' ) 
);
 
-    # throw an error if it has our prefix but isn't a valid attr name
-    #
     if (
-        $attrib ne 'dbm_valid_attrs'    # gotta start somewhere :-)
-        and !$dbh->{dbm_valid_attrs}->{$attrib}
+        $dbh->{dbm_valid_attrs}->{$attrib}
+        or $attrib eq 'dbm_valid_attrs'    # gotta start somewhere :-)
        )
     {
-        return $dbh->set_err( $DBI::stderr, "Invalid attribute '$attrib'" );
-    }
-    else
-    {
-
         # check here if you need to validate values
         # or conceivably do other things as well
         #
         return $dbh->{$attrib};
     }
+    else
+    {
+       # throw an error if it has our prefix but isn't a valid attr name
+        return $dbh->set_err( $DBI::stderr, "Invalid attribute '$attrib'" );
+    }
 }
 
 sub set_versions
@@ -197,7 +202,6 @@
                                 dbm_mldbm          => 1,    # the global MLDBM 
serializer
                                 dbm_cols           => 1,    # the global 
column names
                                 dbm_version        => 1,    # verbose DBD::DBM 
version
-                                dbm_lockfile       => 1,    # lockfile 
extension
                                 dbm_store_metadata => 1,    # column names, 
etc.
                                 dbm_berkeley_flags => 1,    # for BerkeleyDB
                               };
@@ -316,10 +320,6 @@
 
     my $tbl = $self->SUPER::file2table( $meta, $file, $file_is_table, $quoted 
) or return;
 
-    if( !defined($meta->{dbm_lockfile}) and $meta->{dbm_lockfile} )
-    {
-       $meta->{f_fqln} = $meta->{f_fqbn} . $meta->{dbm_lockfile};
-    }
     $meta->{f_dontopen} = 1;
 
     return $tbl;
@@ -335,8 +335,6 @@
     $meta->{dbm_type} ||= $dbh->{dbm_type} || 'SDBM_File';
     $meta->{dbm_mldbm} ||= $dbh->{dbm_mldbm} if ( $dbh->{dbm_mldbm} );
     $meta->{dbm_berkeley_flags} ||= $dbh->{dbm_berkeley_flags};
-    exists $meta->{dbm_lockfile} or
-        $meta->{dbm_lockfile} = $dbh->{dbm_lockfile};
 
     unless ( defined( $meta->{f_ext} ) )
     {
@@ -822,19 +820,6 @@
 lockfile.  In that case, DBD::DBM and your other program will respect each
 other's locks.
 
-If you wish to use a lockfile extension other than '.lck', simply specify
-the dbm_lockfile attribute:
-
-  $dbh = DBI->connect('dbi:DBM:dbm_lockfile=.foo');
-  $dbh->{dbm_lockfile} = '.foo';
-  $dbh->{f_meta}->{qux}->{dbm_lockfile} = '.foo';
-
-If you wish to disable locking, set the dbm_lockfile equal to 0.
-
-  $dbh = DBI->connect('dbi:DBM:dbm_lockfile=0');
-  $dbh->{dbm_lockfile} = 0;
-  $dbh->{f_meta}->{qux}->{dbm_lockfile} = 0;
-
 =head2 Specifying the DBM type
 
 Each "flavor" of DBM stores its files in a different format and has

Modified: dbi/trunk/lib/DBD/File.pm
==============================================================================
--- dbi/trunk/lib/DBD/File.pm   (original)
+++ dbi/trunk/lib/DBD/File.pm   Mon May 24 01:54:39 2010
@@ -726,6 +726,10 @@
 
     $meta->{f_fqfn} = $fqfn;
     $meta->{f_fqbn} = $file;
+    if( !defined($meta->{f_lockfile}) and $meta->{f_lockfile} ) {
+       $meta->{f_fqln} = $meta->{f_fqbn} . $meta->{f_lockfile};
+       }
+
     return $tbl;
     } # file2table
 
@@ -740,14 +744,16 @@
     defined $dbh->{f_meta}->{$table} and "HASH" eq ref 
$dbh->{f_meta}->{$table} or
         $dbh->{f_meta}->{$table} = {};
     my $meta = $dbh->{f_meta}->{$table};
-    defined $meta->{f_dir} or
+    exists $meta->{f_dir} or
        $meta->{f_dir} = $dbh->{f_dir};
     defined $meta->{f_ext} or
        $meta->{f_ext} = $dbh->{f_ext};
-    defined $meta->{f_encoding} or
+    exists $meta->{f_encoding} or
        $meta->{f_encoding} = $dbh->{f_encoding};
-    defined $meta->{f_lock} or
+    exists $meta->{f_lock} or
        $meta->{f_lock} = $dbh->{f_lock};
+    exists $meta->{dbm_lockfile} or
+        $meta->{dbm_lockfile} = $dbh->{dbm_lockfile};
     defined $meta->{f_fqfn} or
        $self->file2table ($meta, $table, $file_is_table, $quoted);
     } # init_table_meta
@@ -1088,6 +1094,21 @@
 
 But see L</"KNOWN BUGS"> below.
 
+=item f_lockfile
+
+If you wish to use a lockfile extension other than '.lck', simply specify
+the f_lockfile attribute:
+
+  $dbh = DBI->connect('dbi:DBM:f_lockfile=.foo');
+  $dbh->{f_lockfile} = '.foo';
+  $dbh->{f_meta}->{qux}->{f_lockfile} = '.foo';
+
+If you wish to disable locking, set the f_lockfile equal to 0.
+
+  $dbh = DBI->connect('dbi:DBM:f_lockfile=0');
+  $dbh->{f_lockfile} = 0;
+  $dbh->{f_meta}->{qux}->{f_lockfile} = 0;
+
 =item f_encoding
 
 With this attribute, you can set the encoding in which the file is opened.

Modified: dbi/trunk/t/50dbm_simple.t
==============================================================================
--- dbi/trunk/t/50dbm_simple.t  (original)
+++ dbi/trunk/t/50dbm_simple.t  Mon May 24 01:54:39 2010
@@ -158,6 +158,7 @@
     # on systems with broken NFS locking daemons.
     # (This test script doesn't test that locking actually works anyway.)
 
+    # use f_lockfile in next release - use it here as test case only
     my $dsn 
="dbi:DBM(RaiseError=0,PrintError=1):dbm_type=$dtype;dbm_mldbm=$mldbm;dbm_lockfile=.lck";
 
     if ($using_dbd_gofer) {

Reply via email to