Moose::Util - Utilities for working with Moose classes
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!\n"; } my $class = search_class_by_role($object, 'FooRole'); print "Nearest class with 'FooRole' is $class\n";
This is a set of utility functions to help working with Moose classes, and is used internally by Moose itself. The goal is to provide useful functions that for both Moose users and Moose extenders (MooseX:: authors).
This is a relatively new addition to the Moose toolchest, so ideas, suggestions and contributions to this collection are most welcome. See the TODO section below for a list of ideas for possible functions to write.
This will attempt to locate a metaclass for the given $class_or_obj and return it.
$class_or_obj
Returns true if $class_or_obj can do the role $role_name.
$role_name
Returns first class in precedence list that consumed $role_name.
Given an $applicant (which can somehow be turned into either a metaclass or a metarole) and a list of @roles this will do the right thing to apply the @roles to the $applicant. This is actually used internally by both Moose and Moose::Role, and the @roles will be pre-processed through Data::OptList::mkopt to allow for the additional arguments to be passed.
$applicant
@roles
Returns the values of the $instance's fields keyed by the attribute names.
$instance
Returns a hash reference where the keys are all the attributes' init_args and the values are the instance's fields. Attributes without an init_arg will be skipped.
init_arg
Resolve a short name like in e.g.
has foo => ( metaclass => "Bar", );
to a full class name.
Here is a list of possible functions to write
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.
Anders Nor Berle <debolaz@gmail.com>
with contributions from:
Robert (phaylon) Sedlacek
Stevan Little
Copyright 2007-2008 by Infinity Interactive, Inc.
http://www.iinteractive.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Moose, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Moose
CPAN shell
perl -MCPAN -e shell install Moose
For more information on module installation, please visit the detailed CPAN module installation guide.