From: Jesse Luehrs Date: Tue, 23 Mar 2010 06:41:36 +0000 (-0500) Subject: add docs for the various ways to specify methods to wrap X-Git-Tag: 1.00~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=78946cf86122e1a6e5ff8fa3b7ad8c176bf3f05f;p=gitmo%2FMoose.git add docs for the various ways to specify methods to wrap --- diff --git a/lib/Moose.pm b/lib/Moose.pm index 31f5684..5541b82 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -804,11 +804,11 @@ B overridden, or removed. =back -=item B sub { ... }> +=item B sub { ... }> -=item B sub { ... }> +=item B sub { ... }> -=item B sub { ... }> +=item B sub { ... }> These three items are syntactic sugar for the before, after, and around method modifier features that L provides. More information on these may be diff --git a/lib/Moose/Manual/MethodModifiers.pod b/lib/Moose/Manual/MethodModifiers.pod index 5b21dd4..3ac53b0 100644 --- a/lib/Moose/Manual/MethodModifiers.pod +++ b/lib/Moose/Manual/MethodModifiers.pod @@ -129,6 +129,47 @@ I the object, and finally any arguments passed to the method. return $self->$orig($size); }; +C, C, and C can also modify multiple methods +at once. The simplest example of this is passing them as a list: + + before qw(foo bar baz) => sub { + warn "something is being called!"; + }; + +This will add a C modifier to each of the C, C, +and C methods in the current class, just as though a separate +call to C was made for each of them. The list can be passed +either as a bare list, or as an arrayref. Note that the name of the +function being modified isn't passed in in any way; this syntax is +only intended for cases where the function being modified doesn't +actually matter. If the function name does matter, something like: + + for my $func (qw(foo bar baz)) { + before $func => sub { + warn "$func was called!"; + }; + } + +would be more appropriate. + +In addition, you can specify a regular expression to indicate the +methods to wrap, like so: + + after qr/^command_/ => sub { + warn "got a command"; + }; + +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, regarding +not being given the name of the method being modified. 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, etc., as this could cause +unintended (and hard to debug) problems. + =head1 INNER AND AUGMENT Augment and inner are two halves of the same feature. The augment