9 my $dbID = $storable_object->
dbID();
10 my $adaptor = $storable_object->adaptor();
14 Storable is a base
class for anything that can be stored.
15 It provides two getters/setters: dbID() and adaptor().
19 Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
20 Copyright [2016-2022] EMBL-European Bioinformatics Institute
22 Licensed under the Apache License,
Version 2.0 (the "License"); you may not use this file except in compliance with the License.
23 You may obtain a copy of the License at
27 Unless required by applicable law or agreed to in writing, software distributed under the License
28 is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 See the License for the specific language governing permissions and limitations under the License.
33 Please contact ehive-users@ebi.ac.uk mailing list with questions/suggestions.
37 The rest of the documentation details each of the object methods.
38 Internal methods are usually preceded with a _
48 use Scalar::Util qw(weaken);
52 use base ( 'Bio::EnsEMBL::Hive::Cacheable' ); # All the
Storable objects are attached to a pipeline, i.e. are
Cacheable 56 Args : pairs of ($method_name, $value)
58 Description : create a new
Storable object
67 my $self = bless {}, $class;
69 while(my ($method,$value) = splice(@_,0,2)) {
71 $self->$method($value);
82 Description : getter/setter
for the database
internal id 84 Caller : general,
set from adaptor on store
91 $self->{
'dbID'} = shift
if(@_);
92 return $self->{
'dbID'};
99 Description : getter/setter
for this objects Adaptor
101 Caller : general,
set from adaptor on store
110 $self->{
'adaptor'} = shift;
111 weaken( $self->{
'adaptor'} )
if defined( $self->{
'adaptor'} );
114 return $self->{
'adaptor'};
118 sub DESTROY { } #
"If you define an AUTOLOAD in your class, 119 # then Perl will call your AUTOLOAD to handle the DESTROY method. 120 # You can prevent this by defining an empty DESTROY (...)" -- perlobj
125 #print "Storable::AUTOLOAD : attempting to run '$AUTOLOAD' (".join(', ', @_).")\n"; 129 if($AUTOLOAD =~ /::(\w+)$/) {
130 my $name_to_parse = $1;
131 my ($AdaptorType, $is_an_id, $foo_id_method_name, $foo_obj_method_name)
134 unless($AdaptorType) {
135 throw(
"Storable::AUTOLOAD : could not parse '$name_to_parse'");
136 } elsif ($is_an_id) { # $name_to_parse was something like foo_dataflow_rule_id
141 $self->{$foo_id_method_name} = shift @_;
143 $self->{$foo_obj_method_name} = undef; # invalidate the
object itself
145 # attempt to lazy-load: 146 } elsif( !$self->{$foo_id_method_name} and my $foo_object=$self->{$foo_obj_method_name}) {
147 $self->{$foo_id_method_name} = $foo_object->dbID;
148 # warn "Lazy-loaded dbID (".$self->{$foo_id_method_name}.") from $AdaptorType object\n"; 151 return $self->{$foo_id_method_name};
154 }
else { # $name_to_parse was something like foo_dataflow_rule
158 if(@_) { # setter of the
object itself
159 $self->{$foo_obj_method_name} = shift @_;
161 $self->{$foo_id_method_name} = undef; # invalidate the object_id
163 # attempt to lazy-load: 164 } elsif( !$self->{$foo_obj_method_name} and my $foo_object_id = $self->{$foo_id_method_name}) {
165 my $collection = $self->hive_pipeline && $self->hive_pipeline->collection_of($AdaptorType);
167 if( $collection and $self->{$foo_obj_method_name} = $collection->find_one_by(
'dbID', $foo_object_id) ) { # careful: $AdaptorType may not be unique (aliases)
168 weaken($self->{$foo_obj_method_name});
169 # warn "Lazy-loading object from $AdaptorType collection\n"; 170 } elsif(my $adaptor = $self->adaptor) {
171 # warn "Lazy-loading object from $AdaptorType adaptor\n"; 172 $self->{$foo_obj_method_name} = $adaptor->db->get_adaptor( $AdaptorType )->fetch_by_dbID( $foo_object_id );
174 # warn "Cannot lazy-load $foo_obj_method_name because the ".ref($self)." is not attached to an adaptor"; 178 return $self->{$foo_obj_method_name};
181 } # choice of autoloadable functions
183 no strict
'refs'; ## no critic ProhibitNoStrict
public parse_underscored_id_name()