NAME
Kavorka - function signatures with the lure of the animal
SYNOPSIS
use Kavorka;fun maxnum (Num @numbers) { my $max = shift @numbers; for (@numbers) { $max = $_ if $max < $_; } return $max;}my $biggest = maxnum(42, 3.14159, 666);
STATUS
Kavorka is still at a very early stage of development; there are likely to be many bugs that still need to be shaken out. Certain syntax features are a little odd and may need to be changed in incompatible ways.
DESCRIPTION
Kavorka providesfun
andmethod
keywords for declaring functions and methods. It uses Perl 5.14's keyword API, so should work more reliably than source filters orDevel::Declare-based modules.
The syntax provided by Kavorka is largely inspired by Perl 6, though it has also been greatly influenced byMethod::Signatures andFunction::Parameters.
For information using the keywords exported by Kavorka:
Exports
-default
Exports
fun
andmethod
.-modifiers
Exports
before
,after
, andaround
.-allmodifiers
Exports
before
,after
,around
,augment
, andoverride
.-all
Exports
fun
,method
,before
,after
,around
,augment
,override
,classmethod
,objectmethod
, andmulti
.
For example:
# Everything except objectmethod and multi...use Kavorka qw( -default -allmodifiers classmethod );
You can rename imported functions:
use Kavorka method => { -as => 'meth' };
You can provide alternative implementations:
# use My::Sub::Method instead of Kavorka::Sub::Methoduse Kavorka method => { implementation => 'My::Sub::Method' };
Or add traits to the default implementation:
use Kavorka method => { traits => ['My::Sub::Role::Foo'] };
SeeExporter::Tiny for more tips.
Function Introspection API
The coderef for any sub created by Kavorka can be passed to theKavorka->info
method. This returns a blessed object that does theKavorka::Sub role.
fun foo (:$x, :$y) { }my $info = Kavorka->info(\&foo);my $function_name = $info->qualified_name;my @named_params = $info->signature->named_params;say $named_params[0]->named_names->[0]; # says 'x'
SeeKavorka::Sub,Kavorka::Signature andKavorka::Parameter for further details.
If you're using Moose, consider usingMooseX::KavorkaInfo to expose Kavorka method signatures via the meta object protocol.
Kavorka::Manual::API provides more details and examples using the introspection API.
CAVEATS
As noted inKavorka::Manual::PrototypeAndAttributes, subroutine attributes don't work properly for anonymous functions.
This module is based onParse::Keyword, which has a chronically broken implementation of closures. Kavorka usesPadWalker to attempt to work around the problem. This mostly seems to work, but you may experience some problems in edge cases, especially for anonymous functions and methods.
If importing Kavorka's method modifiers into Moo/Mouse/Moose classes, pay attention to load order:
use Moose;use Kavorka -all; # ok
If you do it this way, Moose's
before
,after
, andaround
keywords will stomp on top of Kavorka's...use Kavorka -all;use Moose; # STOMP, STOMP, STOMP! :-(
This can lead to delightfully hard to debug errors.
BUGS
If seeing test failures on threaded Perl 5.21+, it may be a bug inDevel::CallParser 0.002. Try installingAlt::Devel::CallParser::ButWorking.
Please report any other bugs tohttp://rt.cpan.org/Dist/Display.html?Queue=Kavorka.
SUPPORT
IRC: support is available through in the#moops channel onirc.perl.org.
SEE ALSO
Inspirations:http://perlcabal.org/syn/S06.html,Function::Parameters,Method::Signatures.
http://en.wikipedia.org/wiki/The_Conversion_(Seinfeld).
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 shellinstall Kavorka
For more information on module installation, please visitthe detailed CPAN module installation guide.