MakeMe...ritable(3pm)

πŸ“¦
version 1.01 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

okay so this is the MakeMe...ritable(3pm) page from User Contributed Perl Documentation, and the main character is Class::MakeMethods::Utility::Inheritable β€” literally "Inheritable" data. πŸ’…βœ¨

✨ SYNOPSIS ✨

bestie, here's the whole vibe in code, copy-paste exact:

  package MyClass;
  sub new { ... }

  package MySubclass;
  @ISA = 'MyClass';
  ...
  my $obj = MyClass->new(...);
  my $subobj = MySubclass->new(...);

  use Class::MakeMethods::Utility::Inheritable qw(get_vvalue set_vvalue );

  my $dataset = {};
  set_vvalue($dataset, 'MyClass', 'Foobar');    # Set value for class
  get_vvalue($dataset, 'MyClass');              # Gets value "Foobar"

  get_vvalue($dataset, $obj);                   # Objects "inherit"
  set_vvalue($dataset, $obj, 'Foible');         # Until you override
  get_vvalue($dataset, $obj);                   # Now finds "Foible"

  get_vvalue($dataset, 'MySubclass');           # Subclass "inherits"
  get_vvalue($dataset, $subobj);                # As do its objects
  set_vvalue($dataset, 'MySubclass', 'Foozle'); # Until we override it
  get_vvalue($dataset, 'MySubclass');           # Now finds "Foozle"

  get_vvalue($dataset, $subobj);                # Change cascades down
  set_vvalue($dataset, $subobj, 'Foolish');     # Until we override again

  get_vvalue($dataset, 'MyClass');              # Superclass is unchanged

πŸ’… DESCRIPTION πŸ’…

So here's the tea: this module hands you several functions that let you store values in a hash corresponding to both objects and classes, and then retrieve those values by searching an object's inheritance tree until it finds a matching entry. πŸ¦‹

This functionality is used by Class::MakeMethods::Standard::Inheritable and Class::MakeMethods::Composite::Inheritable to construct methods that can both store class data and be overridden on a per-object level. periodt. πŸ‘‘

πŸ”₯ REFERENCE πŸ”₯

three functions, three little moments β€” let's go:

πŸ¦‹ find_vself πŸ¦‹

$vself = find_vself( $dataset, $instance );

Searches $instance's inheritance tree until it finds a matching entry in the dataset, and returns either the instance, the class that matched, or undef. that's the whole function, no cap. πŸ’€

πŸ“ get_vvalue πŸ“

$value = get_vvalue( $dataset, $instance );

Searches $instance's inheritance tree until it finds a matching entry in the dataset, and returns that value. slay. πŸ’–

πŸŽ€ set_vvalue πŸŽ€

$value = set_vvalue( $dataset, $instance, $value );

Searches $instance's inheritance tree until it finds a matching entry in the dataset, and returns that value.

bestie, yes, the original description for set_vvalue also says "returns that value" β€” I'm not changing a single word of the lore. πŸ™ˆ

okay that's the whole page bestie πŸ’– this was MakeMe...ritable(3pm) from User Contributed Perl Documentation, built for perl v5.36.0, dated 2022-10-13 β€” mwah 🫢✨

πŸ“¦ where this page comes from