3 # BioPerl module for Bio::Factory::DriverFactory
5 # Cared for by Jason Stajich <jason@bioperl.org> and
6 # Hilmar Lapp <hlapp@gmx.net>
8 # Copyright Jason Stajich, Hilmar Lapp
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::Factory::DriverFactory - Base class for factory classes loading drivers
20 #this class is not instantiable
24 This a base class for factory classes that load drivers. Normally, you don't
25 instantiate this class directly.
31 User feedback is an integral part of the evolution of this
32 and other Bioperl modules. Send your comments and suggestions preferably
33 to one of the Bioperl mailing lists.
34 Your participation is much appreciated.
36 bioperl-l@bioperl.org - General discussion
37 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
41 Report bugs to the Bioperl bug tracking system to help us keep track
42 the bugs and their resolution. Bug reports can be submitted via the
45 http://bugzilla.open-bio.org/
47 =head1 AUTHOR - Jason Stajich
49 Email Jason Stajich E<lt>jason@bioperl.orgE<gt>
53 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
58 package Bio
::Factory
::DriverFactory
;
62 use vars
qw(%DRIVERS);
64 use base qw(Bio::Root::Root);
71 my ($class, @args) = @_;
72 my $self = $class->SUPER::new
(@args);
76 =head2 register_driver
78 Title : register_driver
79 Usage : $factory->register_driver("genscan", "Bio::Tools::Genscan");
80 Function: Registers a driver a factory class should be able to instantiate.
82 This method can be called both as an instance and as a class
86 Args : Key of the driver (string) and the module implementing the driver
92 my ($self, @args) = @_;
95 foreach my $drv (keys(%drivers)) {
96 # note that this doesn't care whether $self is the class or the object
97 $self->driver_table()->{$drv} = $drivers{$drv};
104 Usage : $table = $factory->driver_table();
105 Function: Returns a reference to the hash table storing associations of
106 methods with drivers.
108 You use this table to look up registered methods (keys) and
111 In this implementation the table is class-specific and therefore
112 shared by all instances. You can override this in a derived class,
113 but note that this method can be called both as an instance and a
116 This will be the table used by the object internally. You should
117 definitely know what you're doing if you modify the table's
118 contents. Modifications are shared by _all_ instances, those present
119 and those yet to be created.
121 Returns : A reference to a hash table.
128 my ($self, @args) = @_;
136 Usage : $module = $factory->get_driver("genscan");
137 Function: Returns the module implementing a driver registered under the
141 Args : Key of the driver (string).
146 my ($self, $key) = @_;
148 if(exists($self->driver_table()->{$key})) {
149 return $self->driver_table()->{$key};
157 Usage : $self->_load_module("Bio::Tools::Genscan");
158 Function: Loads up (like use) a module at run time on demand.
160 Returns : TRUE on success
166 my ($self, $name) = @_;
167 my ($module, $load, $m);
168 $module = "_<$name.pm";
169 return 1 if $main::{$module};
172 $load = File
::Spec
->catfile((split(/::/,$load)));
177 $self->throw("$load: $name cannot be found: ".$@
);