Bio/Search/Result/ResultFactory.pm

filter: Statementstmt 93.7% 30 / 32 Branchbran 62.5% 5 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 83.6% 46 / 55 CC 6 SCAR 8.9
CC
6
Cov
84%
type
4.3
create
2.0
new
2.0
CRAP 2.4
« Bio/Search/Hit/HitFactory.pm ↑ Summary Bio/Tree/TreeI.pm »
1 #
2 # BioPerl module for Bio::Search::Result::ResultFactory
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Jason Stajich <jason@bioperl.org>
7 #
8 # Copyright Jason Stajich
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::Search::Result::ResultFactory - A factory to create Bio::Search::Result::ResultI objects
17  
18 =head1 SYNOPSIS
19  
20 use Bio::Search::Result::ResultFactory;
21 my $factory = Bio::Search::Result::ResultFactory->new();
22 my $resultobj = $factory->create(@args);
23  
24 =head1 DESCRIPTION
25  
26 This is a general way of hiding the object creation process so that we
27 can dynamically change the objects that are created by the SearchIO
28 parser depending on what format report we are parsing.
29  
30 This object is for creating new Results.
31  
32 =head1 FEEDBACK
33  
34 =head2 Mailing Lists
35  
36 User feedback is an integral part of the evolution of this and other
37 Bioperl modules. Send your comments and suggestions preferably to
38 the Bioperl mailing list. Your participation is much appreciated.
39  
40 bioperl-l@bioperl.org - General discussion
41 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
42  
43 =head2 Support
44  
45 Please direct usage questions or support issues to the mailing list:
46  
47 I<bioperl-l@bioperl.org>
48  
49 rather than to the module maintainer directly. Many experienced and
50 reponsive experts will be able look at the problem and quickly
51 address it. Please include a thorough description of the problem
52 with code and data examples if at all possible.
53  
54 =head2 Reporting Bugs
55  
56 Report bugs to the Bioperl bug tracking system to help us keep track
57 of the bugs and their resolution. Bug reports can be submitted via the
58 web:
59  
60 https://github.com/bioperl/bioperl-live/issues
61  
62 =head1 AUTHOR - Jason Stajich
63  
64 Email jason@bioperl.org
65  
66 =head1 APPENDIX
67  
68 The rest of the documentation details each of the object methods.
69 Internal methods are usually preceded with a _
70  
71 =cut
72  
73  
74 # Let the code begin...
75  
76  
77 package Bio::Search::Result::ResultFactory;
78 11 $Bio::Search::Result::ResultFactory::VERSION = '1.7.8';
79 11 ▶use vars qw($DEFAULT_TYPE);
Subroutine BEGIN: called CC=1 SCAR=0.0
80 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82  
83 11 ▶use base qw(Bio::Root::Root Bio::Factory::ObjectFactoryI);
Subroutine BEGIN: called CC=1 SCAR=0.0
84  
85 11 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
86 11 $DEFAULT_TYPE = 'Bio::Search::Result::GenericResult';
87 }
88  
89 =head2 new
90  
91 Title : new
92 Usage : my $obj = Bio::Search::Result::ResultFactory->new();
93 Function: Builds a new Bio::Search::Result::ResultFactory object
94 Returns : Bio::Search::Result::ResultFactory
95 Args :
96  
97  
98 =cut
99  
100 16 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
101 16 my($class,@args) = @_;
102  
103 16 my $self = $class->SUPER::new(@args);
104 16 my ($type) = $self->_rearrange([qw(TYPE)],@args);
105 16 ▶ $self->type($type) if defined $type;
Branch: 1 branch
BranchTrueFalseTotal
if defined $type 16 0 16
106 16 return $self;
107 }
108  
109 =head2 create
110  
111 Title : create
112 Usage : $factory->create(%args)
113 Function: Create a new L<Bio::Search::Result::ResultI> object
114 Returns : L<Bio::Search::Result::ResultI>
115 Args : hash of initialization parameters
116  
117  
118 =cut
119  
120 16 ▶sub create{
Subroutine create: called CC=2 SCAR=7.1
Pod documented
121 16 my ($self,@args) = @_;
122 16 my $type = $self->type;
123 16 eval { $self->_load_module($type) };
124 0 ▶ if( $@ ) { $self->throw("Unable to load module $type: $@"); }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 16 16
125 16 return $type->new(@args);
126 }
127  
128  
129 =head2 type
130  
131 Title : type
132 Usage : $factory->type('Bio::Search::Result::GenericResult');
133 Function: Get/Set the Result creation type
134 Returns : string
135 Args : [optional] string to set
136  
137  
138 =cut
139  
140 32 ▶sub type{
Subroutine type: called CC=4 SCAR=14.6
Pod documented
141 32 my ($self,$type) = @_;
142 32 ▶ if( defined $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type) 16 16 32
143 # redundancy with the create method which also calls _load_module
144 # I know - but this is not a highly called object so I am going
145 # to leave it in
146 16 eval {$self->_load_module($type) };
147 0 ▶ if( $@ ){ $self->warn("Cannot find module $type, unable to set type"); }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 16 16
148 16 else { $self->{'_type'} = $type; }
149 }
150 32 ▶ return $self->{'_type'} || $DEFAULT_TYPE;
Condition33%1/3
$self->{'_type'} || $Bio::Search::Result::ResultFactory::DEFAULT_TYPE
l!l&&r!l&&!r
3200
MC/DC0%0/2
$self->{'_type'} || $Bio::Search::Result::ResultFactory::DEFAULT_TYPE
$self->{'_type'} $Bio::Search::Result::ResultFactory::DEFAULT_TYPE
Truth table33%1/3
A || B
A= $self->{'_type'}B= $Bio::Search::Result::ResultFactory::DEFAULT_TYPE
ABresult
1X1
011
000
151 }
152  
153 11 1;
« Bio/Search/Hit/HitFactory.pm ↑ Summary Bio/Tree/TreeI.pm »