Moose::...MetaRole(3)

πŸ’– Moose::Util::MetaRole β€” the manual page, bestie edition πŸ’–

okay so this is Moose::Util::MetaRole(3), straight out of the User Contributed Perl Documentation collection. yes it's a real manual page, yes it's about metaclasses, no you don't have to be scared. sit down, grab a boba, we're doing this together πŸ§‹βœ¨


🌸 NAME 🌸

Moose::Util::MetaRole β€” apply roles to any metaclass, and also to the object base class. like, any of them. all of them. go off πŸ’…


⭐ VERSION ⭐

version 2.4000 β€” that's the one, that's the version, don't @ me πŸŽ€


✨ SYNOPSIS ✨

here's the whole vibe in code form, copied exactly, no notes:

package MyApp::Moose;

use Moose ();
use Moose::Exporter;
use Moose::Util::MetaRole;

use MyApp::Role::Meta::Class;
use MyApp::Role::Meta::Method::Constructor;
use MyApp::Role::Object;

Moose::Exporter->setup_import_methods( also => 'Moose' );

sub init_meta {
    shift;
    my %args = @_;

    Moose->init_meta(%args);

    Moose::Util::MetaRole::apply_metaroles(
        for             => $args{for_class},
        class_metaroles => {
            class       => ['MyApp::Role::Meta::Class'],
            constructor => ['MyApp::Role::Meta::Method::Constructor'],
        },
    );

    Moose::Util::MetaRole::apply_base_class_roles(
        for   => $args{for_class},
        roles => ['MyApp::Role::Object'],
    );

    return $args{for_class}->meta();
}

look at her. so structured. so iconic πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so this utility module exists to help authors of Moose extensions write extensions that can actually cooperate with other Moose extensions. no beef, no drama, just teamwork. and the way you do that is: you write your extensions as roles, and then those roles get dynamically applied to the caller's metaclasses. periodt πŸ’«

the way this module is so thoughtful is that it makes sure to preserve any existing superclasses and roles already set for the meta objects. which means β€” and this is the slay part β€” any number of extensions can apply roles in any order. no cap. it just works πŸ™Œ


πŸ’œ USAGE πŸ’œ

the easiest way to use this module, fr fr, is through Moose::Exporter. that guy can generate the appropriate init_meta method for you, and also make sure it gets called when imported. let him cook 🍳


πŸŽ€ FUNCTIONS πŸŽ€

this module provides two functions. two. that's it. we love a small API πŸ’–

🌟 apply_metaroles( ... ) 🌟

this function will apply roles to one or more metaclasses for the specified class. and it returns a new metaclass object for the class or role you passed in the for parameter. brand new object, fresh out the box 🎁

it accepts the following parameters:

  • for => $name β€” this specifies the class for which to alter the meta classes. it can be a package name, or an appropriate meta-object (a Moose::Meta::Class or Moose::Meta::Role). so like, either the name-name or the whole object, your call bestie 🫢
  • class_metaroles => \%roles β€” this is a hash reference specifying which metaroles will be applied to the class metaclass and its contained metaclasses and helper classes. each key should in turn point to an array reference of role names.

it accepts the following keys:

  • class
  • attribute
  • method
  • wrapped_method
  • instance
  • constructor
  • destructor
  • error

that's the whole list. all eight of them. count them if you want, they're all there 😌

  • role_metaroles => \%roles β€” this is a hash reference specifying which metaroles will be applied to the role metaclass and its contained metaclasses and helper classes.

it accepts the following keys:

  • role
  • attribute
  • method
  • required_method
  • conflicting_method
  • application_to_class
  • application_to_role
  • application_to_instance
  • application_role_summation
  • applied_attribute

yes, ten. ten whole keys. she's thorough, she's committed, she ate πŸ”₯

🌈 apply_base_class_roles( for => $class, roles => @roles ) 🌈

this function will apply the specified roles to the object's base class. that's the whole description. short, sweet, done. it's giving main character with minimal dialogue πŸ’…


😭 BUGS 😭

see "BUGS" in Moose for details on reporting bugs. go tell Moose, not me, i'm just the messenger πŸ™ˆ


πŸ‘‘ AUTHORS πŸ‘‘

these are the legends who built this. absolute icons, every single one:

  • 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>

ten authors. ten. collaborative queen behavior fr fr 🌸


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. so like, go forth, remix, redistribute, it's all legal and it's all yours 🫢


okay that's the whole page bestie!! and before you go β€” this was perl v5.42.0, dated 2025-07-25, and that's the footer, so consider yourself properly signed off ✨ bye ily, go apply some roles to some metaclasses responsibly πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from