1Moose::Util(3)        User Contributed Perl Documentation       Moose::Util(3)
2
3
4

NAME

6       Moose::Util - Utilities for working with Moose classes
7

SYNOPSIS

9         use Moose::Util qw/find_meta does_role search_class_by_role/;
10
11         my $meta = find_meta($object) || die "No metaclass found";
12
13         if (does_role($object, $role)) {
14           print "The object can do $role!\n";
15         }
16
17         my $class = search_class_by_role($object, 'FooRole');
18         print "Nearest class with 'FooRole' is $class\n";
19

DESCRIPTION

21       This module provides a set of utility functions. Many of these
22       functions are intended for use in Moose itself or MooseX modules, but
23       some of them may be useful for use in your own code.
24

EXPORTED FUNCTIONS

26       find_meta($class_or_obj)
27           This method takes a class name or object and attempts to find a
28           metaclass for the class, if one exists. It will not create one if
29           it does not yet exist.
30
31       does_role($class_or_obj, $role_or_obj)
32           Returns true if $class_or_obj does the given $role_or_obj. The role
33           can be provided as a name or a Moose::Meta::Role object.
34
35           The class must already have a metaclass for this to work. If it
36           doesn't, this function simply returns false.
37
38       search_class_by_role($class_or_obj, $role_or_obj)
39           Returns the first class in the class's precedence list that does
40           $role_or_obj, if any. The role can be either a name or a
41           Moose::Meta::Role object.
42
43           The class must already have a metaclass for this to work.
44
45       apply_all_roles($applicant, @roles)
46           This function applies one or more roles to the given $applicant The
47           applicant can be a role name, class name, or object.
48
49           The $applicant must already have a metaclass object.
50
51           The list of @roles should a list of names or Moose::Meta::Role
52           objects, each of which can be followed by an optional hash
53           reference of options ("-excludes" and "-alias").
54
55       ensure_all_roles($applicant, @roles)
56           This function is similar to "apply_all_roles", but only applies
57           roles that $applicant does not already consume.
58
59       with_traits($class_name, @role_names)
60           This function creates a new class from $class_name with each of
61           @role_names applied. It returns the name of the new class.
62
63       get_all_attribute_values($meta, $instance)
64           Returns a hash reference containing all of the $instance's
65           attributes. The keys are attribute names.
66
67       get_all_init_args($meta, $instance)
68           Returns a hash reference containing all of the "init_arg" values
69           for the instance's attributes. The values are the associated
70           attribute values. If an attribute does not have a defined
71           "init_arg", it is skipped.
72
73           This could be useful in cloning an object.
74
75       resolve_metaclass_alias($category, $name, %options)
76       resolve_metatrait_alias($category, $name, %options)
77           Resolves a short name to a full class name. Short names are often
78           used when specifying the "metaclass" or "traits" option for an
79           attribute:
80
81               has foo => (
82                   metaclass => "Bar",
83               );
84
85           The name resolution mechanism is covered in "Metaclass and Trait
86           Name Resolution" in Moose.
87
88       meta_class_alias($to[, $from])
89       meta_attribute_alias($to[, $from])
90           Create an alias from the class $from (or the current package, if
91           $from is unspecified), so that "Metaclass and Trait Name
92           Resolution" in Moose works properly.
93
94       english_list(@items)
95           Given a list of scalars, turns them into a proper list in English
96           ("one and two", "one, two, three, and four"). This is used to help
97           us make nicer error messages.
98

TODO

100       Here is a list of possible functions to write
101
102       discovering original method from modified method
103       search for origin class of a method or attribute
104

BUGS

106       See "BUGS" in Moose for details on reporting bugs.
107

AUTHOR

109       Anders Nor Berle <debolaz@gmail.com>
110
111       with contributions from:
112
113       Robert (phaylon) Sedlacek
114
115       Stevan Little
116
118       Copyright 2007-2009 by Infinity Interactive, Inc.
119
120       <http://www.iinteractive.com>
121
122       This library is free software; you can redistribute it and/or modify it
123       under the same terms as Perl itself.
124
125
126
127perl v5.12.2                      2010-08-28                    Moose::Util(3)
Impressum