NAME
Sub::Meta::Parameters - meta information about parameters
SYNOPSIS
use Sub::Meta::Parameters;
my $p1 = Sub::Meta::Parameters->new(
args => ['Str']
);
$p1->invocant; # => undef;
$p1->invocants; # => [];
$p1->positional; # => [Sub::Meta::Param->new('Str')]
$p1->positional_required; # => [Sub::Meta::Param->new('Str')]
$p1->positional_optional; # => []
$p1->named; # => []
$p1->named_required; # => []
$p1->named_optional; # => []
$p1->nshift; # => 0
$p1->slurpy; # => 0
$p1->args_min; # => 1
$p1->args_max; # => 1
my $x = Sub::Meta::Param->new({ type => 'Int', name => '$x', named => 1 });
my $y = Sub::Meta::Param->new({ type => 'Int', name => '$y', named => 1 });
my $p2 = Sub::Meta::Parameters->new(
nshift => 1,
args => [
'ClassName', $x, $y
]
);
$p2->invocant; # => Sub::Meta::Param->new('ClassName');
$p2->invocants; # => [Sub::Meta::Param->new('ClassName')];
$p2->positional; # => []
$p2->positional_required; # => []
$p2->positional_optional; # => []
$p2->named; # => [$x, $y]
$p2->named_required; # => [$x, $y]
$p2->named_optional; # => []
$p2->nshift; # => 1
$p2->slurpy; # => 0
$p2->args_min; # => 5
$p2->args_max; # => 0+'Inf'
METHODS
new
Constructor of Sub::Meta::Parameters
.
my $p = Sub::Meta::Parameters->new(
args => ['Str'], # required. arguments
nshift => 0, # optional. number of shift arguments
slurpy => 0, # optional. whether get all rest arguments
);
args -> ArrayRef
Subroutine arguments.
set_args(LIST|ArrayRef)
Setter for subroutine arguments. An element can be an argument of Sub::Meta::Param
or any object which has positional
,named
,required
and optional
methods.
nshift -> NonNegativeInt
Number of shift arguments.
set_nshift(NonNegativeInt)
Setter for nshift. For example, it is assumed that 1 is specified in the case of methods, and 0 is specified in the case of normal functions.
slurpy -> Bool
A boolean whether get all rest arguments.
set_slurpy(Bool)
Setter for slurpy.
positional -> ArrayRef.
Returns an arrayref of parameter objects for the positional arguments.
positional_required -> ArrayRef
Returns an arrayref of parameter objects for the required positional arguments.
positional_optional -> ArrayRef
Returns an arrayref of parameter objects for the optional positional arguments.
named
Returns an arrayref of parameter objects for the named arguments.
named_required
Returns an arrayref of parameter objects for the required named arguments.
named_optional
Returns an arrayref of parameter objects for the optional named arguments.
invocant
First element of invocants.
invocants -> ArrayRef
Returns an arrayref of parameter objects for the variables into which initial arguments are shifted automatically. This will usually return () for normal functions and ('$self') for methods.
args_min -> NonNegativeInt
Returns the minimum number of required arguments.
This is computed as follows: Invocants and required positional parameters count 1 each. Optional parameters don't count. Required named parameters count 2 each (key + value). Slurpy parameters don't count either because they accept empty lists.
args_max -> NonNegativeInt|Inf
Returns the maximum number of arguments.
This is computed as follows: If there are any named or slurpy parameters, the result is Inf. Otherwise the result is the number of all invocants and positional parameters.
LICENSE
Copyright (C) kfly8.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
kfly8 <kfly@cpan.org>