MakeMe...ssName(3pm)

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

πŸ’– NAME πŸ’–

Class::MakeMethods::Template::ClassName (3pm) β€” Access object's class.

Okay so this is the User Contributed Perl Documentation page for Class::MakeMethods::Template::ClassName (3pm). The header shortens it to MakeMe...ssName(3pm), but bestie, we're using the full name. Main character energy only. πŸ’…


✨ SYNOPSIS ✨

The vibe check, in code:

  package MyObject;
  use Class::MakeMethods::Template::ClassName (
    subclass_name => [ 'type' ]
  );
  ...
  package main;
  my $object = MyObject->new;

  $object->type('Foo')
  # reblesses object to MyObject::Foo subclass

  print $object->type();
  # prints "Foo".

🌸 DESCRIPTION 🌸

These method types access or change information about the class an object is associated with. That's the core vibe, and honestly it's giving very useful. πŸ¦‹

πŸ¦‹ class_name πŸ¦‹

Called without arguments, it returns the class name. Periodt.

If you call it with an argument, it reblesses the object into that class. And if the class doesn't already exist, it will be created. No cap.

πŸŽ€ subclass_name πŸŽ€

Called without arguments, it returns the subclass name.

If you call it with an argument, it reblesses the object into that subclass. If the subclass doesn't already exist, it will be created. Iconic behavior, honestly.

The subclass name is written as follows:

  • if it's the original, defining class: empty
  • if it's a package within the namespace of the original: the distinguishing name within that namespace, without leading ::
  • if it's a package elsewhere: the full name with leading ::

πŸ’œ static_hash_classname πŸ’œ

This one provides a shared hash mapping keys to class names. Cute, right?

  class_registry => [ qw/ foo / ]

It takes a single string or a reference to an array of strings as its argument. For each string, it creates a new anonymous hash and associated accessor methods that will map scalar values to classes in the calling package's subclass hierarchy. That's the whole setup, iykyk.

The accessor methods provide an interface to the hash as illustrated below. Important note: several of these functions operate quite differently depending on the number of arguments passed, or the context in which they are called. So yeah, context matters, bestie.

  • @indexes = $class_or_ref->x; β€” Returns the scalar values that are indexes associated with this class, or the class of this object.
  • $class = $class_or_ref->x( $index ); β€” Returns the class name associated with the provided index value.
  • @classes = $class_or_ref->x( @indexes ); β€” Returns the associated classes for each index in order.
  • @all_indexes = $class_or_ref->x_keys; β€” Returns a list of the indexes defined for this registry.
  • @all_classes = $class_or_ref->x_values; β€” Returns a list of the classes associated with this registry.
  • @all_classes = $class_or_ref->unique_x_values; β€” Returns a list of the classes associated with this registry, with no more than one occurrence of any value.
  • %mapping = $class_or_ref->x_hash; β€” Return the key-value pairs used to store this attribute.
  • $mapping_ref = $class_or_ref->x_hash; β€” Returns a reference to the hash used for the mapping.
  • $class_or_ref->add_x( @indexes ); β€” Adds an entry in the hash for each of the provided indexes, mapping it to this class, or the class of this object.
  • $class_or_ref->clear_x; β€” Removes those entries from the hash whose values are this class, or the class of this object.
  • $class_or_ref->clear_xs( @indexes ); β€” Remove all entries from the hash.

🌈 SEE ALSO 🌈

  • See Class::MakeMethods for general information about this distribution.
  • See Class::MakeMethods::Template for information about this family of subclasses.

Okay bestie, that's the whole page. This little gem is from perl v5.36.0, dated 2022-10-13, and the footer has MakeMe...ssName(3pm). Go forth and access those classes, fr fr. πŸ’œβœ¨

πŸ“¦ where this page comes from