use feature 'state';
use Type::Params qw( compile compile_named_oo );
use Types::Standard -types;
sub function_with_positional_parameters {
state $check = compile( ArrayRef, Int, Int );
my ( $list, $start, $end ) = $check->( @_ );
my @slice = @{$list}[ $start .. $end ];
return \@slice;
}
sub function_with_named_parameters {
state $check = compile_named_oo( list => ArrayRef, start => Int, end => Int );
my ( $arg ) = $check->( @_ );
my @slice = @{$arg->list}[ $arg->start .. $arg->end ];
return \@slice;
}
####
use Type::Params qw( wrap_subs compile_named_oo );
use Types::Standard -types;
wrap_subs function_with_positional_parameters => [ ArrayRef, Int, Int ];
sub function_with_positional_parameters {
my ( $list, $start, $end ) = @_;
my @slice = @{$list}[ $start .. $end ];
return \@slice;
}
wrap_subs function_with_named_parameters =>
compile_named_oo( list => ArrayRef, start => Int, end => Int );
sub function_with_named_parameters {
my ( $arg ) = @_;
my @slice = @{$arg->list}[ $arg->start .. $arg->end ];
return \@slice;
}
####
use feature 'state';
use Type::Params2;
use Types::Standard -types;
sub function_with_positional_parameters {
state $check = signature(
pos => [ ArrayRef, Int, Int ],
);
my ( $list, $start, $end ) = $check->( @_ );
my @slice = @{$list}[ $start .. $end ];
return \@slice;
}
sub function_with_named_parameters {
state $check = signature(
named => [ list => ArrayRef, start => Int, end => Int ],
);
my ( $arg ) = $check->( @_ );
my @slice = @{$arg->list}[ $arg->start .. $arg->end ];
return \@slice;
}
####
use Type::Params2;
use Types::Standard -types;
signature_for function_with_positional_parameters => (
pos => [ ArrayRef, Int, Int ],
);
sub function_with_positional_parameters {
my ( $list, $start, $end ) = @_;
my @slice = @{$list}[ $start .. $end ];
return \@slice;
}
signature_for function_with_named_parameters => (
named => [ list => ArrayRef, start => Int, end => Int ],
);
sub function_with_named_parameters {
my ( $arg ) = @_;
my @slice = @{$arg->list}[ $arg->start .. $arg->end ];
return \@slice;
}
####
signature_for method_with_named_parameters => (
method => 1,
named => [ list => ArrayRef, start => Int, end => Int ],
);
sub method_with_named_parameters {
my ( $self, $arg ) = @_;
my @slice = @{$arg->list}[ $arg->start .. $arg->end ];
return \@slice;
}