Sync'ed RichSeqI with the implementation. RichSeq provides backward
[bioperl-live.git] / Bio / Search / Hit / HitFactory.pm
blob87474fe84429310372e49c9a702eaf4ecb044388
1 # $Id$
3 # BioPerl module for Bio::Search::Hit::HitFactory
5 # Cared for by Jason Stajich <jason@bioperl.org>
7 # Copyright Jason Stajich
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
13 =head1 NAME
15 Bio::Search::Hit::HitFactory - A factory to create Bio::Search::Hit::HitI objects
17 =head1 SYNOPSIS
19 use Bio::Search::Hit::HitFactory;
20 my $factory = new Bio::Search::Hit::HitFactory();
21 my $resultobj = $factory->create(@args);
23 =head1 DESCRIPTION
25 This is a general way of hiding the object creation process so that we
26 can dynamically change the objects that are created by the SearchIO
27 parser depending on what format report we are parsing.
29 This object is for creating new Hits.
31 =head1 FEEDBACK
33 =head2 Mailing Lists
35 User feedback is an integral part of the evolution of this and other
36 Bioperl modules. Send your comments and suggestions preferably to
37 the Bioperl mailing list. Your participation is much appreciated.
39 bioperl-l@bioperl.org - General discussion
40 http://bioperl.org/MailList.shtml - About the mailing lists
42 =head2 Reporting Bugs
44 Report bugs to the Bioperl bug tracking system to help us keep track
45 of the bugs and their resolution. Bug reports can be submitted via
46 email or the web:
48 bioperl-bugs@bioperl.org
49 http://bugzilla.bioperl.org/
51 =head1 AUTHOR - Jason Stajich
53 Email jason@bioperl.org
55 Describe contact details here
57 =head1 CONTRIBUTORS
59 Additional contributors names and emails here
61 =head1 APPENDIX
63 The rest of the documentation details each of the object methods.
64 Internal methods are usually preceded with a _
66 =cut
69 # Let the code begin...
72 package Bio::Search::Hit::HitFactory;
73 use vars qw(@ISA $DEFAULT_TYPE);
74 use strict;
76 use Bio::Root::Root;
77 use Bio::Factory::ObjectFactoryI;
79 @ISA = qw(Bio::Root::Root Bio::Factory::ObjectFactoryI );
81 BEGIN {
82 $DEFAULT_TYPE = 'Bio::Search::Hit::GenericHit';
85 =head2 new
87 Title : new
88 Usage : my $obj = new Bio::Search::Hit::HitFactory();
89 Function: Builds a new Bio::Search::Hit::HitFactory object
90 Returns : Bio::Search::Hit::HitFactory
91 Args :
94 =cut
96 sub new {
97 my($class,@args) = @_;
99 my $self = $class->SUPER::new(@args);
100 my ($type) = $self->_rearrange([qw(TYPE)],@args);
101 $self->type($type) if defined $type;
102 return $self;
105 =head2 create
107 Title : create
108 Usage : $factory->create(%args)
109 Function: Create a new L<Bio::Search::Hit::HitI> object
110 Returns : L<Bio::Search::Hit::HitI>
111 Args : hash of initialization parameters
114 =cut
116 sub create{
117 my ($self,@args) = @_;
118 my $type = $self->type;
119 eval { $self->_load_module($type) };
120 if( $@ ) { $self->throw("Unable to load module $type"); }
121 return $type->new(@args);
125 =head2 type
127 Title : type
128 Usage : $factory->type('Bio::Search::Hit::GenericHit');
129 Function: Get/Set the Hit creation type
130 Returns : string
131 Args : [optional] string to set
134 =cut
136 sub type{
137 my ($self,$type) = @_;
138 if( defined $type ) {
139 # redundancy with the create method which also calls _load_module
140 # I know - but this is not a highly called object so I am going
141 # to leave it in
142 eval {$self->_load_module($type) };
143 if( $@ ){ $self->warn("Cannot find module $type, unable to set type"); }
144 else { $self->{'_type'} = $type; }
146 return $self->{'_type'} || $DEFAULT_TYPE;