Package::New - Simple base package from which to inherit
Contents
Bugs
Log on RT and contact the author.
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.
Copyright
This program is free software licensed under the...
The BSD License
The full text of the license can be found in the LICENSE file included with this module.
Description
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.
Name
Package::New - Simple base package from which to inherit
Recommendations
Sanedefaults
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"};
}
usestrictandwarnings
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';
LazyLoadwhereyoucan
I recommend Lazy Loading where you can.
sub mymethod {
my $self=shift;
$self->load unless $self->loaded;
return $self->{"mymethod"};
}
See Also
BuildingBlocks
base, parent
OtherLightWeightBaseObjectsSimilartoPackage::New
Package::Base, Class::Base, Class::Easy, Object::Tiny, Badger::Base
HeavyBaseObjects-DrinktheKool-Aid
VSO, Class::Accessor::Fast, Class::Accessor, Moose, (as well as Moose-alikes Moo, Mouse),
Class::MethodMaker, Class::Meta
Evenmore
Spiffy, mixin, SUPER, Class::Trait, Class::C3, Moose::Role
perl v5.40.0 2025-01-12 Package::New(3pm)
Support
DavisNetworks.com provides support services for all Perl applications including this package.
Synopsis
package My::Package;
use base qw{Package::New}; #provides new and initialize
