Skip to content

Instantly share code, notes, and snippets.

@perlpilot
Created January 5, 2011 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perlpilot/766993 to your computer and use it in GitHub Desktop.
Save perlpilot/766993 to your computer and use it in GitHub Desktop.
handles => ARRAY | HASH | REGEXP | ROLE | ROLETYPE | DUCKTYPE | CODE
The handles option provides Moose classes with automated delegation features.
This is a pretty complex and powerful option. It accepts many different option
formats, each with its own benefits and drawbacks.
NOTE: The class being delegated to does not need to be a Moose based class, which
is why this feature is especially useful when wrapping non-Moose classes.
All handles option formats share the following traits:
You cannot override a locally defined method with a delegated method; an exception
will be thrown if you try. That is to say, if you define "foo" in your class, you
cannot override it with a delegated "foo". This is almost never something you
would want to do, and if it is, you should do it by hand and not use Moose.
You cannot override any of the methods found in Moose::Object, or the "BUILD" and
"DEMOLISH" methods. These will not throw an exception, but will silently move on
to the next method in the list. My reasoning for this is that you would almost
never want to do this, since it usually breaks your class. As with overriding
locally defined methods, if you do want to do this, you should do it manually, not
with Moose.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment