line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Oryx::Parent; |
2
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
90
|
use Scalar::Util qw(blessed); |
|
15
|
|
|
|
|
28
|
|
|
15
|
|
|
|
|
697
|
|
4
|
|
|
|
|
|
|
|
5
|
15
|
|
|
15
|
|
73
|
use base qw(Oryx::MetaClass); |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
2521
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Oryx::Parent - multiple inheritance meta-type for Oryx |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Fruit; |
14
|
|
|
|
|
|
|
use base qw(Oryx::Class); |
15
|
|
|
|
|
|
|
our $schema = { |
16
|
|
|
|
|
|
|
attributes => [{ |
17
|
|
|
|
|
|
|
colour => 'String', |
18
|
|
|
|
|
|
|
}], |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
1; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
package Food; |
23
|
|
|
|
|
|
|
use base qw(Oryx::Class); |
24
|
|
|
|
|
|
|
our $schema = { |
25
|
|
|
|
|
|
|
attributes => [{ |
26
|
|
|
|
|
|
|
energy => 'Float', |
27
|
|
|
|
|
|
|
}], |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
package Orange; |
32
|
|
|
|
|
|
|
use base qw(Fruit Food); |
33
|
|
|
|
|
|
|
our $schema = { |
34
|
|
|
|
|
|
|
attributes => [{ |
35
|
|
|
|
|
|
|
segments => 'Integer', |
36
|
|
|
|
|
|
|
}] |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
1; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
use Orange; |
41
|
|
|
|
|
|
|
my $orange = Orange->create({ |
42
|
|
|
|
|
|
|
segments => 10, |
43
|
|
|
|
|
|
|
energy => 543.21, |
44
|
|
|
|
|
|
|
colour => 'orange', |
45
|
|
|
|
|
|
|
}); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$orange->update; |
48
|
|
|
|
|
|
|
$orange->commit; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $id = $orange->id; |
51
|
|
|
|
|
|
|
undef $orange; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $retrieved = Orange->retrieve($id); |
54
|
|
|
|
|
|
|
print $retrieved->colour; # prints 'orange' |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $food_instance = $retrieved->PARENT('Food'); |
57
|
|
|
|
|
|
|
print $food_instance->energy; # prints 543.21 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$food_instance->energy(42.00); |
60
|
|
|
|
|
|
|
$food_instance->update; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $changed_orange = Orange->retrieve($id); |
63
|
|
|
|
|
|
|
print $changed_orange->energy; # prints 42.00 (parent instance updated) |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 DESCRIPTION |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Oryx::Parent objects are constructed during L initialization |
68
|
|
|
|
|
|
|
by inspecting your class' C<@ISA> array, so you get one of these hanging |
69
|
|
|
|
|
|
|
off your class for each superclass that is also an L derivative. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub new { |
74
|
0
|
|
|
0
|
0
|
|
my $_class = shift; |
75
|
0
|
|
|
|
|
|
my ($class, $child) = @_; |
76
|
0
|
|
|
|
|
|
my $self = bless { |
77
|
|
|
|
|
|
|
class => $class, # superclass |
78
|
|
|
|
|
|
|
child => $child, # subclass |
79
|
|
|
|
|
|
|
}, $_class; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
eval "use $class"; $self->_croak($@) if $@; |
|
0
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
unless (UNIVERSAL::can($child, 'PARENT')) { |
84
|
15
|
|
|
15
|
|
80
|
no strict 'refs'; |
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
4251
|
|
85
|
0
|
|
|
|
|
|
*{$child.'::PARENT'} = $self->_mk_accessor; |
|
0
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return $self; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
0
|
0
|
|
sub dbh { $_[0]->{class}->dbh } |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
0
|
0
|
|
sub class { $_[0]->{class} } |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
0
|
0
|
|
sub child { $_[0]->{child} } |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub link_table { |
98
|
0
|
|
|
0
|
0
|
|
lc($_[0]->child->name.'_parents'); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub child_field { |
102
|
0
|
|
|
0
|
0
|
|
return lc($_[0]->child->name.'_id'); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _mk_accessor { |
106
|
|
|
|
|
|
|
return sub { |
107
|
0
|
|
|
0
|
|
|
my $self = shift; |
108
|
0
|
|
|
|
|
|
my $class = shift; |
109
|
0
|
0
|
|
|
|
|
$self->{__parents} = { } unless defined $self->{__parents}; |
110
|
0
|
0
|
|
|
|
|
if (@_) { |
111
|
0
|
|
|
|
|
|
$self->{__parents}->{$class} = shift; |
112
|
|
|
|
|
|
|
} else { |
113
|
0
|
|
|
|
|
|
$self->{__parents}->{$class}; |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
0
|
|
|
}; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |