1Moose::Meta::Class(3) User Contributed Perl DocumentationMoose::Meta::Class(3)
2
3
4
6 Moose::Meta::Class - The Moose metaclass
7
9 This class is a subclass of Class::MOP::Class that provides additional
10 Moose-specific functionality.
11
12 To really understand this class, you will need to start with the
13 Class::MOP::Class documentation. This class can be understood as a set
14 of additional features on top of the basic feature provided by that
15 parent class.
16
18 "Moose::Meta::Class" is a subclass of Class::MOP::Class.
19
21 Moose::Meta::Class->initialize($package_name, %options)
22 This overrides the parent's method in order to provide its own
23 defaults for the "attribute_metaclass", "instance_metaclass", and
24 "method_metaclass" options.
25
26 These all default to the appropriate Moose class.
27
28 Moose::Meta::Class->create($package_name, %options)
29 This overrides the parent's method in order to accept a "roles"
30 option. This should be an array reference containing roles that the
31 class does, each optionally followed by a hashref of options
32 ("-excludes" and "-alias").
33
34 my $metaclass = Moose::Meta::Class->create( 'New::Class', roles => [...] );
35
36 Moose::Meta::Class->create_anon_class
37 This overrides the parent's method to accept a "roles" option, just
38 as "create" does.
39
40 It also accepts a "cache" option. If this is true, then the
41 anonymous class will be cached based on its superclasses and roles.
42 If an existing anonymous class in the cache has the same
43 superclasses and roles, it will be reused.
44
45 my $metaclass = Moose::Meta::Class->create_anon_class(
46 superclasses => ['Foo'],
47 roles => [qw/Some Roles Go Here/],
48 cache => 1,
49 );
50
51 Each entry in both the "superclasses" and the "roles" option can be
52 followed by a hash reference with arguments. The "superclasses"
53 option can be supplied with a -version option that ensures the
54 loaded superclass satisfies the required version. The "role" option
55 also takes the "-version" as an argument, but the option hash
56 reference can also contain any other role relevant values like
57 exclusions or parameterized role arguments.
58
59 $metaclass->make_immutable(%options)
60 This overrides the parent's method to add a few options.
61 Specifically, it uses the Moose-specific constructor and destructor
62 classes, and enables inlining the destructor.
63
64 Also, since Moose always inlines attributes, it sets the
65 "inline_accessors" option to false.
66
67 $metaclass->new_object(%params)
68 This overrides the parent's method in order to add support for
69 attribute triggers.
70
71 $metaclass->superclasses(@superclasses)
72 This is the accessor allowing you to read or change the parents of
73 the class.
74
75 Each superclass can be followed by a hash reference containing a
76 -version value. If the version requirement is not satisfied an
77 error will be thrown.
78
79 $metaclass->add_override_method_modifier($name, $sub)
80 This adds an "override" method modifier to the package.
81
82 $metaclass->add_augment_method_modifier($name, $sub)
83 This adds an "augment" method modifier to the package.
84
85 $metaclass->calculate_all_roles
86 This will return a unique array of "Moose::Meta::Role" instances
87 which are attached to this class.
88
89 $metaclass->calculate_all_roles_with_inheritance
90 This will return a unique array of "Moose::Meta::Role" instances
91 which are attached to this class, and each of this class's
92 ancestors.
93
94 $metaclass->add_role($role)
95 This takes a Moose::Meta::Role object, and adds it to the class's
96 list of roles. This does not actually apply the role to the class.
97
98 $metaclass->role_applications
99 Returns a list of Moose::Meta::Role::Application::ToClass objects,
100 which contain the arguments to role application.
101
102 $metaclass->add_role_application($application)
103 This takes a Moose::Meta::Role::Application::ToClass object, and
104 adds it to the class's list of role applications. This does not
105 actually apply any role to the class; it is only for tracking role
106 applications.
107
108 $metaclass->does_role($role)
109 This returns a boolean indicating whether or not the class does the
110 specified role. The role provided can be either a role name or a
111 Moose::Meta::Role object. This tests both the class and its
112 parents.
113
114 $metaclass->excludes_role($role_name)
115 A class excludes a role if it has already composed a role which
116 excludes the named role. This tests both the class and its parents.
117
118 $metaclass->add_attribute($attr_name, %params|$params)
119 This overrides the parent's method in order to allow the parameters
120 to be provided as a hash reference.
121
122 $metaclass->constructor_class($class_name)
123 $metaclass->destructor_class($class_name)
124 These are the names of classes used when making a class immutable.
125 These default to Moose::Meta::Method::Constructor and
126 Moose::Meta::Method::Destructor respectively. These accessors are
127 read-write, so you can use them to change the class name.
128
129 $metaclass->error_class($class_name)
130 The name of the class used to throw errors. This defaults to
131 Moose::Error::Default, which generates an error with a stacktrace
132 just like "Carp::confess".
133
134 $metaclass->throw_error($message, %extra)
135 Throws the error created by "create_error" using "raise_error"
136
138 See "BUGS" in Moose for details on reporting bugs.
139
141 Stevan Little <stevan@iinteractive.com>
142
144 Copyright 2006-2010 by Infinity Interactive, Inc.
145
146 <http://www.iinteractive.com>
147
148 This library is free software; you can redistribute it and/or modify it
149 under the same terms as Perl itself.
150
151
152
153perl v5.12.2 2010-08-28 Moose::Meta::Class(3)