-
-
27 Jul 2018 17:58:13 UTC
- Distribution: Kavorka
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (1)
- Testers (2941 / 448 / 0)
- Kwalitee
Bus factor: 1- 86.27% Coverage
- License: perl_5
- Perl: v5.14.0
- Activity
24 month- Tools
- Download (77.93KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 6 contributorsNAME
Kavorka::Manual::MethodModifiers - before/after/around keywords
DESCRIPTION
Kavorka provides the
before
,after
andaround
keywords for method modifiers.Method modifiers should work in Moose, Moo, Mouse and Role::Tiny classes and roles. In other classes they will fall back to using Class::Method::Modifiers.
The keywords
augment
andoverride
are also available, but will only work in classes backed by a framework that supports these modifiers (i.e. Moose or Mouse, but not Moo).The anatomy of a method modifier:
The keyword introducing the method.
The method names.
The signature (optional).
Traits (optional).
The prototype (optional).
The attribute list (optional).
The modifier body.
Example:
# (1) (2) (3) (4) (5) (6) (7) after foobar ($foo) is cool :($) :cached { $self->log("foobar $foo") }
The Keyword
By default, these keywords are exported. They must be exported by request:
use Kavorka qw( before after around ); use Kavorka qw( -modifiers );
The Method Names
These are the names of the methods being wrapped.
Multiple names may be separated by colons:
after foo, bar, baz { ... }
The Signature
See Kavorka::Manual::Signatures.
The
before
andafter
keywords have a default invocant called$self
, but it does not have a type constraint, so can equally be used for class or object methods.The
around
modifier defines two invocants called$next
and$self
. (${^NEXT}
is also available as an alias for$next
for backwards compatibility with Moops::MethodModifiers.)Beware using type constraints for method modifiers (which are essentially wrappers); constraints will be checked at each level of wrapping which will slow down method calls.
Traits
See Kavorka::Manual::ExtendingKavorka.
The Prototype
See Kavorka::Manual::PrototypeAndAttributes.
Note however that prototypes are fairly useless for methods.
The Attributes
Attributes may alternatively be provided before the signature.
See Kavorka::Manual::PrototypeAndAttributes.
Note that this applies the attribute to the modifier code, and not to the method being modified.
The Modifier Body
This is more or less what you'd expect from the modifier body you'd write with Moose, however the lexical variables for parameters are pre-declared and pre-populated, and invocants have been shifted off
@_
.BUGS
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=Kavorka.
SEE ALSO
Kavorka::Manual, Kavorka::Manual::Signatures, Kavorka::Manual::PrototypeAndAttributes, Kavorka::Manual::Methods.
AUTHOR
Toby Inkster <tobyink@cpan.org>.
COPYRIGHT AND LICENCE
This software is copyright (c) 2013-2014, 2017 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
DISCLAIMER OF WARRANTIES
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Module Install Instructions
To install Kavorka, copy and paste the appropriate command in to your terminal.
cpanm Kavorka
perl -MCPAN -e shell install Kavorka
For more information on module installation, please visit the detailed CPAN module installation guide.