2010/9/16 Tim Bunce <tim.bu...@pobox.com>:
> No tests?

The tests are already in there - t/5?dbm* test for these features, especially
t/52dbm_complex.t. This is more a refactoring to allow better implementation
in DBD::CSV - which has a separate test for it's special case.

> Tim.

/Jens

> On Wed, Sep 15, 2010 at 10:48:36PM -0700, rehs...@cvs.perl.org wrote:
>> Author: REHSACK
>> Date: Wed Sep 15 22:48:35 2010
>> New Revision: 14407
>>
>> Modified:
>>    dbi/trunk/Changes
>>    dbi/trunk/lib/DBD/DBM.pm
>>    dbi/trunk/lib/DBD/File.pm
>>    dbi/trunk/lib/DBD/File/Developers.pod
>>    dbi/trunk/lib/DBD/File/HowTo.pod
>>
>> Log:
>> Added register_compat_map() and table_meta_attr_changed() to DBD::File::Table
>>
>>
>> Modified: dbi/trunk/Changes
>> ==============================================================================
>> --- dbi/trunk/Changes (original)
>> +++ dbi/trunk/Changes Wed Sep 15 22:48:35 2010
>> @@ -31,6 +31,8 @@
>>    Added improved developers documentation for DBI::DBD::SqlEngine
>>    Added guides how to write DBI drivers using DBI::DBD::SqlEngine
>>      or DBD::File
>> +  Added register_compat_map() and table_meta_attr_changed() to
>> +    DBD::File::Table
>>
>>  =head2 Changes in DBI 1.613 (svn r14271) 22nd July 2010
>>
>>
>> Modified: dbi/trunk/lib/DBD/DBM.pm
>> ==============================================================================
>> --- dbi/trunk/lib/DBD/DBM.pm  (original)
>> +++ dbi/trunk/lib/DBD/DBM.pm  Wed Sep 15 22:48:35 2010
>> @@ -271,6 +271,14 @@
>>                        );
>>  __PACKAGE__->register_reset_on_modify( \%reset_on_modify );
>>
>> +my %compat_map = (
>> +    map { $_ => "dbm_$_" } qw(type mldbm store_metadata),
>> +    dbm_ext => 'f_ext',
>> +    dbm_file => 'f_file',
>> +    dbm_lockfile => ' f_lockfile',
>> +    );
>> +__PACKAGE__->register_compat_map (\%compat_map);
>> +
>>  sub bootstrap_table_meta
>>  {
>>      my ( $self, $dbh, $meta, $table ) = @_;
>>
>> Modified: dbi/trunk/lib/DBD/File.pm
>> ==============================================================================
>> --- dbi/trunk/lib/DBD/File.pm (original)
>> +++ dbi/trunk/lib/DBD/File.pm Wed Sep 15 22:48:35 2010
>> @@ -881,6 +881,10 @@
>>      f_lockfile => "f_fqfn", # forces new file2table call
>>      );
>>
>> +my %compat_map = (
>> +    map { $_ => "f_$_" } qw( file ext lock lockfile )
>> +);
>> +
>>  sub register_reset_on_modify
>>  {
>>      my ($proto, $extra_resets) = @_;
>> @@ -888,9 +892,18 @@
>>      return;
>>      } # register_reset_on_modify
>>
>> +sub register_compat_map
>> +{
>> +    my ($proto, $extra_compat_map) = @_;
>> +    %compat_map = (%compat_map, %$extra_compat_map);
>> +    return;
>> +    } # register_compat_map
>> +
>>  sub get_table_meta_attr
>>  {
>>      my ($class, $meta, $attrib) = @_;
>> +    exists $compat_map{$attrib} and
>> +     $attrib = $compat_map{$attrib};
>>      exists $meta->{$attrib} and
>>       return $meta->{$attrib};
>>      return;
>> @@ -899,11 +912,19 @@
>>  sub set_table_meta_attr
>>  {
>>      my ($class, $meta, $attrib, $value) = @_;
>> +    exists $compat_map{$attrib} and
>> +     $attrib = $compat_map{$attrib};
>> +    $class->table_meta_attr_changed ($meta, $attrib, $value);
>> +    $meta->{$attrib} = $value;
>> +    } # set_table_meta_attr
>> +
>> +sub table_meta_attr_changed
>> +{
>> +    my ($class, $meta, $attrib, $value) = @_;
>>      defined $reset_on_modify{$attrib} and
>>       delete $meta->{$reset_on_modify{$attrib}} and
>>       delete $meta->{initialized};
>> -    $meta->{$attrib} = $value;
>> -    } # set_table_meta_attr
>> +    } # table_meta_attr_changed
>>
>>  # ====== FILE OPEN 
>> =============================================================
>>
>>
>> Modified: dbi/trunk/lib/DBD/File/Developers.pod
>> ==============================================================================
>> --- dbi/trunk/lib/DBD/File/Developers.pod     (original)
>> +++ dbi/trunk/lib/DBD/File/Developers.pod     Wed Sep 15 22:48:35 2010
>> @@ -56,9 +56,15 @@
>>                           myd_mno => "myd_bar",
>>                         );
>>      __PACKAGE__->register_reset_on_modify( \%reset_on_modify );
>> +    my %compat_map = (
>> +                    abc => 'foo_abc',
>> +                    xyz => 'foo_xyz',
>> +                  );
>> +    __PACKAGE__->register_compat_map( \%compat_map );
>>
>>      sub bootstrap_table_meta { ... }
>>      sub init_table_meta { ... }
>> +    sub table_meta_attr_changed { ... }
>>      sub open_file { ... }
>>
>>      sub fetch_row { ... }
>> @@ -432,19 +438,24 @@
>>
>>  =item get_table_meta_attr
>>
>> -Returns a single attribute from the table meta data. This method should
>> -be overridden when mapped attribute names should be returned for
>> -compatibility reasons.
>> +Returns a single attribute from the table meta data. If the attribute
>> +name appears in C<%compat_map>, the attribute name is updated from
>> +there.
>>
>>  =item set_table_meta_attr
>>
>> -Sets a single attribute in the table meta data. This method should
>> -be overridden when mapped attribute names should be modified for
>> -compatibility reasons.
>> +Sets a single attribute in the table meta data. If the attribute
>> +name appears in C<%compat_map>, the attribute name is updated from
>> +there.
>> +
>> +=item table_meta_attr_changed
>> +
>> +Called when an attribute of the meta data is modified.
>>
>>  If the modified attribute requires to reset a calculated attribute, the
>>  calculated attribute is reset (deleted from meta data structure) and
>> -the I<initialized> flag is removed, too.
>> +the I<initialized> flag is removed, too. The decision is made based on
>> +C<%register_reset_on_modify>.
>>
>>  =item register_reset_on_modify
>>
>> @@ -459,6 +470,15 @@
>>      my %reset_on_modify = ( "xxx_foo" => "xxx_bar" );
>>      __PACKAGE__->register_reset_on_modify( \%reset_on_modify );
>>
>> +=item register_compat_map
>> +
>> +Allows C<get_table_meta_attr> and C<set_table_meta_attr> to update the
>> +attribute name to the current favored one:
>> +
>> +    # from DBD::DBM
>> +    my %compat_map = ( "dbm_ext" => "f_ext" );
>> +    __PACKAGE__->register_compat_map( \%compat_map );
>> +
>>  =item open_file
>>
>>  Called to open the table's data file.
>>
>> Modified: dbi/trunk/lib/DBD/File/HowTo.pod
>> ==============================================================================
>> --- dbi/trunk/lib/DBD/File/HowTo.pod  (original)
>> +++ dbi/trunk/lib/DBD/File/HowTo.pod  Wed Sep 15 22:48:35 2010
>> @@ -204,6 +204,16 @@
>>      sub get_table_meta_attr { ... }
>>      sub set_table_meta_attr { ... }
>>
>> +Both methods can adjust the attribute name for compatibility reasons, e.g.
>> +when former versions of the DBD allowed different names to be used for the
>> +same flag:
>> +
>> +    my %compat_map = (
>> +                    abc => 'foo_abc',
>> +                    xyz => 'foo_xyz',
>> +                  );
>> +    __PACKAGE__->register_compat_map( \%compat_map );
>> +
>>  If any user modification on a meta attribute needs reinitialization of
>>  the meta structure (in case of C<DBD::File> these are the attributes
>>  C<f_file>, C<f_dir>, C<f_ext> and C<f_lockfile>), inform DBD::File by
>> @@ -218,6 +228,19 @@
>>  The next access to the table meta data will force DBD::File to re-do the
>>  entire meta initialization process.
>>
>> +Any further action which needs to be taken can handled in
>> +C<table_meta_attr_changed>:
>> +
>> +    sub table_meta_attr_changed
>> +    {
>> +     my ($class, $meta, $attrib, $value) = @_;
>> +     ...
>> +     $class->SUPER::table_meta_attr_changed ($meta, $attrib, $value);
>> +    }
>> +
>> +This is done before the new value is set in C<$meta>, so the attribute
>> +changed handler can act depending on the old value.
>> +
>>  =head2 Testing
>>
>>  Now you should have your own DBD::File based driver. Was easy, wasn't it?
>>
>

Reply via email to