Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by tobyink (Canon)
on Jan 28, 2019 at 14:52 UTC ( [id://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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-04-24 08:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found