Package::New(3pm)

Package::New3pm

Simple base package from which to inherit

Usage

  package My::Package;
  use base qw{Package::New}; #provides new and initialize

Overview

The Package::New object provides a consistent constructor for objects.

I find that I always need these two methods in every package that I build. I plan to use this package as the base for all of my CPAN packages.

Recommendations

Sane defaults

I recommend that you have sane default for all of your object properties. I recommend using code like this.

  sub myproperty {
    my $self=shift;
    $self->{"myproperty"}=shift if @_;
    $self->{"myproperty"}="Default Value" unless defined $self->{"myproperty"};
    return $self->{"myproperty"};
  }

use strict and warnings

I recommend to always use strict, warnings and our version.

  package My::Package;
  use base qw{Package::New};
  use strict;
  use warnings;
  our $VERSION='0.01';

Lazy Load where you can

I recommend Lazy Loading where you can.

  sub mymethod {
    my $self=shift;
    $self->load unless $self->loaded;
    return $self->{"mymethod"};
  }

Usage

Constructor

new

  my $obj = Package::New->new(key=>$value, ...);

initialize

You can override this method in your package if you need to do something after construction. But, lazy loading may be a better option.

Support

DavisNetworks.com provides support services for all Perl applications including this package.

Releases

7 releases since Debian 7 (Wheezy); the text changed 4 times.

  1. 7–9
  2. 10
  3. 11
  4. 12
  5. 13

Bugs

Log on RT and contact the author.

Author

  Michael R. Davis
  CPAN ID: MRDVT
  DavisNetworks.com
  http://www.DavisNetworks.com/

From libpackage-new-perl 0.10-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.