2 # BioPerl module for Bio::Factory::DriverFactory
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Jason Stajich <jason@bioperl.org> and
7 # Hilmar Lapp <hlapp@gmx.net>
9 # Copyright Jason Stajich, Hilmar Lapp
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
17 Bio::Factory::DriverFactory - Base class for factory classes loading drivers
21 #this class is not instantiable
25 This a base class for factory classes that load drivers. Normally, you don't
26 instantiate this class directly.
32 User feedback is an integral part of the evolution of this
33 and other Bioperl modules. Send your comments and suggestions preferably
34 to one of the Bioperl mailing lists.
35 Your participation is much appreciated.
37 bioperl-l@bioperl.org - General discussion
38 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
42 Please direct usage questions or support issues to the mailing list:
44 I<bioperl-l@bioperl.org>
46 rather than to the module maintainer directly. Many experienced and
47 reponsive experts will be able look at the problem and quickly
48 address it. Please include a thorough description of the problem
49 with code and data examples if at all possible.
53 Report bugs to the Bioperl bug tracking system to help us keep track
54 the bugs and their resolution. Bug reports can be submitted via the
57 https://github.com/bioperl/bioperl-live/issues
59 =head1 AUTHOR - Jason Stajich
61 Email Jason Stajich E<lt>jason@bioperl.orgE<gt>
65 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
70 package Bio
::Factory
::DriverFactory
;
74 use vars
qw(%DRIVERS);
76 use base qw(Bio::Root::Root);
83 my ($class, @args) = @_;
84 my $self = $class->SUPER::new
(@args);
88 =head2 register_driver
90 Title : register_driver
91 Usage : $factory->register_driver("genscan", "Bio::Tools::Genscan");
92 Function: Registers a driver a factory class should be able to instantiate.
94 This method can be called both as an instance and as a class
98 Args : Key of the driver (string) and the module implementing the driver
103 sub register_driver
{
104 my ($self, @args) = @_;
107 foreach my $drv (keys(%drivers)) {
108 # note that this doesn't care whether $self is the class or the object
109 $self->driver_table()->{$drv} = $drivers{$drv};
116 Usage : $table = $factory->driver_table();
117 Function: Returns a reference to the hash table storing associations of
118 methods with drivers.
120 You use this table to look up registered methods (keys) and
123 In this implementation the table is class-specific and therefore
124 shared by all instances. You can override this in a derived class,
125 but note that this method can be called both as an instance and a
128 This will be the table used by the object internally. You should
129 definitely know what you're doing if you modify the table's
130 contents. Modifications are shared by _all_ instances, those present
131 and those yet to be created.
133 Returns : A reference to a hash table.
140 my ($self, @args) = @_;
148 Usage : $module = $factory->get_driver("genscan");
149 Function: Returns the module implementing a driver registered under the
153 Args : Key of the driver (string).
158 my ($self, $key) = @_;
160 if(exists($self->driver_table()->{$key})) {
161 return $self->driver_table()->{$key};
169 Usage : $self->_load_module("Bio::Tools::Genscan");
170 Function: Loads up (like use) a module at run time on demand.
172 Returns : TRUE on success
178 my ($self, $name) = @_;
179 my ($module, $load, $m);
180 $module = "_<$name.pm";
181 return 1 if $main::{$module};
184 $load = File
::Spec
->catfile((split(/::/,$load)));
189 $self->throw("$load: $name cannot be found: ".$@
);