Package::New(3pm)
π Package::New π
okay so bestie, welcome to Package::New β it's a Perl manual page (3pm, so you KNOW it's a library situation) and honestly? it's giving simple base package from which to inherit. that's the whole NAME, that's the whole vibe. it's a lil guy you inherit from. slay. π
β¨ SYNOPSIS β¨
package My::Package;
use base qw{Package::New}; #provides new and initialize
like. that's it. two lines and you have a constructor. no cap, #provides new and initialize is literally in the comment and it's literally true. π
πΈ DESCRIPTION πΈ
so Package::New gives you a consistent constructor for objects. that's the job. that's the whole job.
and the author is so real for this: "I find that I always need these two methods in every package that I build." every single one. every time. and they plan to use this package as the base for all of their CPAN packages. main character energy honestly. π
π¦ RECOMMENDATIONS π¦
π Sane defaults
please please PLEASE have a sane default for all your object properties. it's the respectful thing to do. the author recommends code like this:
sub myproperty {
my $self=shift;
$self->{"myproperty"}=shift if @_;
$self->{"myproperty"}="Default Value" unless defined $self->{"myproperty"};
return $self->{"myproperty"};
}
look at it. the setter, the default, the getter, all in one lil bundle. iconic. β¨
π use strict and warnings
always use strict, warnings and our version. always. no exceptions. this is not a drill. π¨
package My::Package;
use base qw{Package::New};
use strict;
use warnings;
our $VERSION='0.01';
π Lazy Load where you can
Lazy Loading? when you can? do it. the author recommends it:
sub mymethod {
my $self=shift;
$self->load unless $self->loaded;
return $self->{"mymethod"};
}
don't do the work until somebody actually asks for it. that's the whole philosophy. that's self-care. π§
π USAGE π
(this section is just vibes and a heading, bestie, there's no prose here β it flows straight into CONSTRUCTOR π«Ά)
π CONSTRUCTOR π
π new
my $obj = Package::New->new(key=>$value, ...);
that's the constructor! it takes a list of key=>$value pairs and hands you back an object. mwah. π
π initialize
you can override this method in your package if you need to do something after construction. but honestly? lazy loading may be a better option. the author is just saying. π€·
π BUGS π
log on RT and contact the author. that's it. that's the whole bug policy. not me reading that and respecting the efficiency fr fr.
π«Ά SUPPORT π«Ά
DavisNetworks.com provides support services for all Perl applications including this package. so if you're stuck, you know where to go. π
β AUTHOR β
Michael R. Davis
CPAN ID: MRDVT
DavisNetworks.com
http://www.DavisNetworks.com/
give it up for Michael. CPAN ID MRDVT. legend behavior. π
π 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. go read it, bestie, it's right there. π
π₯ SEE ALSO π₯
π Building Blocks
base, parent
π Other Light Weight Base Objects Similar to Package::New
Package::Base, Class::Base, Class::Easy, Object::Tiny, Badger::Base
π Heavy Base Objects - Drink the Kool-Aid
VSO, Class::Accessor::Fast, Class::Accessor, Moose, (as well as Moose-alikes Moo, Mouse), Class::MethodMaker, Class::Meta
π Even more
Spiffy, mixin, SUPER, Class::Trait, Class::C3, Moose::Role
ok that's the whole page bestie, you ate that π now go inherit responsibly π¦
and just so we're keeping the receipts: this was perl v5.40.0, dated 2025-01-12, and yes, it's Package::New(3pm). periodt. β¨π
πΈ
π¦ where this page comes from
- debian trixie: libpackage-new-perl 0.10-1 Β· BSD-3-Clause~STOP
- ubuntu resolute: libpackage-new-perl 0.10-1 Β· BSD-3-Clause~STOP
- ubuntu stonking: libpackage-new-perl 0.10-1 Β· BSD-3-Clause~STOP
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms