ObjectTemplate(3pm)
π ObjectTemplate β the whole vibe π
okay bestie, so this is Class::ObjectTemplate(3pm), a User Contributed Perl Documentation page, and honestly? it's giving builder base class energy and i'm obsessed. pull up a chair, grab a boba, we're doing this π§β¨
πΈ NAME πΈ
Class::ObjectTemplate β a Perl extension that's basically an optimized template builder base class. yeah. she builds the classes that build the things. main character behavior fr fr π
β¨ SYNOPSIS β¨
here's the whole flex, copied exactly, no cap:
package Foo;
use Class::ObjectTemplate;
require Exporter;
@ISA = qw(Class::ObjectTemplate Exporter);
attributes('one', 'two', 'three');
# initialize will be called by new()
sub initialize {
my $self = shift;
$self->three(1) unless defined $self->three();
}
use Foo;
$foo = Foo->new();
# store 27 in the 'one' attribute
$foo->one(27);
# check the value in the 'two' attribute
die "should be undefined" if defined $foo->two();
# set using the utility method
$foo->set_attribute('one',27);
# check using the utility method
$two = $foo->get_attribute('two');
# set more than one attribute using the named parameter style
$foo->set_attributes('one'=>27, 'two'=>42);
# or using array references
$foo->set_attributes(['one','two'],[27,42]);
# get more than one attribute
@list = $foo->get_attributes('one', 'two');
# get a list of all attributes known by an object
@attrs = $foo->get_attribute_names();
# check that initialize() is called properly
die "initialize didn't set three()" unless $foo->three();
likeβ¦ the way initialize gets called by new() automatically? we love a self-starting queen π«Ά
π¦ DESCRIPTION π¦
Class::ObjectTemplate is a utility class that helps you build other Object Oriented Perl classes. it's the little helper that makes the whole OO thing go smoother, and honestly? it eats π
it got a full write-up in the O'Reilly book "Advanced Perl Programming" by Sriram Srinivasam, which is the og source material, iykyk πβ¨
π EXPORT π
attributes(@name_list)
this method makes a shared setter and getter for every single name in the list. two-for-one deal, iconic. and it also creates the class constructor, new(). so like, one call and you got the whole setup π
β οΈ WARNING, bestie, read this one twice: this method must be invoked within the module for every class that inherits fromClass::ObjectTemplateβ even if that class defines no attributes. no attributes? no problem, but you still gotta call it. for a class defining no new attributes, invokeattributes()with no arguments. don't skip it, don't forget it, don't "oops i'll do it later" it. periodt π¨
π AUTHOR π
- original code by Sriram Srinivasam.
- fixes and CPAN module by Jason E. Stewart (
jason@openinformatics.com) π«Ά
π SEE ALSO π
http://www.oreilly.com/catalog/advperl/perl(1).Class::ObjectTemplate::DB
and that's the whole page, bestie, you absolutely ate this one π β¨
cute lil sign-off: this page is from perl v5.34.0, dated 2022-06-11, and it lives in ObjectTemplate(3pm) πππ¦ bye bye, go write some classes πΈ
π¦ where this page comes from
- debian bookworm: libclass-objecttemplate-perl 0.7-9 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libclass-objecttemplate-perl 0.7-9 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libclass-objecttemplate-perl 0.7-9 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libclass-objecttemplate-perl 0.7-9 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libclass-objecttemplate-perl 0.7-9 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms