Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Exploring Type::Tiny Part 7: Creating a Type Library with Type::Library

by tobyink (Canon)
on Jan 28, 2019 at 14:52 UTC ( #1229071=CUFP: print w/replies, xml ) Need Help??

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,
       );
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://1229071]
Approved by marto
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2019-10-16 22:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?