ObjectTemplate(3pm)

πŸ“¦
version 0.7 Β· 2 versions
  • 0.7 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.7 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 from Class::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, invoke attributes() 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 🌈


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