| 1 | =head1 NAME | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | TestObject - An implementation of TestInterface | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | This module attempts to provide an implementation of TestInterface and | ||||||||||||||||||||||||||||
| 8 | is used for illustrating exception throwing using Graham Barr's | ||||||||||||||||||||||||||||
| 9 | Error.pm object. | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | Steve Chervitz E<lt>sac@bioperl.orgE<gt> | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =cut | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | package Bio::Root::TestObject; | ||||||||||||||||||||||||||||
| 18 | 2 | $Bio::Root::TestObject::VERSION = '1.7.8'; | |||||||||||||||||||||||||||
| 19 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # Define a special type of error "Bio::TestException" as a subclass of Error. | ||||||||||||||||||||||||||||
| 22 | # Note two things: | ||||||||||||||||||||||||||||
| 23 | # 1. The ISA declaration effectively defines our new Exception object. | ||||||||||||||||||||||||||||
| 24 | # 2. This declaration doesn't have to be located in the Bio directory. | ||||||||||||||||||||||||||||
| 25 | # 3. We don't have to use Bio::Root::Exception in this module. | ||||||||||||||||||||||||||||
| 26 | # 4. If Error.pm isn't available this statement doesn't matter. | ||||||||||||||||||||||||||||
| 27 | 2 | @Bio::TestException::ISA = qw( Bio::Root::Exception ); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use base qw( Bio::Root::Root ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Note that we're not implementing foo(), so calling it | ||||||||||||||||||||||||||||
| 32 | # will result in a Bio::Root::NotImplemented exception. | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | ▶ | sub data { | ||||||||||||||||||||||||||
|
Subroutine
data: called CC=4 SCAR=15.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 1 | my ($self, $data) = @_; | |||||||||||||||||||||||||||
| 36 | 1 | ▶ | print "Setting test data ($data)\n" if $data && $self->verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$data and $self->verbose
MC/DC0%0/2
$data and $self->verbose
$data
$self->verbose
Truth table33%1/3
A and B
A= $dataB= $self->verbose
| |||||||||||||||||||||||||||||
| 37 | 1 | ▶ | $self->{'data'} = $data if $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | return $self->{'data'} | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | ▶ | sub bar { | ||||||||||||||||||||||||||
|
Subroutine
bar: called CC=4 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 1 | ▶ | print "\nExecuting method bar() in TestObject\n" if $self->verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 1 | ▶ | print "Throwing a Bio::TestException\n" if $self->verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | my $message = "A Test error"; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # Bio::Root::Root::throw() will make use of Error.pm if present. | ||||||||||||||||||||||||||||
| 52 | # The type of Error is specified with a -class parameter. | ||||||||||||||||||||||||||||
| 53 | # If -class is not supplied, a Bio::Root::Exception is throw. | ||||||||||||||||||||||||||||
| 54 | # In this case, the argument can consist of a simple string. | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 1 | $self->throw( -class => 'Bio::TestException', | |||||||||||||||||||||||||||
| 57 | -text => $message ); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | print "Code within bar() below the throw that shouldn't be executed.\n" if $self->verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | 1; | |||||||||||||||||||||||||||