| 1 | package Bio::Root::Root; | ||||||||||||||||||||||||||||
| 2 | 582 | $Bio::Root::Root::VERSION = '1.7.8'; | |||||||||||||||||||||||||||
| 3 | 582 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 582 | ▶ | use Bio::Root::IO; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 582 | ▶ | use Scalar::Util qw(blessed reftype); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 582 | ▶ | use base qw(Bio::Root::RootI); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Bio::Root::Root - implementation of Bio::Root::RootI interface | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # Any Bioperl-compliant object is a RootI compliant object | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # Here's how to throw and catch an exception using the eval-based syntax. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | $obj->throw("This is an exception"); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | eval { | ||||||||||||||||||||||||||||
| 21 | $obj->throw("This is catching an exception"); | ||||||||||||||||||||||||||||
| 22 | }; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | if( $@ ) { | ||||||||||||||||||||||||||||
| 25 | print "Caught exception"; | ||||||||||||||||||||||||||||
| 26 | } else { | ||||||||||||||||||||||||||||
| 27 | print "no exception"; | ||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # Alternatively, using the new typed exception syntax in the throw() call: | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | $obj->throw( -class => 'Bio::Root::BadParameter', | ||||||||||||||||||||||||||||
| 33 | -text => "Can not open file $file", | ||||||||||||||||||||||||||||
| 34 | -value => $file ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # Want to see debug() outputs for this object | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | my $obj = Bio::Object->new(-verbose=>1); | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | my $obj = Bio::Object->new(%args); | ||||||||||||||||||||||||||||
| 41 | $obj->verbose(2); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # Print debug messages which honour current verbosity setting | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | $obj->debug("Boring output only to be seen if verbose > 0\n"); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # Deep-object copy | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | my $clone = $obj->clone; | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | This is a hashref-based implementation of the Bio::Root::RootI | ||||||||||||||||||||||||||||
| 54 | interface. Most Bioperl objects should inherit from this. | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | See the documentation for L<Bio::Root::RootI> for most of the methods | ||||||||||||||||||||||||||||
| 57 | implemented by this module. Only overridden methods are described | ||||||||||||||||||||||||||||
| 58 | here. | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head2 Throwing Exceptions | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | One of the functionalities that L<Bio::Root::RootI> provides is the | ||||||||||||||||||||||||||||
| 63 | ability to L<throw>() exceptions with pretty stack traces. Bio::Root::Root | ||||||||||||||||||||||||||||
| 64 | enhances this with the ability to use L<Error> (available from CPAN) | ||||||||||||||||||||||||||||
| 65 | if it has also been installed. | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | If L<Error> has been installed, L<throw>() will use it. This causes an | ||||||||||||||||||||||||||||
| 68 | Error.pm-derived object to be thrown. This can be caught within a | ||||||||||||||||||||||||||||
| 69 | C<catch{}> block, from which you can extract useful bits of | ||||||||||||||||||||||||||||
| 70 | information. If L<Error> is not installed, it will use the | ||||||||||||||||||||||||||||
| 71 | L<Bio::Root::RootI>-based exception throwing facilty. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =head2 Typed Exception Syntax | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | The typed exception syntax of L<throw>() has the advantage of plainly | ||||||||||||||||||||||||||||
| 76 | indicating the nature of the trouble, since the name of the class | ||||||||||||||||||||||||||||
| 77 | is included in the title of the exception output. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | To take advantage of this capability, you must specify arguments | ||||||||||||||||||||||||||||
| 80 | as named parameters in the L<throw>() call. Here are the parameters: | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =over 4 | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =item -class | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | name of the class of the exception. | ||||||||||||||||||||||||||||
| 87 | This should be one of the classes defined in L<Bio::Root::Exception>, | ||||||||||||||||||||||||||||
| 88 | or a custom error of yours that extends one of the exceptions | ||||||||||||||||||||||||||||
| 89 | defined in L<Bio::Root::Exception>. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =item -text | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | a sensible message for the exception | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =item -value | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | the value causing the exception or $!, if appropriate. | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =back | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | Note that Bio::Root::Exception does not need to be imported into | ||||||||||||||||||||||||||||
| 102 | your module (or script) namespace in order to throw exceptions | ||||||||||||||||||||||||||||
| 103 | via Bio::Root::Root::throw(), since Bio::Root::Root imports it. | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head2 Try-Catch-Finally Support | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | In addition to using an eval{} block to handle exceptions, you can | ||||||||||||||||||||||||||||
| 108 | also use a try-catch-finally block structure if L<Error> has been | ||||||||||||||||||||||||||||
| 109 | installed in your system (available from CPAN). See the documentation | ||||||||||||||||||||||||||||
| 110 | for Error for more details. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | Here's an example. See the L<Bio::Root::Exception> module for | ||||||||||||||||||||||||||||
| 113 | other pre-defined exception types: | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | my $IN; | ||||||||||||||||||||||||||||
| 116 | try { | ||||||||||||||||||||||||||||
| 117 | open $IN, '<', $file or $obj->throw( -class => 'Bio::Root::FileOpenException', | ||||||||||||||||||||||||||||
| 118 | -text => "Cannot read file '$file'", | ||||||||||||||||||||||||||||
| 119 | -value => $!); | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | catch Bio::Root::BadParameter with { | ||||||||||||||||||||||||||||
| 122 | my $err = shift; # get the Error object | ||||||||||||||||||||||||||||
| 123 | # Perform specific exception handling code for the FileOpenException | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | catch Bio::Root::Exception with { | ||||||||||||||||||||||||||||
| 126 | my $err = shift; # get the Error object | ||||||||||||||||||||||||||||
| 127 | # Perform general exception handling code for any Bioperl exception. | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | otherwise { | ||||||||||||||||||||||||||||
| 130 | # A catch-all for any other type of exception | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | finally { | ||||||||||||||||||||||||||||
| 133 | # Any code that you want to execute regardless of whether or not | ||||||||||||||||||||||||||||
| 134 | # an exception occurred. | ||||||||||||||||||||||||||||
| 135 | }; | ||||||||||||||||||||||||||||
| 136 | # the ending semicolon is essential! | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head1 AUTHOR Steve Chervitz | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | Ewan Birney, Lincoln Stein | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 582 | our ($DEBUG, $ID, $VERBOSITY, $ERRORLOADED, $CLONE_CLASS); | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 582 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=8 SCAR=30.8
| |||||||||||||||||||||||||||||
| 147 | 582 | $ID = 'Bio::Root::Root'; | |||||||||||||||||||||||||||
| 148 | 582 | $DEBUG = 0; | |||||||||||||||||||||||||||
| 149 | 582 | $VERBOSITY = 0; | |||||||||||||||||||||||||||
| 150 | 582 | $ERRORLOADED = 0; | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | # Check whether or not Error.pm is available. | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | # $main::DONT_USE_ERROR is intended for testing purposes and also | ||||||||||||||||||||||||||||
| 155 | # when you don't want to use the Error module, even if it is installed. | ||||||||||||||||||||||||||||
| 156 | # Just put a INIT { $DONT_USE_ERROR = 1; } at the top of your script. | ||||||||||||||||||||||||||||
| 157 | 582 | ▶ | if( not $main::DONT_USE_ERROR ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 582 | ▶ | if ( eval "require Error; 1;" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 582 | import Error qw(:try); | |||||||||||||||||||||||||||
| 160 | 582 | require Bio::Root::Exception; | |||||||||||||||||||||||||||
| 161 | 582 | $ERRORLOADED = 1; | |||||||||||||||||||||||||||
| 162 | 582 | $Error::Debug = 1; # enable verbose stack trace | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | 582 | ▶ | if( !$ERRORLOADED ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 0 | require Carp; import Carp qw( confess ); | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # set up _dclone() | ||||||||||||||||||||||||||||
| 170 | 582 | for my $class (qw(Clone Storable)) { | |||||||||||||||||||||||||||
| 171 | 582 | eval "require $class; 1;"; | |||||||||||||||||||||||||||
| 172 | 582 | ▶ | if (!$@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 582 | $CLONE_CLASS = $class; | |||||||||||||||||||||||||||
| 174 | 582 | ▶ | if ($class eq 'Clone') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 582 | ▶ | *Bio::Root::Root::_dclone = sub {shift; return Clone::clone(shift)}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | *Bio::Root::Root::_dclone = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 178 | 0 | shift; | |||||||||||||||||||||||||||
| 179 | 0 | local $Storable::Deparse = 1; | |||||||||||||||||||||||||||
| 180 | 0 | local $Storable::Eval = 1; | |||||||||||||||||||||||||||
| 181 | 0 | return Storable::dclone(shift); | |||||||||||||||||||||||||||
| 182 | 0 | }; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | 582 | last; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | 582 | ▶ | if (!defined $CLONE_CLASS) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 0 | ▶ | *Bio::Root::Root::_dclone = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 189 | 0 | my ($self, $orig, $level) = @_; | |||||||||||||||||||||||||||
| 190 | 0 | ▶ | my $class = Scalar::Util::blessed($orig) || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
builtin::blessed($orig) || ''
MC/DC0%0/1
builtin::blessed($orig) || ''
builtin::blessed($orig)
Truth table0%0/2
A
A= builtin::blessed($orig)
| |||||||||||||||||||||||||||||
| 191 | 0 | ▶ | my $reftype = Scalar::Util::reftype($orig) || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
builtin::reftype($orig) || ''
MC/DC0%0/1
builtin::reftype($orig) || ''
builtin::reftype($orig)
Truth table0%0/2
A
A= builtin::reftype($orig)
| |||||||||||||||||||||||||||||
| 192 | 0 | my $data; | |||||||||||||||||||||||||||
| 193 | 0 | ▶ | if (!$reftype) { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 194 | 0 | $data = $orig | |||||||||||||||||||||||||||
| 195 | } elsif ($reftype eq "ARRAY") { | ||||||||||||||||||||||||||||
| 196 | 0 | $data = [map $self->_dclone($_), @$orig]; | |||||||||||||||||||||||||||
| 197 | } elsif ($reftype eq "HASH") { | ||||||||||||||||||||||||||||
| 198 | 0 | $data = { map { $_ => $self->_dclone($orig->{$_}) } keys %$orig }; | |||||||||||||||||||||||||||
| 199 | } elsif ($reftype eq 'CODE') { # nothing, maybe shallow copy? | ||||||||||||||||||||||||||||
| 200 | 0 | $self->throw("Code reference cloning not supported; install Clone or Storable from CPAN"); | |||||||||||||||||||||||||||
| 201 | 0 | } else { $self->throw("What type is $_?")} | |||||||||||||||||||||||||||
| 202 | 0 | ▶ | if ($class) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | bless $data, $class; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | 0 | $data; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | 0 | } | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 582 | $main::DONT_USE_ERROR; # so that perl -w won't warn "used only once" | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | =head2 new | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | Purpose : generic instantiation function can be overridden if | ||||||||||||||||||||||||||||
| 215 | special needs of a module cannot be done in _initialize | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | =cut | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 77649 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||
| 220 | # my ($class, %param) = @_; | ||||||||||||||||||||||||||||
| 221 | 77649 | my $class = shift; | |||||||||||||||||||||||||||
| 222 | 77649 | my $self = {}; | |||||||||||||||||||||||||||
| 223 | 77649 | ▶ | bless $self, ref($class) || $class; | ||||||||||||||||||||||||||
|
Condition66%2/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table66%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 77649 | ▶ | if(@_ > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | # if the number of arguments is odd but at least 3, we'll give | ||||||||||||||||||||||||||||
| 227 | # it a try to find -verbose | ||||||||||||||||||||||||||||
| 228 | 63429 | ▶ | shift if @_ % 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 63429 | my %param = @_; | |||||||||||||||||||||||||||
| 230 | ## See "Comments" above regarding use of _rearrange(). | ||||||||||||||||||||||||||||
| 231 | 63429 | ▶ | $self->verbose($param{'-VERBOSE'} || $param{'-verbose'}); | ||||||||||||||||||||||||||
|
Condition66%2/3
$param{'-VERBOSE'} || $param{'-verbose'}
MC/DC50%1/2
$param{'-VERBOSE'} || $param{'-verbose'}
$param{'-VERBOSE'}
$param{'-verbose'}
Truth table66%2/3
A || B
A= $param{'-VERBOSE'}B= $param{'-verbose'}
| |||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | 77649 | return $self; | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | =head2 clone | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | Title : clone | ||||||||||||||||||||||||||||
| 240 | Usage : my $clone = $obj->clone(); | ||||||||||||||||||||||||||||
| 241 | or | ||||||||||||||||||||||||||||
| 242 | my $clone = $obj->clone( -start => 110 ); | ||||||||||||||||||||||||||||
| 243 | Function: Deep recursion copying of any object via Storable dclone() | ||||||||||||||||||||||||||||
| 244 | Returns : A cloned object. | ||||||||||||||||||||||||||||
| 245 | Args : Any named parameters provided will be set on the new object. | ||||||||||||||||||||||||||||
| 246 | Unnamed parameters are ignored. | ||||||||||||||||||||||||||||
| 247 | Comments: Where possible, faster clone methods are used, in order: | ||||||||||||||||||||||||||||
| 248 | Clone::Fast::clone(), Clone::clone(), Storable::dclone. If neither | ||||||||||||||||||||||||||||
| 249 | is present, a pure perl fallback (not very well tested) is used | ||||||||||||||||||||||||||||
| 250 | instead. Storable dclone() cannot clone CODE references. Therefore, | ||||||||||||||||||||||||||||
| 251 | any CODE reference in your original object will remain, but will not | ||||||||||||||||||||||||||||
| 252 | exist in the cloned object. This should not be used for anything | ||||||||||||||||||||||||||||
| 253 | other than cloning of simple objects. Developers of subclasses are | ||||||||||||||||||||||||||||
| 254 | encouraged to override this method with one of their own. | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | =cut | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 708 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||
| 259 | 708 | my ($orig, %named_params) = @_; | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 708 | ▶ | __PACKAGE__->throw("Can't call clone() as a class method") unless | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $orig and $orig->isa("Bio::Root::Root")
MC/DC0%0/2
ref $orig and $orig->isa("Bio::Root::Root")
ref $orig
$orig->isa("Bio::Root::Root")
Truth table33%1/3
A and B
A= ref $origB= $orig->isa("Bio::Root::Root")
| |||||||||||||||||||||||||||||
| 262 | ref $orig && $orig->isa('Bio::Root::Root'); | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | # Can't dclone CODE references... | ||||||||||||||||||||||||||||
| 265 | # Should we shallow copy these? Should be harmless for these specific | ||||||||||||||||||||||||||||
| 266 | # methods... | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | my %put_these_back = ( | ||||||||||||||||||||||||||||
| 269 | 708 | _root_cleanup_methods => $orig->{'_root_cleanup_methods'}, | |||||||||||||||||||||||||||
| 270 | ); | ||||||||||||||||||||||||||||
| 271 | 708 | delete $orig->{_root_cleanup_methods}; | |||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | # call the proper clone method, set lazily above | ||||||||||||||||||||||||||||
| 274 | 708 | my $clone = __PACKAGE__->_dclone($orig); | |||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 708 | $orig->{_root_cleanup_methods} = $put_these_back{_root_cleanup_methods}; | |||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 708 | foreach my $key (grep { /^-/ } keys %named_params) { | |||||||||||||||||||||||||||
| 279 | 2 | my $method = $key; | |||||||||||||||||||||||||||
| 280 | 2 | $method =~ s/^-//; | |||||||||||||||||||||||||||
| 281 | 2 | ▶ | if ($clone->can($method)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | 2 | $clone->$method($named_params{$key}) | |||||||||||||||||||||||||||
| 283 | } else { | ||||||||||||||||||||||||||||
| 284 | 0 | $orig->warn("Parameter $method is not a method for ".ref($clone)); | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | 708 | return $clone; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | =head2 _dclone | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | Title : clone | ||||||||||||||||||||||||||||
| 293 | Usage : my $clone = $obj->_dclone($ref); | ||||||||||||||||||||||||||||
| 294 | or | ||||||||||||||||||||||||||||
| 295 | my $clone = $obj->_dclone($ref); | ||||||||||||||||||||||||||||
| 296 | Function: Returns a copy of the object passed to it (a deep clone) | ||||||||||||||||||||||||||||
| 297 | Returns : clone of passed argument | ||||||||||||||||||||||||||||
| 298 | Args : Anything | ||||||||||||||||||||||||||||
| 299 | NOTE : This differs from clone significantly in that it does not clone | ||||||||||||||||||||||||||||
| 300 | self, but the data passed to it. This code may need to be optimized | ||||||||||||||||||||||||||||
| 301 | or overridden as needed. | ||||||||||||||||||||||||||||
| 302 | Comments: This is set in the BEGIN block to take advantage of optimized | ||||||||||||||||||||||||||||
| 303 | cloning methods if Clone or Storable is present, falling back to a | ||||||||||||||||||||||||||||
| 304 | pure perl kludge. May be moved into a set of modules if the need | ||||||||||||||||||||||||||||
| 305 | arises. At the moment, code ref cloning is not supported. | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | =cut | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | =head2 verbose | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | Title : verbose | ||||||||||||||||||||||||||||
| 312 | Usage : $self->verbose(1) | ||||||||||||||||||||||||||||
| 313 | Function: Sets verbose level for how ->warn behaves | ||||||||||||||||||||||||||||
| 314 | -1 = no warning | ||||||||||||||||||||||||||||
| 315 | 0 = standard, small warning | ||||||||||||||||||||||||||||
| 316 | 1 = warning with stack trace | ||||||||||||||||||||||||||||
| 317 | 2 = warning becomes throw | ||||||||||||||||||||||||||||
| 318 | Returns : The current verbosity setting (integer between -1 to 2) | ||||||||||||||||||||||||||||
| 319 | Args : -1,0,1 or 2 | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | =cut | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 323037 | ▶ | sub verbose { | ||||||||||||||||||||||||||
|
Subroutine
verbose: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 325 | 323037 | my ($self,$value) = @_; | |||||||||||||||||||||||||||
| 326 | # allow one to set global verbosity flag | ||||||||||||||||||||||||||||
| 327 | 323037 | ▶ | return $DEBUG if $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 328 | 323037 | ▶ | return $VERBOSITY unless ref $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 323037 | ▶ | if (defined $value || ! defined $self->{'_root_verbose'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $value or not defined $self->{"_root_verbose"}
MC/DC100%2/2
defined $value or not defined $self->{"_root_verbose"}
defined $value
not defined $self->{"_root_verbose"}
Truth table100%3/3
A or not(B)
A= defined $valueB= not defined $self->{"_root_verbose"}
| |||||||||||||||||||||||||||||
| 331 | 121824 | ▶ | $self->{'_root_verbose'} = $value || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$value || 0
MC/DC100%1/1
$value || 0
$value
Truth table100%2/2
A
A= $value
| |||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | 323037 | return $self->{'_root_verbose'}; | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | =head2 _register_for_cleanup | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | =cut | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 50687 | ▶ | sub _register_for_cleanup { | ||||||||||||||||||||||||||
|
Subroutine
_register_for_cleanup: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 341 | 50687 | my ($self,$method) = @_; | |||||||||||||||||||||||||||
| 342 | 50687 | ▶ | if ($method) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 343 | 50687 | ▶ | if(! exists($self->{'_root_cleanup_methods'})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | 49068 | $self->{'_root_cleanup_methods'} = []; | |||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||
| 346 | 50687 | push(@{$self->{'_root_cleanup_methods'}},$method); | |||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | =head2 _unregister_for_cleanup | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | =cut | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 0 | ▶ | sub _unregister_for_cleanup { | ||||||||||||||||||||||||||
|
Subroutine
_unregister_for_cleanup: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 355 | 0 | my ($self,$method) = @_; | |||||||||||||||||||||||||||
| 356 | 0 | my @methods = grep {$_ ne $method} $self->_cleanup_methods; | |||||||||||||||||||||||||||
| 357 | 0 | $self->{'_root_cleanup_methods'} = \@methods; | |||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | =head2 _cleanup_methods | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | =cut | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 155740 | ▶ | sub _cleanup_methods { | ||||||||||||||||||||||||||
|
Subroutine
_cleanup_methods: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||
| 365 | 155740 | my $self = shift; | |||||||||||||||||||||||||||
| 366 | 155740 | ▶ | return unless ref $self && $self->isa('HASH'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $self and $self->isa("HASH")
MC/DC0%0/2
ref $self and $self->isa("HASH")
ref $self
$self->isa("HASH")
Truth table33%1/3
A and B
A= ref $selfB= $self->isa("HASH")
| |||||||||||||||||||||||||||||
| 367 | 155740 | ▶ | my $methods = $self->{'_root_cleanup_methods'} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 368 | 41292 | @$methods; | |||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | =head2 throw | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | Title : throw | ||||||||||||||||||||||||||||
| 374 | Usage : $obj->throw("throwing exception message"); | ||||||||||||||||||||||||||||
| 375 | or | ||||||||||||||||||||||||||||
| 376 | $obj->throw( -class => 'Bio::Root::Exception', | ||||||||||||||||||||||||||||
| 377 | -text => "throwing exception message", | ||||||||||||||||||||||||||||
| 378 | -value => $bad_value ); | ||||||||||||||||||||||||||||
| 379 | Function: Throws an exception, which, if not caught with an eval or | ||||||||||||||||||||||||||||
| 380 | a try block will provide a nice stack trace to STDERR | ||||||||||||||||||||||||||||
| 381 | with the message. | ||||||||||||||||||||||||||||
| 382 | If Error.pm is installed, and if a -class parameter is | ||||||||||||||||||||||||||||
| 383 | provided, Error::throw will be used, throwing an error | ||||||||||||||||||||||||||||
| 384 | of the type specified by -class. | ||||||||||||||||||||||||||||
| 385 | If Error.pm is installed and no -class parameter is provided | ||||||||||||||||||||||||||||
| 386 | (i.e., a simple string is given), A Bio::Root::Exception | ||||||||||||||||||||||||||||
| 387 | is thrown. | ||||||||||||||||||||||||||||
| 388 | Returns : n/a | ||||||||||||||||||||||||||||
| 389 | Args : A string giving a descriptive error message, optional | ||||||||||||||||||||||||||||
| 390 | Named parameters: | ||||||||||||||||||||||||||||
| 391 | '-class' a string for the name of a class that derives | ||||||||||||||||||||||||||||
| 392 | from Error.pm, such as any of the exceptions | ||||||||||||||||||||||||||||
| 393 | defined in Bio::Root::Exception. | ||||||||||||||||||||||||||||
| 394 | Default class: Bio::Root::Exception | ||||||||||||||||||||||||||||
| 395 | '-text' a string giving a descriptive error message | ||||||||||||||||||||||||||||
| 396 | '-value' the value causing the exception, or $! (optional) | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | Thus, if only a string argument is given, and Error.pm is available, | ||||||||||||||||||||||||||||
| 399 | this is equivalent to the arguments: | ||||||||||||||||||||||||||||
| 400 | -text => "message", | ||||||||||||||||||||||||||||
| 401 | -class => Bio::Root::Exception | ||||||||||||||||||||||||||||
| 402 | Comments : If Error.pm is installed, and you don't want to use it | ||||||||||||||||||||||||||||
| 403 | for some reason, you can block the use of Error.pm by | ||||||||||||||||||||||||||||
| 404 | Bio::Root::Root::throw() by defining a scalar named | ||||||||||||||||||||||||||||
| 405 | $main::DONT_USE_ERROR (define it in your main script | ||||||||||||||||||||||||||||
| 406 | and you don't need the main:: part) and setting it to | ||||||||||||||||||||||||||||
| 407 | a true value; you must do this within a BEGIN subroutine. | ||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | =cut | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 32 | ▶ | sub throw { | ||||||||||||||||||||||||||
|
Subroutine
throw: called CC=13 SCAR=35.7
Pod
documented
| |||||||||||||||||||||||||||||
| 412 | 32 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 32 | my ($text, $class, $value) = $self->_rearrange( [qw(TEXT | |||||||||||||||||||||||||||
| 415 | CLASS | ||||||||||||||||||||||||||||
| 416 | VALUE)], @args); | ||||||||||||||||||||||||||||
| 417 | 32 | ▶ | $text ||= $args[0] if @args == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$text ||= $args[0]
MC/DC0%0/2
$text ||= $args[0]
$text
$args[0]
Truth table33%1/3
A ||= B
A= $textB= $args[0]
| |||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | 32 | ▶ | if ($ERRORLOADED) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 420 | # Enable re-throwing of Error objects. | ||||||||||||||||||||||||||||
| 421 | # If the error is not derived from Bio::Root::Exception, | ||||||||||||||||||||||||||||
| 422 | # we can't guarantee that the Error's value was set properly | ||||||||||||||||||||||||||||
| 423 | # and, ipso facto, that it will be catchable from an eval{}. | ||||||||||||||||||||||||||||
| 424 | # But chances are, if you're re-throwing non-Bio::Root::Exceptions, | ||||||||||||||||||||||||||||
| 425 | # you're probably using Error::try(), not eval{}. | ||||||||||||||||||||||||||||
| 426 | # TODO: Fix the MSG: line of the re-thrown error. Has an extra line | ||||||||||||||||||||||||||||
| 427 | # containing the '----- EXCEPTION -----' banner. | ||||||||||||||||||||||||||||
| 428 | 32 | ▶ | if (ref($args[0])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 429 | 0 | ▶ | if( $args[0]->isa('Error')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 430 | 0 | my $class = ref $args[0]; | |||||||||||||||||||||||||||
| 431 | 0 | $class->throw( @args ); | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | else { | ||||||||||||||||||||||||||||
| 434 | 0 | my $text .= "\nWARNING: Attempt to throw a non-Error.pm object: " . ref$args[0]; | |||||||||||||||||||||||||||
| 435 | 0 | my $class = "Bio::Root::Exception"; | |||||||||||||||||||||||||||
| 436 | 0 | $class->throw( '-text' => $text, '-value' => $args[0] ); | |||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||
| 439 | else { | ||||||||||||||||||||||||||||
| 440 | 32 | ▶ | $class ||= "Bio::Root::Exception"; | ||||||||||||||||||||||||||
|
Condition100%2/2
$class ||= "Bio::Root::Exception"
MC/DC100%1/1
$class ||= "Bio::Root::Exception"
$class
Truth table100%2/2
A
A= $class
| |||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | 32 | my %args; | |||||||||||||||||||||||||||
| 443 | 32 | ▶ | if( @args % 2 == 0 && $args[0] =~ /^-/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@args % 2 == 0 and $args[0] =~ /^-/
MC/DC50%1/2
@args % 2 == 0 and $args[0] =~ /^-/
@args % 2 == 0
$args[0] =~ /^-/
Truth table66%2/3
A and B
A= @args % 2 == 0B= $args[0] =~ /^-/
| |||||||||||||||||||||||||||||
| 444 | 1 | %args = @args; | |||||||||||||||||||||||||||
| 445 | 1 | $args{-text} = $text; | |||||||||||||||||||||||||||
| 446 | 1 | $args{-object} = $self; | |||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | 32 | ▶ | $class->throw( scalar keys %args > 0 ? %args : @args ); # (%args || @args) puts %args in scalar context! | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||
| 452 | else { | ||||||||||||||||||||||||||||
| 453 | 0 | ▶ | $class ||= ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$class ||= ""
MC/DC0%0/1
$class ||= ""
$class
Truth table0%0/2
A
A= $class
| |||||||||||||||||||||||||||||
| 454 | 0 | ▶ | $class = ': '.$class if $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 455 | 0 | my $std = $self->stack_trace_dump(); | |||||||||||||||||||||||||||
| 456 | 0 | my $title = "------------- EXCEPTION$class -------------"; | |||||||||||||||||||||||||||
| 457 | 0 | my $footer = ('-' x CORE::length($title))."\n"; | |||||||||||||||||||||||||||
| 458 | 0 | ▶ | $text ||= ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$text ||= ""
MC/DC0%0/1
$text ||= ""
$text
Truth table0%0/2
A
A= $text
| |||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | 0 | die "\n$title\n", "MSG: $text\n", $std, $footer, "\n"; | |||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | =head2 debug | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | Title : debug | ||||||||||||||||||||||||||||
| 467 | Usage : $obj->debug("This is debugging output"); | ||||||||||||||||||||||||||||
| 468 | Function: Prints a debugging message when verbose is > 0 | ||||||||||||||||||||||||||||
| 469 | Returns : none | ||||||||||||||||||||||||||||
| 470 | Args : message string(s) to print to STDERR | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | =cut | ||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | 63735 | ▶ | sub debug { | ||||||||||||||||||||||||||
|
Subroutine
debug: called CC=6 SCAR=30.2
Pod
documented
| |||||||||||||||||||||||||||||
| 475 | 63735 | my ($self, @msgs) = @_; | |||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | # using CORE::warn doesn't give correct backtrace information; we want the | ||||||||||||||||||||||||||||
| 478 | # line from the previous call in the call stack, not this call (similar to | ||||||||||||||||||||||||||||
| 479 | # cluck). For now, just add a stack trace dump and simple comment under the | ||||||||||||||||||||||||||||
| 480 | # correct conditions. | ||||||||||||||||||||||||||||
| 481 | 63735 | ▶ | if (defined $self->verbose && $self->verbose > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->verbose and $self->verbose > 0
MC/DC0%0/2
defined $self->verbose and $self->verbose > 0
defined $self->verbose
$self->verbose > 0
Truth table66%2/3
A and B
A= defined $self->verboseB= $self->verbose > 0
| |||||||||||||||||||||||||||||
| 482 | 0 | ▶ | if (!@msgs || $msgs[-1] !~ /\n$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@msgs and $msgs[-1] =~ /\n$/
MC/DC0%0/2
@msgs and $msgs[-1] =~ /\n$/
@msgs
$msgs[-1] =~ /\n$/
Truth table0%0/3
A and B
A= @msgsB= $msgs[-1] =~ /\n$/
| |||||||||||||||||||||||||||||
| 483 | 0 | ▶ | push @msgs, "Debugging comment:" if !@msgs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 484 | 0 | push @msgs, sprintf("%s %s:%s", @{($self->stack_trace)[2]}[3,1,2])."\n"; | |||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||
| 486 | 0 | CORE::warn @msgs; | |||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | =head2 _load_module | ||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | Title : _load_module | ||||||||||||||||||||||||||||
| 493 | Usage : $self->_load_module("Bio::SeqIO::genbank"); | ||||||||||||||||||||||||||||
| 494 | Function: Loads up (like use) the specified module at run time on demand. | ||||||||||||||||||||||||||||
| 495 | Example : | ||||||||||||||||||||||||||||
| 496 | Returns : TRUE on success. Throws an exception upon failure. | ||||||||||||||||||||||||||||
| 497 | Args : The module to load (_without_ the trailing .pm). | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | =cut | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | 3744 | ▶ | sub _load_module { | ||||||||||||||||||||||||||
|
Subroutine
_load_module: called CC=4 SCAR=14.4
| |||||||||||||||||||||||||||||
| 502 | 3744 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 503 | 3744 | my ($module, $load, $m); | |||||||||||||||||||||||||||
| 504 | 3744 | $module = "_<$name.pm"; | |||||||||||||||||||||||||||
| 505 | 3744 | ▶ | return 1 if $main::{$module}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | # untaint operation for safe web-based running (modified after | ||||||||||||||||||||||||||||
| 508 | # a fix by Lincoln) HL | ||||||||||||||||||||||||||||
| 509 | 3744 | ▶ | if ($name !~ /^([\w:]+)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 510 | 0 | $self->throw("$name is an illegal perl package name"); | |||||||||||||||||||||||||||
| 511 | } else { | ||||||||||||||||||||||||||||
| 512 | 3744 | $name = $1; | |||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | 3744 | $load = "$name.pm"; | |||||||||||||||||||||||||||
| 516 | 3744 | my $io = Bio::Root::IO->new(); | |||||||||||||||||||||||||||
| 517 | # catfile comes from IO | ||||||||||||||||||||||||||||
| 518 | 3744 | $load = $io->catfile((split(/::/,$load))); | |||||||||||||||||||||||||||
| 519 | 3744 | eval { | |||||||||||||||||||||||||||
| 520 | 3744 | require $load; | |||||||||||||||||||||||||||
| 521 | }; | ||||||||||||||||||||||||||||
| 522 | 3744 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 523 | 0 | $self->throw("Failed to load module $name. ".$@); | |||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||
| 525 | 3744 | return 1; | |||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||
| 528 | =head2 DESTROY | ||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | =cut | ||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | 155740 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 533 | 155740 | my $self = shift; | |||||||||||||||||||||||||||
| 534 | 155740 | ▶ | my @cleanup_methods = $self->_cleanup_methods or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 535 | 41292 | for my $method (@cleanup_methods) { | |||||||||||||||||||||||||||
| 536 | 42900 | $method->($self); | |||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||
| 540 | 582 | 1; | |||||||||||||||||||||||||||