.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Moose::Util 3pm" .TH Moose::Util 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Moose::Util \- Utilities for working with Moose classes .SH VERSION .IX Header "VERSION" version 2.2207 .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Moose::Util qw/find_meta does_role search_class_by_role/; \& \& my $meta = find_meta($object) || die "No metaclass found"; \& \& if (does_role($object, $role)) { \& print "The object can do $role!\en"; \& } \& \& my $class = search_class_by_role($object, \*(AqFooRole\*(Aq); \& print "Nearest class with \*(AqFooRole\*(Aq is $class\en"; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This module provides a set of utility functions. Many of these functions are intended for use in Moose itself or MooseX modules, but some of them may be useful for use in your own code. .SH "EXPORTED FUNCTIONS" .IX Header "EXPORTED FUNCTIONS" .SS find_meta($class_or_obj) .IX Subsection "find_meta($class_or_obj)" This method takes a class name or object and attempts to find a metaclass for the class, if one exists. It will \fBnot\fR create one if it does not yet exist. .SS is_role($package_or_obj) .IX Subsection "is_role($package_or_obj)" Returns true if the provided package name or object is a Moose::Role. .ie n .SS "does_role($class_or_obj, $role_or_obj)" .el .SS "does_role($class_or_obj, \f(CW$role_or_obj\fP)" .IX Subsection "does_role($class_or_obj, $role_or_obj)" Returns true if \f(CW$class_or_obj\fR does the given \f(CW$role_or_obj\fR. The role can be provided as a name or a Moose::Meta::Role object. .PP The class must already have a metaclass for this to work. If it doesn't, this function simply returns false. .ie n .SS "search_class_by_role($class_or_obj, $role_or_obj)" .el .SS "search_class_by_role($class_or_obj, \f(CW$role_or_obj\fP)" .IX Subsection "search_class_by_role($class_or_obj, $role_or_obj)" Returns the first class in the class's precedence list that does \&\f(CW$role_or_obj\fR, if any. The role can be either a name or a Moose::Meta::Role object. .PP The class must already have a metaclass for this to work. .ie n .SS "apply_all_roles($applicant, @roles)" .el .SS "apply_all_roles($applicant, \f(CW@roles\fP)" .IX Subsection "apply_all_roles($applicant, @roles)" This function applies one or more roles to the given \f(CW$applicant\fR. The applicant can be a role name, class name, or object. .PP The \f(CW$applicant\fR must already have a metaclass object. .PP The list of \f(CW@roles\fR should a list of names or Moose::Meta::Role objects, each of which can be followed by an optional hash reference of options (\f(CW\*(C`\-excludes\*(C'\fR and \f(CW\*(C`\-alias\*(C'\fR). .ie n .SS "ensure_all_roles($applicant, @roles)" .el .SS "ensure_all_roles($applicant, \f(CW@roles\fP)" .IX Subsection "ensure_all_roles($applicant, @roles)" This function is similar to \f(CW\*(C`apply_all_roles\*(C'\fR, but only applies roles that \&\f(CW$applicant\fR does not already consume. .ie n .SS "with_traits($class_name, @role_names)" .el .SS "with_traits($class_name, \f(CW@role_names\fP)" .IX Subsection "with_traits($class_name, @role_names)" This function creates a new class from \f(CW$class_name\fR with each of \&\f(CW@role_names\fR applied. It returns the name of the new class. .ie n .SS "get_all_attribute_values($meta, $instance)" .el .SS "get_all_attribute_values($meta, \f(CW$instance\fP)" .IX Subsection "get_all_attribute_values($meta, $instance)" Returns a hash reference containing all of the \f(CW$instance\fR's attributes. The keys are attribute names. .ie n .SS "get_all_init_args($meta, $instance)" .el .SS "get_all_init_args($meta, \f(CW$instance\fP)" .IX Subsection "get_all_init_args($meta, $instance)" Returns a hash reference containing all of the \f(CW\*(C`init_arg\*(C'\fR values for the instance's attributes. The values are the associated attribute values. If an attribute does not have a defined \f(CW\*(C`init_arg\*(C'\fR, it is skipped. .PP This could be useful in cloning an object. .ie n .SS "resolve_metaclass_alias($category, $name, %options)" .el .SS "resolve_metaclass_alias($category, \f(CW$name\fP, \f(CW%options\fP)" .IX Subsection "resolve_metaclass_alias($category, $name, %options)" .ie n .SS "resolve_metatrait_alias($category, $name, %options)" .el .SS "resolve_metatrait_alias($category, \f(CW$name\fP, \f(CW%options\fP)" .IX Subsection "resolve_metatrait_alias($category, $name, %options)" Resolves a short name to a full class name. Short names are often used when specifying the \f(CW\*(C`metaclass\*(C'\fR or \f(CW\*(C`traits\*(C'\fR option for an attribute: .PP .Vb 3 \& has foo => ( \& metaclass => "Bar", \& ); .Ve .PP The name resolution mechanism is covered in "Metaclass and Trait Name Resolution" in Moose. .ie n .SS "meta_class_alias($to[, $from])" .el .SS "meta_class_alias($to[, \f(CW$from\fP])" .IX Subsection "meta_class_alias($to[, $from])" .ie n .SS "meta_attribute_alias($to[, $from])" .el .SS "meta_attribute_alias($to[, \f(CW$from\fP])" .IX Subsection "meta_attribute_alias($to[, $from])" Create an alias from the class \f(CW$from\fR (or the current package, if \&\f(CW$from\fR is unspecified), so that "Metaclass and Trait Name Resolution" in Moose works properly. .SS english_list(@items) .IX Subsection "english_list(@items)" Given a list of scalars, turns them into a proper list in English ("one and two", "one, two, three, and four"). This is used to help us make nicer error messages. .ie n .SS "throw_exception( $class_name, %arguments_to_exception)" .el .SS "throw_exception( \f(CW$class_name\fP, \f(CW%arguments_to_exception\fP)" .IX Subsection "throw_exception( $class_name, %arguments_to_exception)" Calls die with an object of Moose::Exception::$class_name, with \&\f(CW%arguments_to_exception\fR passed as arguments. .SH TODO .IX Header "TODO" Here is a list of possible functions to write .IP "discovering original method from modified method" 4 .IX Item "discovering original method from modified method" .PD 0 .IP "search for origin class of a method or attribute" 4 .IX Item "search for origin class of a method or attribute" .PD .SH BUGS .IX Header "BUGS" See "BUGS" in Moose for details on reporting bugs. .SH AUTHORS .IX Header "AUTHORS" .IP \(bu 4 Stevan Little .IP \(bu 4 Dave Rolsky .IP \(bu 4 Jesse Luehrs .IP \(bu 4 Shawn M Moore .IP \(bu 4 יובל קוג'מן (Yuval Kogman) .IP \(bu 4 Karen Etheridge .IP \(bu 4 Florian Ragwitz .IP \(bu 4 Hans Dieter Pearcey .IP \(bu 4 Chris Prather .IP \(bu 4 Matt S Trout .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2006 by Infinity Interactive, Inc. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.