Closed danschmidt5189 closed 7 years ago
I would like to see this as well.
A simpler example...
use Function::Parameters {
pair_function => { defaults => 'function_strict', shift => [qw($x $y)] }
};
pair_function swap {
return ($y, $x);
}
pair_function multiply {
return $x * $y;
}
pair_function marry {
say "I now pronounce $x and $y husband and wife!";
}
This can be done in Kavorka. Probably needs to be made easier though.
use v5.14;
use warnings;
use Kavorka ();
# This would typically be in an external file.
BEGIN {
package My::Function::Pair;
use Moo;
with 'Kavorka::Sub';
sub default_invocant {
require Kavorka::Parameter;
return (
'Kavorka::Parameter'->new(name => '$x', traits => { invocant => 1 }),
'Kavorka::Parameter'->new(name => '$y', traits => { invocant => 1 }),
);
}
};
use Kavorka '-default', pair_function => { implementation => 'My::Function::Pair' };
# This function uses $x and $y defined above.
pair_function marry {
say "I now pronounce $x and $y husband and wife!";
say for @_;
}
marry("Bob", "Alice", "Those two were shifted off.");
# This one overrides $x and $y using its own variable names.
pair_function marry2 ($husband, $wife: ...) {
say "I now pronounce $husband and $wife husband and wife!";
say for @_;
}
marry2("Dave", "Carol", "Those two were shifted off.");
This is now possible with version 2 (already released to CPAN).
It would be nice if F::P offered a shortcut for working with Moose's
around
modifier, e.g.:(Right now you're only able to shift off a single argument.)