Moose::...WhyMeta(3)

πŸ’– NAME πŸ’–

Moose::Cookbook::Meta::WhyMeta β€” welcome to the meta world, bestie (aka Why Go Meta?) πŸ¦‹

So like, the manual name is Moose::...WhyMeta(3) and it lives in the User Contributed Perl Documentation, and it is giving meta main character energy from the very first line. Periodt.


✨ VERSION ✨

version 2.4000 β€” yeah that's the one, no cap.


🌸 SUMMARY 🌸

Okay so first things first: if you haven't read Moose::Manual::MOP yet, go do that. Like, right now. This page will hit way harder afterward, trust. πŸ™ˆ

So here's the vibe. If you have ever thought "Moose is great, but I wish it did X differently" β€” congrats babe, you've officially gone meta. πŸ’… The meta recipes are all about showing you how to change and extend the way Moose works, by extending and overriding how the meta classes work β€” think Moose::Meta::Class, Moose::Meta::Attribute, and the rest of that lil squad.

The metaclass API is literally just a set of classes that describe classes, roles, attributes, etc. It's giving "classes about classes." And it lets you ask questions about a class, like "what attributes does it have?" or "what roles does the class do?" πŸ‘‘

And not only can you ask β€” the metaclass system also lets you make changes to a class. Adding new methods? New attributes? Yeah. All of it. πŸŽ€

Here's the part that lowkey blows minds: the interface you already know and love from Moose.pm β€” has, with, extends β€” is just a thin layer of syntactic sugar sitting on top of the underlying metaclass system. That's it. That's the whole thing.

So by extending and changing how that metaclass system works, you can create your own Moose variant. Your own. Custom. Iconic. πŸ‘‘

🧚 Examples 🧚

Say you wanna add extra properties to attributes. Specifically, let's say we want to add a label property to each attribute, so you can write:

My::Class->meta()->get_attribute('size')->label()

The first recipe shows exactly how to pull that off using an attribute trait. Slay. ✨

You might also wanna add extra properties to your metaclass itself. For example, if you were writing an ORM based on Moose, you could associate a table name with each class via the class's metaclass object, letting you write:

My::Class->meta()->table_name()

Obsessed, honestly. 🫢


πŸ”₯ SEE ALSO πŸ”₯

So many of the MooseX modules on CPAN implement metaclass extensions, and a couple of really good examples include MooseX::Aliases and MooseX::UndefTolerant. If you want something more complex to sink your teeth into, go look at Fey::ORM or Bread::Board::Declare. πŸ’œ


πŸ‘‘ AUTHORS πŸ‘‘

Shoutout to the legends, fr fr:

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

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.

Not me being legally required to say that, but also it's genuinely a slay that it's free software. πŸ“

Okay bestie that's the whole page, mwah πŸ’‹ This cutie was served up as part of perl v5.42.0 on 2025-07-25, courtesy of the User Contributed Perl Documentation. Go forth and go meta. 🌈⭐

πŸ“¦ where this page comes from