line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Oryx::MetaClass; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# okay, so it's not really a meta-class in the true sense since it |
4
|
|
|
|
|
|
|
# doesn't get instantiated. Instead, it gets subclassed, but we use |
5
|
|
|
|
|
|
|
# inheritable class data to achieve the same effect. This is |
6
|
|
|
|
|
|
|
# because we're not trying to create our own meta-model so much as |
7
|
|
|
|
|
|
|
# trying to squeeze a relational data model into Perl's in-built |
8
|
|
|
|
|
|
|
# meta-model. Subclassing this via Perl's inheritance mechanism |
9
|
|
|
|
|
|
|
# preserves class state as if the sub class were a Class instance of a |
10
|
|
|
|
|
|
|
# MetaClass (which it is, just not this one... Perl's). There is |
11
|
|
|
|
|
|
|
# meta-data associated with the class which is in the form of a DOM |
12
|
|
|
|
|
|
|
# Node which was used to define the schema in the first place (and |
13
|
|
|
|
|
|
|
# which is passed into the constructor of whichever entity derives |
14
|
|
|
|
|
|
|
# from this class). |
15
|
|
|
|
|
|
|
|
16
|
15
|
|
|
15
|
|
89
|
use Carp qw(carp croak cluck); |
|
15
|
|
|
|
|
32
|
|
|
15
|
|
|
|
|
1662
|
|
17
|
15
|
|
|
15
|
|
72
|
use base qw(Class::Data::Inheritable); |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
6497
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata("storage"); |
20
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata("schema"); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Oryx::MetaClass - abstract base class for all Oryx meta types |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 INTERFACE |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
All Oryx components implement the interface defined herein. This |
29
|
|
|
|
|
|
|
is the basis for all Oryx components to share a common interface. |
30
|
|
|
|
|
|
|
All this really means is that when an object is created, retrieved, |
31
|
|
|
|
|
|
|
deleted etc. then each meta-instance (L, L etc.) |
32
|
|
|
|
|
|
|
associated with the class or instance can decide what it wants to do |
33
|
|
|
|
|
|
|
during each call. So when we say: |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
CMS::Page->create({ ... }); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
then in the C method inherited from L we |
38
|
|
|
|
|
|
|
do something similar to: |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub create { |
41
|
|
|
|
|
|
|
my ($class, $params) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# do a few things with $params, exactly what would depend |
44
|
|
|
|
|
|
|
# on whether we're using DBI or DBM back-end |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$_->create($query, $params, ...) foreach $class->members; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# return a newly created instance |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Here the C method (defined in L returns |
52
|
|
|
|
|
|
|
all meta-instances hanging off the class, and to each on is the |
53
|
|
|
|
|
|
|
C method delegated; hence the common interface. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=over |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item create |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
meta object's C hook |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item retrieve |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
meta object's C hook |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item update |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
meta object's C hook |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item delete |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
meta object's C hook |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item search |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
meta object's C hook |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item construct |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
meta object's C hook |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 META-DATA ACCESS |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Each meta-type (with the exception of L types) has |
84
|
|
|
|
|
|
|
meta-data associated with it which is usually defined in the |
85
|
|
|
|
|
|
|
C<$schema> class variable used in your persistent classes. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
The following are accessors for this meta-data: |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item meta |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
usually returns a hash reference which corresponds to the meta-data |
92
|
|
|
|
|
|
|
described in C<$schema>. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item getMetaAttribute( $name ) |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
get a value from the meta-data hash ref keyed by C<$name> |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item setMetaAttribute( $name, $value ) |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
set a value from the meta-data hash ref keyed by C<$name> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=back |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
0
|
1
|
|
sub create { } |
107
|
0
|
|
|
0
|
1
|
|
sub retrieve { } |
108
|
0
|
|
|
0
|
1
|
|
sub update { } |
109
|
0
|
|
|
0
|
1
|
|
sub delete { } |
110
|
0
|
|
|
0
|
1
|
|
sub search { } |
111
|
0
|
|
|
0
|
1
|
|
sub construct { } |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub meta { |
114
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
115
|
0
|
0
|
|
|
|
|
$class->{meta} = shift if @_; |
116
|
0
|
|
|
|
|
|
$class->{meta}; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub setMetaAttribute { |
120
|
0
|
|
|
0
|
1
|
|
my ($class, $key, $value) = @_; |
121
|
0
|
|
|
|
|
|
$class->meta->{$key} = $value; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub getMetaAttribute { |
125
|
0
|
|
|
0
|
1
|
|
my ($class, $key) = @_; |
126
|
0
|
0
|
|
|
|
|
unless ($class->meta) { |
127
|
0
|
|
|
|
|
|
cluck("$class has no meta"); |
128
|
|
|
|
|
|
|
} |
129
|
0
|
|
|
|
|
|
return $class->meta->{$key}; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub _carp { |
133
|
0
|
0
|
|
0
|
|
|
my $thing = ref($_[0]) ? ref($_[0]) : $_[0]; |
134
|
0
|
|
|
|
|
|
carp("[$thing] $_[1]"); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub _croak { |
138
|
0
|
0
|
|
0
|
|
|
my $thing = ref($_[0]) ? ref($_[0]) : $_[0]; |
139
|
0
|
|
|
|
|
|
croak("[$thing] $_[1]"); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 SEE ALSO |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L, L |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 AUTHOR |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Copyright (C) 2005 Richard Hundt |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 LICENSE |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This library is free software and may be used under the same terms as Perl itself. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |