t/AlignIO/AlignIO.t: fix number of tests in plan (fixup c523e6bed866)
[bioperl-live.git] / Bio / Root / TestObject.pm
blob35b92c9ea1a9f87804a4e2873b05ef4d3eb2b776
1 =head1 NAME
3 TestObject - An implementation of TestInterface
5 =head1 DESCRIPTION
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.
11 =head1 AUTHOR
13 Steve Chervitz E<lt>sac@bioperl.orgE<gt>
15 =cut
17 package Bio::Root::TestObject;
19 use strict;
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 @Bio::TestException::ISA = qw( Bio::Root::Exception );
29 use base qw( Bio::Root::Root );
31 # Note that we're not implementing foo(), so calling it
32 # will result in a Bio::Root::NotImplemented exception.
34 sub data {
35 my ($self, $data) = @_;
36 print "Setting test data ($data)\n" if $data && $self->verbose;
37 $self->{'data'} = $data if $data;
39 return $self->{'data'}
42 sub bar {
44 my $self = shift;
46 print "\nExecuting method bar() in TestObject\n" if $self->verbose;
47 print "Throwing a Bio::TestException\n" if $self->verbose;
49 my $message = "A Test error";
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.
56 $self->throw( -class => 'Bio::TestException',
57 -text => $message );
59 print "Code within bar() below the throw that shouldn't be executed.\n" if $self->verbose;