use Function::Parameters;
fun foo($x, $y, $z = 5) {
return $x + $y + $z;
}
print foo(1, 2), "\n";
method bar($label, $n) {
return "$label: " . ($n * $self->scale);
}
use Function::Parameters;
fun foo($x, $y = $x * 100, $z = []) {
...
}
method bar($x = $self->default_x, $y = $self->default_y) {
...
}
package Collection;
use strict;
use warnings;
sub values { ... }
my %hash;
my @vals = values %hash;
package Collection;
use Function::Parameters;
use strict;
use warnings;
method values() { ... }
my %hash;
my @vals = values %hash;
use Function::Parameters;
fun create_point(:$x, :$y, :$color) {
print "creating a $color point at ($x, $y)\n";
}
create_point(
color => "red",
x => 10,
y => 5,
);
use Function::Parameters;
fun create_point(:$x, :$y, :$color, %rest) {
print "creating a $color point at ($x, $y)\n";
}
create_point(
flavor => "chocolate",
color => "red",
x => 10,
y => 5,
);
package Derived {
use Function::Parameters qw(:std :modifiers);
use Moo;
extends 'Base';
has 'go_big' => (
is => 'ro',
);
around size() {
return $self->$orig() * 2 if $self->go_big;
return $self->$orig();
}
}
use Function::Parameters;
use Types::Standard qw(Int Str ArrayRef HashRef Object);
use MooseX::Types::Moose qw(Int Str ArrayRef HashRef Object);
fun foo(
Int $n,
Str $name,
HashRef[ ArrayRef[ Object ] ] $mapping,
) { ... }
use Function::Parameters;
use Types::Standard qw(Int Str ArrayRef HashRef Object);
use MooseX::Types::Moose qw(Int Str ArrayRef HashRef Object);
method foo(
Int $n,
Str $name,
HashRef[ ArrayRef[ Object ] ] $mapping,
) { ... }
use Function::Parameters;
use MooseX::Types::Moose qw(Int Str ArrayRef HashRef Object);
fun foo(
Int $n,
Str $name,
HashRef[ ArrayRef[ Object ] ] $mapping,
) { ... }
use utf8;
use Function::Parameters { 'λ' => 'function' };
my $fac = λ ($n) { $n < 2 ? 1 : $n * __SUB__->($n - 1) };
use Function::Parameters;
fun foo($man, $plan, $canal, @panama) { ... }
my $meta = Function::Parameters::info \&foo;
say $meta->args_min;
say $meta->args_max;