- or download this
sub foo (
...
@rest # slurp up any remaining arguments
) { .... }
- or download this
sub f ($x :foo, $y :bar(baz) bar2(baz2), ...) { ... }
- or download this
my $x :foo;
my $y :bar(baz) bar2(baz2);
- or download this
my ($x, $y) :foo(foo_arg) :bar(bar_arg);
- or download this
use attributes ();
my ($x,$y);
attributes->import(, __PACKAGE__, \$x, "foo(foo_arg)", "bar(bar_ar
+g)");
attributes->import(, __PACKAGE__, \$y, "foo(foo_arg)", "bar(bar_ar
+g)");
- or download this
sub foo (
$pos1, # positional parameter; consumes 1 arg
...
:$name2, # named parameter, consumes ("name2", value) arg
+pair
@rest, # consumes all unrecognised name/value pairs
) { ... }
- or download this
?$x peek ahead to the next arg
??$x peek ahead and see if there is a next arg
?@a peek ahead and copy all remaining args
?%h peek ahead and copy all remaining key/val arg pairs
?{ code } execute some code without consuming any args
- or download this
sub foo {
# the lexical vars $a, @b and %c are aliased to the things poi
+nted
...
*%g
) { ... }
- or download this
sub f(
$self isa Foo::Bar, # croak unless $self->isa('Foo
+::Bar');
...
$f is \@, # croak unless array ref
$aref as ref ? $_ : [ $_ ] # coercions: maybe modify the
+param
) { ...};
- or download this
sub f (Int $x) { ... }
- or download this
sub f ($x) { croak unless
defined $x
...
&& $x =~ /\A-?[0-9]+\Z/;
....;
}
- or download this
sub f (Some::Arbitrary::Class $x) { ... }
- or download this
sub f ($x) { croak unless
defined $x
...
&& $x->isa(Some::Arbitrary::Class);
...;
}
- or download this
sub f ($x where * < 10*$y) { ... }
- or download this
sub f($a, $b, $c, ... ) { BODY; }
- or download this
sub f {
my $a = ....;
...
....;
BODY;
}