Moose::Meta::Class(3)

πŸ’– Moose::Meta::Class πŸ’–

okay bestie, you found the metaclass. this is Moose::Meta::Class, straight out of the User Contributed Perl Documentation section, and honestly? it's giving main character energy for the whole Moose universe. ✨

version 2.4000 β€” yes queen, we're on the modern stuff πŸŽ€


🌸 NAME 🌸

Moose::Meta::Class β€” the Moose metaclass. no cap, that's literally it. πŸ’…


✨ VERSION ✨

version 2.4000 πŸ¦‹


🫢 DESCRIPTION 🫢

So. This class is a subclass of Class::MOP::Class that provides additional Moose-specific functionality. that's the whole vibe. πŸ’œ

But lowkey, to really get this class you have to start with the Class::MOP::Class documentation first. Think of Moose::Meta::Class as a set of extra features stacked on top of the basic feature set that its parent class gives you. like, parent gives you the base fit, this class adds the accessories. πŸ”₯


πŸ‘‘ INHERITANCE πŸ‘‘

Moose::Meta::Class is a subclass of Class::MOP::Class. periodt.


πŸ’… METHODS πŸ’…

⭐ Moose::Meta::Class->initialize($package_name, %options)

This overrides the parent's method in order to provide its own defaults for the attribute_metaclass, instance_metaclass, and method_metaclass options.

These all default to the appropriate Moose class. so you don't gotta lift a finger, bestie. πŸ™ˆ

🌈 Moose::Meta::Class->create($package_name, %options)

This overrides the parent's method in order to accept a roles option. That option should be an array reference containing roles that the class does, each optionally followed by a hashref of options (-excludes and -alias).

my $metaclass = Moose::Meta::Class->create( 'New::Class', roles => [...] );

πŸ¦‹ Moose::Meta::Class->create_anon_class

This overrides the parent's method to accept a roles option, just as create does.

It also accepts a cache option. If this is true, then the anonymous class will be cached based on its superclasses and roles. If an existing anonymous class in the cache has the same superclasses and roles, it will be reused. recycle, reuse, it's iconic. ♻️

my $metaclass = Moose::Meta::Class->create_anon_class(
    superclasses => ['Foo'],
    roles        => [qw/Some Roles Go Here/],
    cache        => 1,
);

Each entry in both the superclasses and the roles option can be followed by a hash reference with arguments. The superclasses option can be supplied with a -version option that ensures the loaded superclass satisfies the required version. The role option also takes the -version as an argument, but the option hash reference can also contain any other role relevant values like exclusions or parameterized role arguments. very "bring your own options" of it. πŸ’–

πŸŽ€ $metaclass->new_object(%params)

This overrides the parent's method in order to add support for attribute triggers.

πŸ’œ $metaclass->superclasses(@superclasses)

This is the accessor allowing you to read or change the parents of the class. glow-up for your inheritance tree, fr fr.

Each superclass can be followed by a hash reference containing a -version value. If the version requirement is not satisfied an error will be thrown. 😭

When you pass classes to this method, we will attempt to load them if they are not already loaded.

🌸 $metaclass->add_override_method_modifier($name, $sub)

This adds an override method modifier to the package.

⭐ $metaclass->add_augment_method_modifier($name, $sub)

This adds an augment method modifier to the package.

✨ $metaclass->calculate_all_roles

This will return a unique list of Moose::Meta::Role instances which are attached to this class. no duplicates allowed, we don't do repeats here. πŸ’…

🫢 $metaclass->calculate_all_roles_with_inheritance

This will return a unique list of Moose::Meta::Role instances which are attached to this class, and each of this class's ancestors. whole family tree said present. 🌈

πŸ¦‹ $metaclass->add_role($role)

This takes a Moose::Meta::Role object, and adds it to the class's list of roles. This does not actually apply the role to the class.

lowkey important: it's just adding to the list. it is not applying anything. don't get it twisted bestie. πŸ’€

πŸŽ€ $metaclass->role_applications

Returns a list of Moose::Meta::Role::Application::ToClass objects, which contain the arguments to role application.

πŸ’œ $metaclass->add_role_application($application)

This takes a Moose::Meta::Role::Application::ToClass object, and adds it to the class's list of role applications. This does not actually apply any role to the class; it is only for tracking role applications.

again β€” tracking only. not applying. πŸ™ˆ

🌸 $metaclass->does_role($role)

This returns a boolean indicating whether or not the class does the specified role. The role provided can be either a role name or a Moose::Meta::Role object. This tests both the class and its parents.

⭐ $metaclass->excludes_role($role_name)

A class excludes a role if it has already composed a role which excludes the named role. This tests both the class and its parents.

✨ $metaclass->add_attribute($attr_name, %params|$params)

This overrides the parent's method in order to allow the parameters to be provided as a hash reference.

🫢 $metaclass->constructor_class($class_name)

🫢 $metaclass->destructor_class($class_name)

These are the names of classes used when making a class immutable. These default to Moose::Meta::Method::Constructor and Moose::Meta::Method::Destructor respectively. These accessors are read-write, so you can use them to change the class name. customize away, bestie. πŸŽ€


πŸ’€ BUGS πŸ’€

See "BUGS" in Moose for details on reporting bugs.


πŸ‘‘ AUTHORS πŸ‘‘

  • Stevan Little <stevan@cpan.org>
  • Dave Rolsky <autarch@urth.org>
  • Jesse Luehrs <doy@cpan.org>
  • Shawn M Moore <sartak@cpan.org>
  • Χ™Χ•Χ‘Χœ Χ§Χ•Χ’'מן (Yuval Kogman) <nothingmuch@woobling.org>
  • Karen Etheridge <ether@cpan.org>
  • Florian Ragwitz <rafl@debian.org>
  • Hans Dieter Pearcey <hdp@cpan.org>
  • Chris Prather <chris@prather.org>
  • Matt S Trout <mstrout@cpan.org>

look at that roster. absolute legends, every single one. 🫢✨


This software is copyright (c) 2006 by Infinity Interactive, Inc.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


and that's the whole page, bestie!! πŸŽ€ this one shipped as Moose::Meta::Class(3), page generated on 2025-07-25, and it's hanging out with perl v5.42.0. go forth and metaprogram, you gorgeous genius. πŸ’–βœ¨πŸ’…

πŸ“¦ where this page comes from