1Moose::Cookbook::Meta::UWsheyrMeCtoan(t3r)ibuted Perl DoMcouomseen:t:aCtoiooknbook::Meta::WhyMeta(3)
2
3
4
6 Moose::Cookbook::Meta::WhyMeta - Welcome to the meta world (Why Go
7 Meta?)
8
10 version 2.2206
11
13 You might want to read Moose::Manual::MOP if you haven't done so 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 (Moose::Meta::Class, Moose::Meta::Attribute, etc)
19 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 example
27 by adding new methods or attributes.
28
29 The interface presented by Moose.pm ("has", "with", "extends") is just
30 a thin layer of syntactic sugar over the underlying metaclass system.
31
32 By extending and changing how this metaclass system works, you can
33 create your own Moose variant.
34
35 Examples
36 Let's say that you want to add additional properties to attributes.
37 Specifically, we want to add a "label" property to each attribute, so
38 we can write "My::Class->meta()->get_attribute('size')->label()". The
39 first recipe shows how to do this using an attribute trait.
40
41 You might also want to add additional properties to your metaclass. For
42 example, if you were writing an ORM based on Moose, you could associate
43 a table name with each class via the class's metaclass object, letting
44 you write "My::Class->meta()->table_name()".
45
47 Many of the MooseX modules on CPAN implement metaclass extensions. A
48 couple good examples include MooseX::Aliases and MooseX::UndefTolerant.
49 For a more complex example see Fey::ORM or Bread::Board::Declare.
50
52 • Stevan Little <stevan@cpan.org>
53
54 • Dave Rolsky <autarch@urth.org>
55
56 • Jesse Luehrs <doy@cpan.org>
57
58 • Shawn M Moore <sartak@cpan.org>
59
60 • יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
61
62 • Karen Etheridge <ether@cpan.org>
63
64 • Florian Ragwitz <rafl@debian.org>
65
66 • Hans Dieter Pearcey <hdp@cpan.org>
67
68 • Chris Prather <chris@prather.org>
69
70 • Matt S Trout <mstrout@cpan.org>
71
73 This software is copyright (c) 2006 by Infinity Interactive, Inc.
74
75 This is free software; you can redistribute it and/or modify it under
76 the same terms as the Perl 5 programming language system itself.
77
78
79
80perl v5.38.0 2023-07-23 Moose::Cookbook::Meta::WhyMeta(3)