1 package Moose::Cookbook::Meta::WhyMeta;
3 # ABSTRACT: Welcome to the meta world (Why Go Meta?)
12 You might want to read L<Moose::Manual::MOP> if you haven't done so
15 If you've ever thought "Moose is great, but I wish it did X
16 differently", then you've gone meta. The meta recipes demonstrate how
17 to change and extend the way Moose works by extending and overriding
18 how the meta classes (L<Moose::Meta::Class>,
19 L<Moose::Meta::Attribute>, etc) work.
21 The metaclass API is a set of classes that describe classes, roles,
22 attributes, etc. The metaclass API lets you ask questions about a
23 class, like "what attributes does it have?", or "what roles does the
26 The metaclass system also lets you make changes to a class, for
27 example by adding new methods or attributes.
29 The interface presented by L<Moose.pm|Moose> (C<has>, C<with>,
30 C<extends>) is just a thin layer of syntactic sugar over the
31 underlying metaclass system.
33 By extending and changing how this metaclass system works, you can
34 create your own Moose variant.
38 Let's say that you want to add additional properties to
39 attributes. Specifically, we want to add a "label" property to each
40 attribute, so we can write C<<
41 My::Class->meta()->get_attribute('size')->label() >>. The first
42 recipe shows how to do this using an attribute trait.
44 You might also want to add additional properties to your
45 metaclass. For example, if you were writing an ORM based on Moose, you
46 could associate a table name with each class via the class's metaclass
47 object, letting you write C<< My::Class->meta()->table_name() >>.
51 Many of the MooseX modules on CPAN implement metaclass extensions. A
52 couple good examples include L<MooseX::Aliases> and
53 L<MooseX::UndefTolerant>. For a more complex example see
54 L<Fey::ORM> or L<Bread::Board::Declare>.