0
|
1 # $Id: ResultFactory.pm,v 1.3 2002/10/22 07:45:18 lapp Exp $
|
|
2 #
|
|
3 # BioPerl module for Bio::Search::Result::ResultFactory
|
|
4 #
|
|
5 # Cared for by Jason Stajich <jason@bioperl.org>
|
|
6 #
|
|
7 # Copyright Jason Stajich
|
|
8 #
|
|
9 # You may distribute this module under the same terms as perl itself
|
|
10
|
|
11 # POD documentation - main docs before the code
|
|
12
|
|
13 =head1 NAME
|
|
14
|
|
15 Bio::Search::Result::ResultFactory - A factory to create Bio::Search::Result::ResultI objects
|
|
16
|
|
17 =head1 SYNOPSIS
|
|
18
|
|
19 use Bio::Search::Result::ResultFactory;
|
|
20 my $factory = new Bio::Search::Result::ResultFactory();
|
|
21 my $resultobj = $factory->create(@args);
|
|
22
|
|
23 =head1 DESCRIPTION
|
|
24
|
|
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.
|
|
28
|
|
29 This object is for creating new Results.
|
|
30
|
|
31 =head1 FEEDBACK
|
|
32
|
|
33 =head2 Mailing Lists
|
|
34
|
|
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.
|
|
38
|
|
39 bioperl-l@bioperl.org - General discussion
|
|
40 http://bioperl.org/MailList.shtml - About the mailing lists
|
|
41
|
|
42 =head2 Reporting Bugs
|
|
43
|
|
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:
|
|
47
|
|
48 bioperl-bugs@bioperl.org
|
|
49 http://bugzilla.bioperl.org/
|
|
50
|
|
51 =head1 AUTHOR - Jason Stajich
|
|
52
|
|
53 Email jason@bioperl.org
|
|
54
|
|
55 Describe contact details here
|
|
56
|
|
57 =head1 CONTRIBUTORS
|
|
58
|
|
59 Additional contributors names and emails here
|
|
60
|
|
61 =head1 APPENDIX
|
|
62
|
|
63 The rest of the documentation details each of the object methods.
|
|
64 Internal methods are usually preceded with a _
|
|
65
|
|
66 =cut
|
|
67
|
|
68
|
|
69 # Let the code begin...
|
|
70
|
|
71
|
|
72 package Bio::Search::Result::ResultFactory;
|
|
73 use vars qw(@ISA $DEFAULT_TYPE);
|
|
74 use strict;
|
|
75
|
|
76 use Bio::Root::Root;
|
|
77 use Bio::Factory::ObjectFactoryI;
|
|
78
|
|
79 @ISA = qw(Bio::Root::Root Bio::Factory::ObjectFactoryI );
|
|
80
|
|
81 BEGIN {
|
|
82 $DEFAULT_TYPE = 'Bio::Search::Result::GenericResult';
|
|
83 }
|
|
84
|
|
85 =head2 new
|
|
86
|
|
87 Title : new
|
|
88 Usage : my $obj = new Bio::Search::Result::ResultFactory();
|
|
89 Function: Builds a new Bio::Search::Result::ResultFactory object
|
|
90 Returns : Bio::Search::Result::ResultFactory
|
|
91 Args :
|
|
92
|
|
93
|
|
94 =cut
|
|
95
|
|
96 sub new {
|
|
97 my($class,@args) = @_;
|
|
98
|
|
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;
|
|
103 }
|
|
104
|
|
105 =head2 create
|
|
106
|
|
107 Title : create
|
|
108 Usage : $factory->create(%args)
|
|
109 Function: Create a new L<Bio::Search::Result::ResultI> object
|
|
110 Returns : L<Bio::Search::Result::ResultI>
|
|
111 Args : hash of initialization parameters
|
|
112
|
|
113
|
|
114 =cut
|
|
115
|
|
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);
|
|
122 }
|
|
123
|
|
124
|
|
125 =head2 type
|
|
126
|
|
127 Title : type
|
|
128 Usage : $factory->type('Bio::Search::Result::GenericResult');
|
|
129 Function: Get/Set the Result creation type
|
|
130 Returns : string
|
|
131 Args : [optional] string to set
|
|
132
|
|
133
|
|
134 =cut
|
|
135
|
|
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; }
|
|
145 }
|
|
146 return $self->{'_type'} || $DEFAULT_TYPE;
|
|
147 }
|
|
148
|
|
149 1;
|