Class::DBI::DataMigration::Mapping - Abstract parent class for objects that


Class-DBI-DataMigration documentation Contained in the Class-DBI-DataMigration distribution.

Index


Code Index:

Name

Top

Class::DBI::DataMigration::Mapping - Abstract parent class for objects that map a single column in a single row from the source database to the target database.

Synopsis

Top

 use Class::DBI::DataMigration::Mapping;

 # ... Later, when building $mappings hashref for use by a
 # Class::DBI::DataMigration::Mapper (which see for synopsis --
 # in this example, assume an appropriate @source_keys):

 foreach my $source_key (@source_keys) {
     $mappings{$source_key} = new Class::DBI::DataMigration::Mapping;
 }

 # ... Now we can assign $mappings to our Mapper ...

Description

Top

Class::DBI::DataMigration::Mapping objects are used by Class::DBI::DataMigration::Mapper objects to retrieve the values for particular keys into source database objects; these will in turn be stored under particular keys into newly-created target database objects.

Methods

Top

map

Expects two parameters: the key into the source object, and the source object itself.

The default map() implementation simply uses the source key as a method call on the source object and returns the value thus retrieved.

Subclasses may do something fancier.

Author

Top

Dan Friedman, <lamech@cpan.org>

Copyright & License

Top


Class-DBI-DataMigration documentation Contained in the Class-DBI-DataMigration distribution.
#!/usr/bin/perl -w

use strict;

package Class::DBI::DataMigration::Mapping;

use base 'Class::Accessor';
use Carp;

# subs:

sub map {
    my ($self, $source_key, $source_object) = @_;
    my $retval = eval qq{ return \$source_object->$source_key };
    $retval = $@ if $@;
    return $retval;
}

1;