NAME

Package::Base - An abstract base for implementation classes to inherit from

SYNOPSIS

      #don't use this module directly, but rather inherit from it.
      package My::Package;
      use base qw(Package::Base);

      #define a couple of get/setters
      sub slot1 {
        my($self,$val) = @_;
        $self->{'slot1'} = $val if defined($val);
        return $self->{'slot1'};
      }

      sub slot2 {
        my($self,$val) = @_;
        $self->{'slot2'} = $val if defined($val);
        return $self->{'slot2'};
      }

      package main:
      my $object = My::Package->new(slot1 => 'value1', slot2 => 'value2', slot3 => 'value3');
      #slot3 => 'value3' is silently ignored

      $self->slot1; #returns 'value1'
      $self->slot2; #returns 'value2'

DESCRIPTION

Package::Base is an abstract base class, meaning it isn't intended to be used directly, but rather inherited from by an instantiable class. In fact, attempting to instantiate a Package::Base object directly will result in an error.

Q: So why would you want to inherit from Package::Base?

  1. Because it provides some nice functionality:

and have nice Log::Log4perl logging about what your method is doing sent to a file, filehandle, email, database... whatever (see Log::Log4perl for details about this amazing logging API). Then, when you're ready to ship, just change the line:

      package My::Package;
      -use base qw(Package::Base::Devel);
      +use base qw(Package::Base);

and the heavy debugging toll paid for the debug logging vanishes.

Now to be "fair and balanced" :)

Q: Why might Package::Base not be right for me?

  1. It does some things you might not like for stylistic reasons:

AUTHOR

Allen Day, <allenday@ucla.edu>

SEE ALSO

For another way to do it, see Class::Base, Class::Accessor.