DataMigration/Mapping.pm

filter: Statementstmt 71.4% 10 / 14 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 66.6% 14 / 21 CC 2 SCAR 11.0
CC
2
Cov
62%
map
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
« DataMigration/Migrator.pm ↑ Summary DataMigration/Synchronizer.pm »
1 #!/usr/bin/perl -w
2  
3 =head1 Name
4  
5 Class::DBI::DataMigration::Mapping - Abstract parent class for objects that
6 map a single column in a single row from the source database to the target
7 database.
8  
9 =head1 Synopsis
10  
11 use Class::DBI::DataMigration::Mapping;
12  
13 # ... Later, when building $mappings hashref for use by a
14 # Class::DBI::DataMigration::Mapper (which see for synopsis --
15 # in this example, assume an appropriate @source_keys):
16  
17 foreach my $source_key (@source_keys) {
18 $mappings{$source_key} = new Class::DBI::DataMigration::Mapping;
19 }
20  
21 # ... Now we can assign $mappings to our Mapper ...
22  
23 =head1 Description
24  
25 Class::DBI::DataMigration::Mapping objects are used by
26 Class::DBI::DataMigration::Mapper objects to retrieve the values for
27 particular keys into source database objects; these will in turn be stored
28 under particular keys into newly-created target database objects.
29  
30 =cut
31  
32 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 package Class::DBI::DataMigration::Mapping;
35  
36 3 ▶use base 'Class::Accessor';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 =head1 Methods
40  
41 =head2 map
42  
43 Expects two parameters: the key into the source object, and the source object
44 itself.
45  
46 The default map() implementation simply uses the source key as a method call on
47 the source object and returns the value thus retrieved.
48  
49 Subclasses may do something fancier.
50  
51 =cut
52  
53 # subs:
54  
55 0 ▶sub map {
Subroutine map: not called CC=2 SCAR=17.9
Pod documented
56 0 my ($self, $source_key, $source_object) = @_;
57 0 my $retval = eval qq{ return \$source_object->$source_key };
58 0 ▶ $retval = $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
59 0 return $retval;
60 }
61  
62 =begin testing
63  
64 use_ok('Class::DBI::DataMigration::Mapping');
65 can_ok('Class::DBI::DataMigration::Mapping', 'map');
66  
67 =end testing
68  
69 =head1 Author
70  
71 Dan Friedman, C<< <lamech@cpan.org> >>
72  
73 =head1 Copyright & License
74  
75 Copyright 2004 Dan Friedman, All Rights Reserved.
76  
77 This program is free software; you can redistribute it and/or modify it
78 under the same terms as Perl itself.
79  
80 Please note that these modules are not products of or supported by the
81 employers of the various contributors to the code.
82  
83 =cut
84  
85 3 1;
86  
87  
« DataMigration/Migrator.pm ↑ Summary DataMigration/Synchronizer.pm »