Commit | Line | Data |
daa0fd7d |
1 | package Moose::Cookbook::Meta::Recipe1; |
17a65b17 |
2 | |
daa0fd7d |
3 | # ABSTRACT: Welcome to the meta world (Why Go Meta?) |
4 | |
5 | __END__ |
17a65b17 |
6 | |
17a65b17 |
7 | |
daa0fd7d |
8 | =pod |
17a65b17 |
9 | |
10 | =head1 SUMMARY |
11 | |
ad0cb4db |
12 | You might want to read L<Moose::Manual::MOP> if you haven't done so |
13 | yet. |
17a65b17 |
14 | |
ad0cb4db |
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, |
17a65b17 |
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 | |
ad0cb4db |
26 | The metaclass system also lets you make changes to a class, for |
27 | example by adding new methods or attributes. |
17a65b17 |
28 | |
ad0cb4db |
29 | The interface presented by L<Moose.pm|Moose> (C<has>, C<with>, |
17a65b17 |
30 | C<extends>) is just a thin layer of syntactic sugar over the |
31 | underlying metaclass system. |
32 | |
ad0cb4db |
33 | By extending and changing how this metaclass system works, you can |
34 | create your own Moose variant. |
17a65b17 |
35 | |
36 | =head2 Examples |
37 | |
2a67e654 |
38 | Let's say that you want to add additional properties to |
17a65b17 |
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 |
ad0cb4db |
53 | couple good examples include L<MooseX::Singleton> and |
54 | L<MooseX::AttributeHelpers>. For a more complex example see |
55 | L<Fey::ORM> or L<Reaction>. |
17a65b17 |
56 | |
17a65b17 |
57 | =cut |
58 | |
59 | |