blib/lib/Oryx/DBM/Parent.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 50 CC 4 SCAR 14.3
CC
4
Cov
0%
create
6.0
update
6.0
delete
6.0
CRAP 4.2
1 package Oryx::DBM::Parent;
2  
3 use Scalar::Util qw(blessed);
4  
5 use base qw(Oryx::Parent);
6  
7 sub create {
8 my ($self, $param) = @_;
9 my $parent = $self->class->create($param);
10 $param->{_parent_ids} = { } unless defined $param->{_parent_ids};
11 $param->{_parent_ids}->{$self->class} = $parent->id;
12 }
13  
14 sub retrieve { }
15  
16 sub update {
17 my ($self, $query, $obj) = @_;
18 my $parent = $obj->PARENT($self->class);
19 return unless (defined $parent and blessed($parent)); # abstract (no attributes)
20 $parent->$_($obj->$_) foreach keys %{$self->class->attributes};
21 $parent->update;
22 }
23  
24 sub delete {
25 my ($self, $query, $obj) = @_;
26 my $parent = $obj->PARENT($self->class);
27 $parent->delete() if $parent;
28 }
29  
30 sub search { }
31  
32 sub construct {
33 my ($self, $obj) = @_;
34 my $parent = $self->class->retrieve($obj->{_parent_ids}->{$self->class});
35  
36 # copy the attribute values from the parent to the child instance
37 $obj->$_($parent->$_) foreach keys %{$self->class->attributes};
38 $obj->PARENT($self->class, $parent);
39 }
40  
41 1;
42 __END__