ea6341d14666ab4a05934634f386a59534a44d14
[gitmo/Moose.git] / lib / Moose / Cookbook / Meta / Recipe1.pod
1 package Moose::Cookbook::Meta::Recipe1;
2
3 # ABSTRACT: Welcome to the meta world (Why Go Meta?)
4
5 __END__
6
7
8 =pod
9
10 =head1 SUMMARY
11
12 You might want to read L<Moose::Manual::MOP> if you haven't done so
13 yet.
14
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.
20
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
24 class do?"
25
26 The metaclass system also lets you make changes to a class, for
27 example by adding new methods or attributes.
28
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.
32
33 By extending and changing how this metaclass system works, you can
34 create your own Moose variant.
35
36 =head2 Examples
37
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 two
42 recipes show two different ways to do this, one with a full
43 meta-attribute subclass, and the other with an attribute trait.
44
45 You might also want to add additional properties to your
46 metaclass. For example, if you were writing an ORM based on Moose, you
47 could associate a table name with each class via the class's metaclass
48 object, letting you write C<< My::Class->meta()->table_name() >>.
49
50 =head1 SEE ALSO
51
52 Many of the MooseX modules on CPAN implement metaclass extensions. A
53 couple good examples include L<MooseX::Aliases> and
54 L<MooseX::UndefTolerant>. For a more complex example see
55 L<Fey::ORM> or L<Bread::Board::Declare>.
56
57 =cut
58
59