~ubuntu-branches/ubuntu/hoary/bioperl/hoary

« back to all changes in this revision

Viewing changes to examples/root/lib/TestObject.pm

  • Committer: Bazaar Package Importer
  • Author(s): Matt Hope
  • Date: 2004-04-18 14:24:11 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040418142411-gr92uexquw4w8liq
Tags: 1.4-1
* New upstream release
* Examples and working code are installed by default to usr/bin,
  this has been moved to usr/share/doc/bioperl/bin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#'
 
18
 
 
19
package TestObject;
 
20
 
 
21
use strict;
 
22
use vars qw(@ISA);
 
23
 
 
24
use TestInterface;
 
25
use Bio::Root::Root;
 
26
 
 
27
# Define a special type of error "Bio::TestException" as a subclass of Error.
 
28
# Note two things:
 
29
#   1. The ISA declaration effectively defines our new Exception object.
 
30
#   2. This declaration doesn't have to be located in the Bio directory.
 
31
#   3. We don't have to use Bio::Root::Exception in this module.
 
32
#   4. If Error.pm isn't available this statement doesn't matter.
 
33
@Bio::TestException::ISA = qw( Bio::Root::Exception );
 
34
 
 
35
@ISA = qw( Bio::Root::Root TestInterface );
 
36
 
 
37
 
 
38
# Note that we're not implementing foo(), so calling it
 
39
# will result in a Bio::Root::NotImplemented exception.
 
40
 
 
41
sub data {
 
42
    my ($self, $data) = @_;
 
43
    print "Setting test data ($data)\n" if $data;
 
44
    $self->{'data'} = $data if $data;
 
45
 
 
46
   return $self->{'data'} 
 
47
}
 
48
 
 
49
sub bar {
 
50
 
 
51
    my $self = shift;
 
52
 
 
53
    print "\nExecuting method bar() in TestObject\n";
 
54
    print "Throwing a Bio::TestException\n";
 
55
 
 
56
    my $message = "A Test error";
 
57
 
 
58
    # Bio::Root::Root::throw() will make use of Error.pm if present.
 
59
    # The type of Error is specified with a -class parameter. 
 
60
    # If -class is not supplied, a Bio::Root::Exception is throw.
 
61
    # In this case, the argument can consist of a simple string.
 
62
 
 
63
    $self->throw( -class => 'Bio::TestException',
 
64
                  -text  => $message );
 
65
 
 
66
    print "Code within bar() below the throw that shouldn't be executed.\n";
 
67
 
 
68
}
 
69
 
 
70
1;