My presentation about Data::Mapper at Kyoto.pm #1 on 2012-03-17. Data::Mapper is a simple ORM and a implementation of Data Mapper Pattern described in PofEAA.
An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data. http://martinfowler.com/eaaCatalog/activeRecord.html
Table <-> Data user <-> User user_info <-> UserInfo Table <-> Data Class user <-> D::M::Data::User user_info <-> D::M::Data::UserInfo (Customizable by D::M#data_class()
# Data to Table sub mapped_params { my ($self, $data) = @_; my $table = $self- >to_table_name($data); my $schema = $self->adapter->schemata- >{$table} or Carp::croak("no such table: $table"); # snip } Schema
# Data sub mapper { my ($self, $mapper) = @_; $self->{_mapper} = $mapper if defined $mapper; $self->{_mapper}; } # Mapper sub map_data { my $self = shift; my $data = $self->SUPER::map_data(@_); $data->mapper($self); $data; } Relation (Idea 2)
# Data sub mapper { my ($self, $mapper) = @_; $self->{_mapper} = $mapper if defined $mapper; $self->{_mapper}; } # Mapper sub map_data { my $self = shift; my $data = $self->SUPER::map_data(@_); $data->mapper($self); $data; } Relation (Idea 2)