2 # BioPerl module for Bio::ParameterBaseI
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Chris Fields <cjfields at bioperl dot org>
8 # Copyright Chris Fields
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::ParameterBaseI - Simple interface class for any parameter-related data such
17 as IDs, database name, program arguments, and other odds and ends.
21 # Bio::DB::MyParams implements Bio::ParameterBaseI
23 @params = (-db => 'protein',
27 $pobj->Bio::DB::MyDBParams->new();
29 # sets only parameters passed; results in a state change if any parameter
30 # passed is new or differs from previously set value
32 $pobj->set_params(@params);
34 # reset all parameters (sets to undef); results in a state change
36 $pobj->reset_params();
38 # resets parameters to those in %param (sets all others to undef); resets the
39 # object state to indicate change.
41 $pobj->reset_params(@params);
43 # direct get/set; results in a state change if any parameter passed is new or
44 # differs from previously set value
46 $pobj->db('nucleotide');
49 # retrieve list containing set defined parameters
51 %myparams = $pobj->get_parameters();
53 # checks whether the state of the object has changed (i.e. parameter has
56 if ($pobj->parameters_changed) {
59 # return cached search
62 # available parameters
64 @params = $pobj->available_parameters();
66 # retrieve string (URI, query, etc); calling to* methods changes object state
67 # to indicate data hasn't changed (so future calls to parameters_changed()
70 $query = $pobj->to_string(); # returns raw string
71 $uri = $pobj->to_uri(); # returns URI-based object
72 $uri = $pobj->to_my_data_struct(); # returns implemenation-specific data structure
77 This is a class interface which focuses on common parameter-related tasks such
78 as building simple database queries, URI-related requests, program arguments,
81 Implementing classes use the following ways to set parameters:
83 1) Create a new instance of a ParameterBaseI-implementing object.
85 $pobj->Bio::DB::MyParamClass->new(-db => 'local', -id => \@ids);
87 2) Pass the parameters as a hash or array to set_parameters(), which sets the
88 parameters listed in the hash but leaves all others as is.
90 $pobj->set_parameters(-retmax => 100, -retstart => 20);
92 3) Pass the parameters as a hash or array to reset_parameters(), which sets the
93 parameters listed in the hash and resets everything else.
95 $pobj->reset_parameters(-term => 'pyrimidine'); # sets db and id to undef
97 4) Pass values using specific getter/setters.
99 $pobj->id(\@ids); # sets IDs
101 There is no restriction on what one uses to set up individual parameter
102 getter/setters, though there are some other options implemented in BioPerl (for
103 instance, Bio::Root::RootI::_set_from_args()).
105 A key requirement is there be a way to detect changes in the state of the
106 ParameterBaseI object so that any object with a Bio::ParameterBaseI can decide
107 whether to submit a new request or return cached data. State changes are
108 revealed by the returned values of the parameters_changed() method, which is a
109 simple boolean set to TRUE when the object is first instantiated or parameters
112 When retrieving anything using the implementation-specific to_* methods (such as
113 to_query, to_string, to_uri, to_request, etc), the ParameterBaseI object state
114 is set to FALSE to indicate the data has been accessed and indicate reaccessing
115 will retrieve the same value. The observing object can then independently decide
116 whether to rerun the cached query or return a previously cached result.
118 One can also use indiviual getter/setters to retrieve single parameter values as
119 well as use parameter_hash() to retrieve all of the parameters in one go as a
120 hash. To check which parameters are available use available_parameters(). Args
127 User feedback is an integral part of the
128 evolution of this and other Bioperl modules. Send
129 your comments and suggestions preferably to one
130 of the Bioperl mailing lists. Your participation
133 bioperl-l@lists.open-bio.org - General discussion
134 http://www.bioperl.org/wiki/Mailing_lists - About the mailing lists
138 Please direct usage questions or support issues to the mailing list:
140 I<bioperl-l@bioperl.org>
142 rather than to the module maintainer directly. Many experienced and
143 reponsive experts will be able look at the problem and quickly
144 address it. Please include a thorough description of the problem
145 with code and data examples if at all possible.
147 =head2 Reporting Bugs
149 Report bugs to the Bioperl bug tracking system to
150 help us keep track the bugs and their resolution.
151 Bug reports can be submitted via the web.
153 https://redmine.open-bio.org/projects/bioperl/
157 Email cjfields at bioperl dot org
161 The rest of the documentation details each of the
162 object methods. Internal methods are usually
167 # Let the code begin...
169 package Bio
::ParameterBaseI
;
173 use base
qw(Bio::Root::RootI);
175 =head2 set_parameters
177 Title : set_parameters
178 Usage : $pobj->set_parameters(%params);
179 Function: sets the parameters listed in the hash or array
181 Args : [optional] hash or array of parameter/values.
186 shift->throw_not_implemented;
189 =head2 reset_parameters
191 Title : reset_parameters
192 Usage : resets values
193 Function: resets parameters to either undef or value in passed hash
195 Args : [optional] hash of parameter-value pairs
199 sub reset_parameters
{
200 shift->throw_not_implemented;
203 =head2 parameters_changed
205 Title : parameters_changed
206 Usage : if ($pobj->parameters_changed) {...}
207 Function: Returns boolean true (1) if parameters have changed
208 Returns : Boolean (0 or 1)
209 Args : [optional] Boolean
213 sub parameters_changed
{
214 shift->throw_not_implemented;
217 =head2 available_parameters
219 Title : available_parameters
220 Usage : @params = $pobj->available_parameters()
221 Function: Returns a list of the available parameters
222 Returns : Array of parameters
223 Args : [optional, implementation-dependent] string for returning subset of
228 sub available_parameters
{
229 shift->throw_not_implemented;
232 =head2 get_parameters
234 Title : get_parameters
235 Usage : %params = $pobj->get_parameters;
236 Function: Returns list of key-value pairs of parameter => value
237 Returns : List of key-value pairs
238 Args : [optional] A string is allowed if subsets are wanted or (if a
239 parameter subset is default) 'all' to return all parameters
244 shift->throw_not_implemented;
249 All to_* methods are implementation-specific