blib/lib/Oryx/DBM/Association/Reference.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 57 CC 6 SCAR 18.7
CC
6
Cov
0%
update
12.0
retrieve
6.0
delete
6.0
CRAP 6.5
1 package Oryx::DBM::Association::Reference;
2  
3 use base qw(Oryx::Association::Reference);
4  
5 sub create {
6 my ($self, $proto, $param) = @_;
7 }
8  
9 sub retrieve {
10 my ($self, $proto, $id) = @_;
11 my $f_key = $self->class->table."_id";
12 my $f_id = $proto->{ $f_key };
13 $proto->{ $f_key } = $self->class->dbm->get( $f_id )
14 if defined $f_id;
15 }
16  
17 sub update {
18 my ($self, $proto, $obj) = @_;
19 my $accessor = $self->role;
20 if (tied($obj->{$accessor})->changed) {
21 my $f_key = $self->class->table.'_id';
22 if (ref($obj->$accessor)) {
23 $proto->{ $f_key } = $obj->$accessor->id;
24 } else {
25 $proto->{ $f_key } = $obj->$accessor;
26 }
27 }
28 }
29  
30 sub delete {
31 my $self = shift;
32 my ($proto, $obj) = @_;
33 if ($self->constraint eq 'Composition') {
34 # cascade the delete
35 my $accessor = $self->role;
36 $obj->$accessor->dbm->delete($obj->id);
37 }
38 $self->update(@_);
39 }
40  
41 sub search {
42  
43 }
44  
45 sub construct {
46 my ($self, $obj) = @_;
47 my $assoc_name = $self->role;
48 my @args;
49 if ($obj->{$assoc_name} and defined $obj->{$assoc_name}->{id}) {
50 @args = ($self, $obj->{$assoc_name}->{id});
51 } else {
52 @args = ($self, $obj->{$self->class->table.'_id'});
53 }
54 tie $obj->{$assoc_name}, __PACKAGE__, @args;
55 }
56  
57 1;
58 __END__