.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Package::New 3pm" .TH Package::New 3pm "2022-10-14" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Package::New \- Simple base package from which to inherit .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& package My::Package; \& use base qw{Package::New}; #provides new and initialize .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The Package::New object provides a consistent constructor for objects. .PP 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 \s-1CPAN\s0 packages. .SH "RECOMMENDATIONS" .IX Header "RECOMMENDATIONS" .SS "Sane defaults" .IX Subsection "Sane defaults" I recommend that you have sane default for all of your object properties. I recommend using code like this. .PP .Vb 6 \& sub myproperty { \& my $self=shift; \& $self\->{"myproperty"}=shift if @_; \& $self\->{"myproperty"}="Default Value" unless defined $self\->{"myproperty"}; \& return $self\->{"myproperty"}; \& } .Ve .SS "use strict and warnings" .IX Subsection "use strict and warnings" I recommend to always use strict, warnings and our version. .PP .Vb 5 \& package My::Package; \& use base qw{Package::New}; \& use strict; \& use warnings; \& our $VERSION=\*(Aq0.01\*(Aq; .Ve .SS "Lazy Load where you can" .IX Subsection "Lazy Load where you can" I recommend Lazy Loading where you can. .PP .Vb 5 \& sub mymethod { \& my $self=shift; \& $self\->load unless $self\->loaded; \& return $self\->{"mymethod"}; \& } .Ve .SH "USAGE" .IX Header "USAGE" .SH "CONSTRUCTOR" .IX Header "CONSTRUCTOR" .SS "new" .IX Subsection "new" .Vb 1 \& my $obj = Package::New\->new(key=>$value, ...); .Ve .SS "initialize" .IX Subsection "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. .SH "BUGS" .IX Header "BUGS" Log on \s-1RT\s0 and contact the author. .SH "SUPPORT" .IX Header "SUPPORT" DavisNetworks.com provides support services for all Perl applications including this package. .SH "AUTHOR" .IX Header "AUTHOR" .Vb 4 \& Michael R. Davis \& CPAN ID: MRDVT \& DavisNetworks.com \& http://www.DavisNetworks.com/ .Ve .SH "COPYRIGHT" .IX Header "COPYRIGHT" This program is free software licensed under the... .PP .Vb 1 \& The BSD License .Ve .PP The full text of the license can be found in the \s-1LICENSE\s0 file included with this module. .SH "SEE ALSO" .IX Header "SEE ALSO" .SS "Building Blocks" .IX Subsection "Building Blocks" base, parent .SS "Other Light Weight Base Objects Similar to Package::New" .IX Subsection "Other Light Weight Base Objects Similar to Package::New" Package::Base, Class::Base, Class::Easy, Object::Tiny, Badger::Base .SS "Heavy Base Objects \- Drink the Kool-Aid" .IX Subsection "Heavy Base Objects - Drink the Kool-Aid" \&\s-1VSO\s0, Class::Accessor::Fast, Class::Accessor, Moose, (as well as Moose-alikes Moo, Mouse), Class::MethodMaker, Class::Meta .SS "Even more" .IX Subsection "Even more" Spiffy, mixin, \s-1SUPER\s0, Class::Trait, Class::C3, Moose::Role