X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FManual%2FMethodModifiers.pod;h=a264155081eb63a1a79f07d301d0993ed905f7e9;hb=abcafa002873d10cda6b6acc9d8fb8c87ff186a8;hp=d05efd27a1b993eaa00e524f2a10cab28d6242eb;hpb=8e5dd3fb4d0102f0e91b658540172825831ee49d;p=gitmo%2FMoose.git diff --git a/lib/Moose/Manual/MethodModifiers.pod b/lib/Moose/Manual/MethodModifiers.pod index d05efd2..a264155 100644 --- a/lib/Moose/Manual/MethodModifiers.pod +++ b/lib/Moose/Manual/MethodModifiers.pod @@ -1,8 +1,10 @@ -=pod +package Moose::Manual::MethodModifiers; + +# ABSTRACT: Moose's method modifiers -=head1 NAME +__END__ -Moose::Manual::MethodModifiers - Moose's method modifiers +=pod =head1 WHAT IS A METHOD MODIFIER? @@ -73,6 +75,10 @@ modifiers work, but may not be the most natural usage. =head1 BEFORE, AFTER, AND AROUND +Method modifiers can be used to add behavior to methods without modifying the definition of those methods. + +=head2 BEFORE and AFTER modifiers + Method modifiers can be used to add behavior to a method that Moose generates for you, such as an attribute accessor: @@ -106,6 +112,8 @@ was taken. Note that the return values of both before and after modifiers are ignored. +=head2 AROUND modifiers + An around modifier is more powerful than either a before or after modifier. It can modify the arguments being passed to the original method, and you can even decide to simply not call the @@ -129,6 +137,8 @@ I the object, and finally any arguments passed to the method. return $self->$orig($size); }; +=head2 Wrapping multiple methods at once + C, C, and C can also modify multiple methods at once. The simplest example of this is passing them as a list: @@ -150,6 +160,8 @@ actually matter. If the function name does matter, use something like this: }; } +=head2 Using regular expressions to select methods to wrap + In addition, you can specify a regular expression to indicate the methods to wrap, like so: @@ -159,13 +171,15 @@ methods to wrap, like so: This will match the regular expression against each method name returned by L, and add a modifier -to each one that matches. The same caveats apply as above. Using regular -expressions to determine methods to wrap is quite a bit more powerful -than the previous alternatives, but it's also quite a bit more -dangerous. In particular, you should make sure to avoid wrapping -methods with a special meaning to Moose or Perl, such as C, C, -C, C, C, etc., as this could cause -unintended (and hard to debug) problems. +to each one that matches. The same caveats apply as above. + +Using regular expressions to determine methods to wrap is quite a bit more +powerful than the previous alternatives, but it's also quite a bit more +dangerous. Bear in mind that if your regular expression matches certain Perl +and Moose reserved method names with a special meaning to Moose or Perl, such +as C, C, C, C, C, etc, this could cause +unintended (and hard to debug) problems and is best avoided. + =head1 INNER AND AUGMENT @@ -295,17 +309,13 @@ semi-colon: after 'foo' => sub { }; -=head1 AUTHOR - -Dave Rolsky Eautarch@urth.orgE - -=head1 COPYRIGHT AND LICENSE +=cut -Copyright 2008-2010 by Infinity Interactive, Inc. +=head1 CAVEATS -L +These method modification features do not work well with multiple inheritance, +due to how method resolution is performed in Perl. Experiment with a test +program to ensure your class hierarchy works as expected, or more preferably, +don't use multiple inheritance (roles can help with this)! -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. -=cut