##
use feature qw( state );
use Type::Params qw( compile_named_oo );
use Types::Standard qw( Num );
sub add_numbers {
state $signature = compile_named_oo(
{ head => [ Any ] },
'x' => Num,
'y' => Num,
);
my ( $self, $arg ) = $signature->( @_ );
return $arg->x + $arg->y;
}
####
use feature qw( state );
use Type::Params qw( signature );
use Types::Standard qw( Num );
sub add_numbers {
state $signature = signature(
method => 0,
positional => [ Num, Num ],
);
my ( $x, $y ) = $signature->( @_ );
return $x + $y;
}
####
use feature qw( state );
use Type::Params qw( signature );
use Types::Standard qw( Num );
sub add_numbers {
state $signature = signature(
method => 1,
named => [ 'x' => Num, 'y' => Num ],
);
my ( $self, $arg ) = $signature->( @_ );
return $arg->x + $arg->y;
}
####
use experimental qw( signatures );
use Type::Params qw( signature_for );
use Types::Standard qw( Num );
signature_for add_numbers => (
method => 1,
named => [ 'x' => Num, 'y' => Num ],
);
sub add_numbers ( $self, $arg ) {
return $arg->x + $arg->y;
}
####
use Type::Tiny::Enum Size => [ qw( S M L XL ) ];
####
package Local::TShirt {
use Moose;
use Types::Common -types;
use Type::Tiny::Enum Size => [ qw( S M L XL ) ];
use namespace::autoclean;
has size => (
is => 'ro',
isa => Size,
required => 1,
);
sub price {
my $self = shift;
my $size = $self->size;
if ( $size eq SIZE_XL ) {
return 10.99;
}
elsif ( $size eq SIZE_L ) {
return 9.99;
}
else {
return 8.99;
}
}
}
####
sub post_data ( $url, $data, $ua=undef ) {
use Type::Tiny::Class -lexical, 'HTTP::Tiny';
$ua = HTTPTiny->new unless is_HTTPTiny $ua;
$ua->post( $url, $data );
}
####
use Types::Common -all;
####
use Types::Common qw( signature_for Num NonEmptyStr );
If you have a bleeding-edge Perl installed, you can import functions lexically:
use Types::Common -lexical, -all;
## ##
has lucky_numbers => (
is => 'ro',
isa => ArrayRef[ Num / Any ],
);
####
has output_list => (
is => 'ro',
isa => ArrayRef,
default => sub { [] },
);
####
has output_list => (
is => 'ro',
isa => ArrayRef,
default => ArrayRef->type_default,
);
####
has colour_scheme => (
is => 'ro',
isa => ColourScheme,
default => sub {
my %colours = (
foreground => 'black',
background => 'white',
links => 'blue',
highlight => 'red',
);
return \%colours;
},
);