Help for this page

Select Code to Download


  1. or download this
       use Types::Common::Numeric qw(PositiveInt);
       
       has user_id => (
          is   => 'ro',
          isa  => PositiveInt,
       );
    
  2. or download this
       package MyApp::Types {
          use Type::Library
             -base,
    ...
          
          ...;
       }
    
  3. or download this
       declare User, as InstanceOf['MyApp::User'];
       
       coerce User,
    ...
       
       coerce UserId,
          from User, via { $_->user_id };
    
  4. or download this
       package MyApp::Types {
          use Type::Library -base;
          use Type::Utils (); # don't import any keywords
    ...
          
          __PACKAGE__->make_immutable;
       }
    
  5. or download this
       # Imagine this is some code in a class...
       #
       
    ...
          isa    => UserId->plus_coercions(Str, sub { ... }),
          coerce => 1,
       );