RoPkg::Object(3pm)
π¦ RoPkg::Object β the manual, but make it cute π¦
okay bestie so this is RoPkg::Object, a User Contributed Perl Documentation page, manual section 3pm. buckle up, it's actually lowkey iconic β¨
π NAME π
RoPkg::Object β literally just that, that's the name, that's the whole vibe π
πΈ VERSION πΈ
0.3.2
β¨ DESCRIPTION β¨
So RoPkg::Object is a general purpose module (yes the original says "pourpose", we don't gatekeep typos here, but you get it π«Ά) and it's made for Get/Set objects β you know, the ones where you do NOT want to spend your entire afternoon writing annoying Get/Set methods by hand. that's giving unpaid labor fr fr π
The main character use of this module is to be a base class. that's its whole job, and it eats. π
π SYNOPSIS π
here's how you do it, no cap:
package RoPkg::Person;
use strict;
use warnings;
use RoPkg::Object;
use base qw(RoPkg::Object);
$pf = {
FirstName => 'A person first name',
LastName => 'A person last name'
};
sub new {
my ($class, %opt) = @_;
my $self;
$self = $class->SUPER::new(%opt);
$self->{methods} = $pf;
$self->_inject();
return $self;
}
1;
tester.pl
#!/usr/bin/perl
use strict;
use warnings;
use English qw(-no_match_vars);
use RoPkg::Person;
sub main {
my $p = new RoPkg::Person();
$p->FirstName('John');
$p->LastName('Doe');
print $p->FirstName,' ',$p->LastName,$RS;
}
main();
likeβ¦ look at that. no getters written by hand. we love to see it π
π§ SUBROUTINES/METHODS π§
okay important tea first β: every single method (besides new()) raises an OutsiteClass exception if you call it outside a class instance. so don't do that, bestie.
Also, each method may raise other exceptions too. so if you want the extra info, go read that specific method's documentation. iykyk π
π new()
The class constructor. At this moment the constructor does nothing (besides bless). it's giving "shows up, does the bare minimum, blesses the object, leaves" π
π key($value)
Searches into the methods list for an entry whose value is $value. Returns the method name β or 0 if such a method was not found. π
π methods()
In list context, this method returns a list of method names. In scalar context it returns just the number of methods.
heads up bestie: only the valid methods are counted here β they get tested with can($method_name). so no fake ones sneaking in π
π chkp(@plist)
Checks the current object to see if the parameters specified in the list are defined. If a parameter is not defined, a Param::Missing exception gets raised. dramatic? yes. useful? also yes. π€
π SUBCLASSING π
As said before (and we're saying it again, because it matters π«Ά), this module is specially used as a base class for those objects with many SET/GET methods.
So how do you actually use this class in your project? As seen in the SYNOPSIS: when you create the new class, in the class constructor you call the $self->_inject method, who creates the new methods at runtime. β¨
The list of methods who are gonna be created is actually a hash reference. A method can be specified like this:
FirstName => q{-}
This means that _inject will create a get/set method named FirstName.
There are some key values with special meaning:
__exclude__β the method with this value will not be created by_injectq{}β the method with this value will not be created by_inject
If an existing method is available in the class and is also included in the list of methods who will be created by _inject, that method will be ignored by _inject. like, it already exists, we're not doing that twice, we're not messy π
Each method created by _inject() has the following code:
sub {
my ($self, $pval) = @_;
if ( !blessed($self) ) {
OutsideClass->throw('Called outside class instance');
}
if ( defined $pval) {
$self->{$method_name} = $pval;
}
return $self->{$method_name};
};
that's the whole blueprint, bestie. copy it, respect it, love it. π
π¦ DEPENDENCIES π¦
RoPkg::Object requires perl 5.008 or later and the Scalar::Util module.
To run the tests you also need:
Test::MoreTest::PodTest::Pod::Coverage
yes, three whole testing modules. we're thorough here, it's the vibe πΈ
β DIAGNOSTICS β
This module is subject of tests. To run those tests, unpack the source and use the following command:
make test
go on, run it, watch it pass, feel powerful π₯
π CONFIGURATION AND ENVIRONMENT π
This module does not use any configuration file or environment variables. nothing to set up, nothing to export, no surprises. zero drama, we love a low-maintenance icon π
π INCOMPATIBILITIES π
None known to the author. as far as anyone knows, it plays nice with everyone π«Ά
π BUGS AND LIMITATIONS π
No known bugs. If you find one, please send a detailed report to the author β detailed, bestie, we need the receipts π
Please note: the methods are not automatically created. One must manually call (inside the child object) the method who "injects" the new methods. that's the whole catch, don't forget it π
π PERL CRITIC π
This module is perl critic level 1 compliant with 2 exceptions. almost perfect, and honestly? the two exceptions are just part of the charm π
π AUTHOR π
Subredu Manuel <diablo@iasi.roedu.net>
π LICENSE AND COPYRIGHT π
Copyright (C) 2005 Subredu Manuel. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The LICENSE file contains the full text of the license. π
okay that's the whole page, bestie!! go forth and inject some methods, you're gonna slay π β¨
sign-off tea: this page ships with perl v5.32.1, dated 2021-12-26. that's the version and the date, and that's a wrap. mwah π«Άπ
π¦ where this page comes from
- ubuntu jammy: libropkg-perl 0.4-1.4
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms