NAME
Sub::Meta::Param - element of Sub::Meta::Parameters
SYNOPSIS
use Sub::Meta::Param
# specify all parameters
my $param = Sub::Meta::Param->new(
type => 'Str',
name => '$msg',
default => 'world',
coerce => 0,
optional => 0, # default
named => 0, # default
);
$param->type; # => 'Str'
# omit parameters
my $param = Sub::Meta::Param->new('Str');
$param->type; # => 'Str'
$param->positional; # => !!1
$param->required; # => !!1
METHODS
new
Constructor of Sub::Meta::Param
.
use Types::Standard -types;
Sub::Meta::Param->new({
type => ArrayRef[Int],
required => 1,
positional => 1,
})
ACCESSORS
name
variable name, e.g. $msg
, @list
.
set_name(Str $name)
Setter for name
.
type
Any type constraints, e.g. Str
.
set_type($type)
Setter for type
.
isa_
The alias of type
set_isa($type)
The alias of set_type
default
default value, e.g. "HELLO"
, sub { ... }
set_default($default)
Setter for default
.
coerce
A boolean value indicating whether to coerce. Default to false.
set_coerce($bool)
Setter for coerce
.
optional
A boolean value indicating whether to optional. Default to false. This boolean is the opposite of required
.
set_optional($bool=true)
Setter for optional
.
required
A boolean value indicating whether to required. Default to true. This boolean is the opposite of optional
.
set_required($bool=true)
Setter for required
.
named
A boolean value indicating whether to named arguments. Default to false. This boolean is the opposite of positional
.
set_named($bool=true)
Setter for named
.
positional
A boolean value indicating whether to positional arguments. Default to true. This boolean is the opposite of positional
.
set_positional($bool=true)
Setter for positional
.
invocant
A boolean value indicating whether to be invocant. Default to false.
set_invocant($bool=true)
Setter for invocant
.
METHODS
is_same_interface($other_meta)
A boolean value indicating whether Sub::Meta::Param
object is same or not. Specifically, check whether name
, type
, optional
and named
are equal.
is_same_interface_inlined($other_meta_inlined)
Returns inlined is_same_interface
string.
display
Returns the display of Sub::Meta::Param:
use Sub::Meta::Param;
use Types::Standard qw(Str);
my $meta = Sub::Meta::Param->new(
type => Str,
name => '$message',
);
$meta->display; # 'Str $message'
SEE ALSO
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>