The Solution - code
- ScalarAttributeToHasA isn't necessary!
- Subclass Class::DBI::DataMigration::Mapping and override map():
package Legacy::Mapping::GameVendorToPublisher;
use base qw/Class::DBI::DataMigration::Mapping/;
use New::DBI::Publisher;
use Carp;
sub map {
my ($self, $source_key, $source_object) = @_;
# We're about to call $source_object->$source_key,
# so let's make sure we know how to do that:
my $source_class = ref $source_object;
eval "require $source_class" unless $source_class->can('new');
confess $@ if $@;
# Now find_or_create the target object:
return New::DBI::Publisher->
find_or_create({ name => $source_object->$source_key });
}
- Install somewhere in @INC so that Mapper can find it