- or download this
use Types::Standard qw(Int);
tie(my @numbers, Int);
push @numbers, 1, 2, 3; # ok
push @numbers, "four"; # dies
- or download this
use Types::Standard qw(Int Num);
my $RoundedInt = Int->plus_coercions( Num, 'int $_' );
...
push @numbers, 1, 2, 3; # ok
push @numbers, 4.2; # rounded to 4
push @numbers, "five"; # dies
- or download this
use Type::Tie qw();
use MooseX::Types::Moose qw(Int);
tie(my @numbers, "Type::Tie::ARRAY", Int);
- or download this
use Type::Tie qw(ttie);
use MooseX::Types::Moose qw(Int);
ttie(my @numbers, Int);
- or download this
use v5.16;
package Foo {
...
my $foo = Foo->new( numbers => [1, 2, 3] );
push @{ $foo->numbers }, "hi"; # this is allowed
- or download this
use v5.16;
package Foo {
...
my $foo = Foo->new( numbers => [1, 2, 3] );
push @{ $foo->numbers }, "hi"; # dies
- or download this
use Types::Standard qw(Int);
use Devel::StrictMode qw(STRICT);
...
tie @array_of_ints, Int if STRICT;
...; # do stuff here