Add the original source packages to maemo, source lenny
[dh-make-perl] / dev / i386 / libtest-harness-perl / libtest-harness-perl-3.12 / lib / TAP / Object.pm
1 package TAP::Object;
2
3 use strict;
4 use vars qw($VERSION);
5
6 =head1 NAME
7
8 TAP::Object - Base class that provides common functionality to all C<TAP::*> modules
9
10 =head1 VERSION
11
12 Version 3.12
13
14 =cut
15
16 $VERSION = '3.12';
17
18 =head1 SYNOPSIS
19
20     package TAP::Whatever;
21
22     use strict;
23     use vars qw(@ISA);
24
25     use TAP::Object;
26
27     @ISA = qw(TAP::Object);
28
29     # new() implementation by TAP::Object
30     sub _initialize {
31         my ( $self, @args) = @_;
32         # initialize your object
33         return $self;
34     }
35
36     # ... later ...
37     my $obj = TAP::Whatever->new(@args);
38
39 =head1 DESCRIPTION
40
41 C<TAP::Object> provides a default constructor and exception model for all
42 C<TAP::*> classes.  Exceptions are raised using L<Carp>.
43
44 =head1 METHODS
45
46 =head2 Class Methods
47
48 =head3 C<new>
49
50 Create a new object.  Any arguments passed to C<new> will be passed on to the
51 L</_initialize> method.  Returns a new object.
52
53 =cut
54
55 sub new {
56     my $class = shift;
57     my $self = bless {}, $class;
58     return $self->_initialize(@_);
59 }
60
61 =head2 Instance Methods
62
63 =head3 C<_initialize>
64
65 Initializes a new object.  This method is a stub by default, you should override
66 it as appropriate.
67
68 I<Note:> L</new> expects you to return C<$self> or raise an exception.  See
69 L</_croak>, and L<Carp>.
70
71 =cut
72
73 sub _initialize {
74     return $_[0];
75 }
76
77 =head3 C<_croak>
78
79 Raise an exception using C<croak> from L<Carp>, eg:
80
81     $self->_croak( 'why me?', 'aaarrgh!' );
82
83 May also be called as a I<class> method.
84
85     $class->_croak( 'this works too' );
86
87 =cut
88
89 sub _croak {
90     my $proto = shift;
91     require Carp;
92     Carp::croak(@_);
93     return;
94 }
95
96 1;
97