RoPkg::Object(3pm)

πŸ“¦ version 0.4, in ubuntu jammy

πŸ¦‹ 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 _inject
  • q{} β€” 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::More
  • Test::Pod
  • Test::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>


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