8 TAP::Object - Base class that provides common functionality to all C<TAP::*> modules
20 package TAP::Whatever;
27 @ISA = qw(TAP::Object);
29 # new() implementation by TAP::Object
31 my ( $self, @args) = @_;
32 # initialize your object
37 my $obj = TAP::Whatever->new(@args);
41 C<TAP::Object> provides a default constructor and exception model for all
42 C<TAP::*> classes. Exceptions are raised using L<Carp>.
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.
57 my $self = bless {}, $class;
58 return $self->_initialize(@_);
61 =head2 Instance Methods
65 Initializes a new object. This method is a stub by default, you should override
68 I<Note:> L</new> expects you to return C<$self> or raise an exception. See
69 L</_croak>, and L<Carp>.
79 Raise an exception using C<croak> from L<Carp>, eg:
81 $self->_croak( 'why me?', 'aaarrgh!' );
83 May also be called as a I<class> method.
85 $class->_croak( 'this works too' );
98 Create a new instance of the specified class.
103 my ( $self, $class, @args ) = @_;
105 $self->_croak("Bad module name $class")
106 unless $class =~ /^ \w+ (?: :: \w+ ) *$/x;
108 unless ( $class->can('new') ) {
110 eval "require $class";
111 $self->_croak("Can't load $class") if $@;
114 return $class->new(@args);
119 Create simple getter/setters.
121 __PACKAGE__->mk_methods(@method_names);
126 my ( $class, @methods ) = @_;
127 foreach my $method_name (@methods) {
128 my $method = "${class}::$method_name";
132 $self->{$method_name} = shift if @_;
133 return $self->{$method_name};