Stevan Little > Moose-0.38 > Moose::Util

Download:
Moose-0.38.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  4
Open  10
View Bugs
Report a bug
Module Version: 0.03   Source   Latest Release: Moose-0.93

NAME ^

Moose::Util - Utilities for working with Moose classes

SYNOPSIS ^

  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";

DESCRIPTION ^

This is a set of utility functions to help working with Moose classes. This is an experimental module, and it's not 100% clear what purpose it will serve. That said, 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.

EXPORTED FUNCTIONS ^

find_meta ($class_or_obj)

This will attempt to locate a metaclass for the given $class_or_obj and return it.

does_role ($class_or_obj, $role_name)

Returns true if $class_or_obj can do the role $role_name.

search_class_by_role ($class_or_obj, $role_name)

Returns first class in precedence list that consumed $role_name.

apply_all_roles ($applicant, @roles)

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.

get_all_attribute_values($meta, $instance)

Returns the values of the $instance's fields keyed by the attribute names.

get_all_init_args($meta, $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.

TODO ^

Here is a list of possible functions to write

discovering original method from modified method
search for origin class of a method or attribute

BUGS ^

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.

AUTHOR ^

Anders Nor Berle <debolaz@gmail.com>

with contributions from:

Robert (phaylon) Sedlacek

Stevan Little

COPYRIGHT AND LICENSE ^

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.