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

method name() => Str

variable name, e.g. $msg, @list.

has_name

method has_name() => Bool

Whether Sub::Meta::Param has name or not.

set_name($name)

method set_name(Str $name) => $self

Setter for name.

type

method type() => Any

Any type constraints, e.g. Str.

has_type

method has_type() => Bool

Whether Sub::Meta::Param has type or not.

set_type($type)

method set_type(Any $type) => $self

Setter for type.

isa_

The alias of type

set_isa($type)

The alias of set_type

default

method default() => Any

default value, e.g. "HELLO", sub { ... }

has_default

method has_default() => Bool

Whether Sub::Meta::Param has default or not.

set_default($default)

method set_default(Any $default) => $self

Setter for default.

coerce

method coerce() => Any

A boolean value indicating whether to coerce. Default to false.

has_coerce

method has_coerce() => Bool

Whether Sub::Meta::Param has coerce or not.

set_coerce($coerce)

method set_coerce(Any $coerce) => $self

Setter for coerce.

optional

method optional() => Bool

A boolean value indicating whether to optional. Default to false. This boolean is the opposite of required.

set_optional($bool=true)

method set_optional(Bool $bool=true) => $self

Setter for optional.

required

method required() => Bool

A boolean value indicating whether to required. Default to true. This boolean is the opposite of optional.

set_required($bool=true)

method set_required(Bool $bool=true) => $self

Setter for required.

named

method named() => Bool

A boolean value indicating whether to named arguments. Default to false. This boolean is the opposite of positional.

set_named($bool=true)

method set_named(Bool $bool=true) => $self

Setter for named.

positional

method positional() => Bool

A boolean value indicating whether to positional arguments. Default to true. This boolean is the opposite of positional.

set_positional($bool=true)

method set_positional(Bool $bool=true) => $self

Setter for positional.

invocant

method invocant() => Bool

A boolean value indicating whether to be invocant. Default to false.

set_invocant($bool=true)

method set_invocant(Bool $bool=true) => $self

Setter for invocant.

METHODS

is_same_interface($other_meta)

method is_same_interface(InstanceOf[Sub::Meta::Param] $other_meta) => Bool

A boolean value indicating whether Sub::Meta::Param object is same or not. Specifically, check whether name, type, optional and named are equal.

is_relaxed_same_interface($other_meta)

method is_relaxed_same_interface(InstanceOf[Sub::Meta::Param] $other_meta) => Bool

A boolean value indicating whether Sub::Meta::Param object is same or not. Specifically, check whether name, type, optional and named are satisfy the condition of $self side:

my $meta = Sub::Meta::Param->new;
my $other = Sub::Meta::Param->new(name => '$a');
$meta->is_same_interface($other); # NG
$meta->is_relaxed_same_interface($other); # OK. The reason is that $meta does not specify the name.

is_same_interface_inlined($other_meta_inlined)

method is_same_interface_inlined(InstanceOf[Sub::Meta::Param] $other_meta) => Str

Returns inlined is_same_interface string.

is_relaxed_same_interface_inlined($other_meta_inlined)

method is_relaxed_same_interface_inlined(InstanceOf[Sub::Meta::Param] $other_meta) => Str

Returns inlined is_relaxed_same_interface string.

display

method display() => Str

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

Sub::Meta::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>