Help for this page

Select Code to Download


  1. or download this
       use Types::Standard qw(Int);
       
       tie(my @numbers, Int);
       
       push @numbers, 1, 2, 3;     # ok
       push @numbers, "four";      # dies
    
  2. 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
    
  3. or download this
       use Type::Tie qw();
       use MooseX::Types::Moose qw(Int);
       
       tie(my @numbers, "Type::Tie::ARRAY", Int);
    
  4. or download this
       use Type::Tie qw(ttie);
       use MooseX::Types::Moose qw(Int);
       
       ttie(my @numbers, Int);
    
  5. or download this
       use v5.16;
       
       package Foo {
    ...
       my $foo = Foo->new( numbers => [1, 2, 3] );
       
       push @{ $foo->numbers }, "hi";   # this is allowed
    
  6. or download this
       use v5.16;
       
       package Foo {
    ...
       my $foo = Foo->new( numbers => [1, 2, 3] );
       
       push @{ $foo->numbers }, "hi";   # dies
    
  7. or download this
       use Types::Standard qw(Int);
       use Devel::StrictMode qw(STRICT);
       
    ...
       tie @array_of_ints, Int if STRICT;
       
       ...;   # do stuff here