Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Exploring Type::Tiny Part 1: Using Type::Params for Validating Function Parameters

by tobyink (Canon)
on Jul 30, 2018 at 18:49 UTC ( [id://1219503]=CUFP: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
      sub htmlprint {
        my %arg = @_;
        $arg{file}->printf(
    ...
          $arg{text},
        );
      }
    
  2. or download this
      use Carp qw(croak);
      
      sub htmlprint {
    ...
          $arg{text},
        );
      }
    
  3. or download this
      use Carp qw(croak);
      use Scalar::Util qw(blessed);
      
    ...
          $arg{text},
        );
      }
    
  4. or download this
      use feature qw(state);
      use Type::Params qw(compile_named);
      use Types::Standard qw(FileHandle HasMethods Str);
    ...
          $arg->{text},
        );
      }
    
  5. or download this
      use Type::Params qw(compile_named);
      use Types::Standard qw(FileHandle HasMethods Str);
      
    ...
        
        ...;  # rest of the function goes here
      }
    
  6. or download this
      # will throw an exception because of 'size'
      htmlprint( file => $fh, text => "Hello world", colour => "red", size
    + => 7 );
    
  7. or download this
      use feature qw(state);
      use Type::Params 1.004000 qw(compile_named);
      use Types::Standard qw(FileHandle HasMethods Str);
    ...
        
        ...;  # rest of the function goes here
      }
    
  8. or download this
      use feature qw(state);
      use Type::Params 1.004000 qw(compile_named_oo);
      use Types::Standard qw(FileHandle HasMethods Str);
    ...
          $arg->text,                           # not $arg->{text}
        );
      }
    
  9. or download this
      use feature qw(state);
      use Type::Params 1.004000 qw(compile_named);
      use Types::Standard qw(FileHandle HasMethods Str);
    ...
        
        ...;  # rest of the function goes here
      }
    
  10. or download this
      use feature qw(state);
      use Type::Params 1.004000 qw(compile_named);
      use Types::Standard qw(FileHandle HasMethods Str Object);
    ...
        
        ...;  # rest of the function goes here
      }
    
  11. or download this
      use feature qw(state);
      use Type::Params 1.004000 qw(compile);
      use Types::Standard qw(FileHandle HasMethods Str);
    ...
      
      htmlprint($fh, "Hello world", "red");
      htmlprint($fh, "Hello world");   # defaults to black
    
  12. or download this
      package My::Types {
        use Type::Library -base;
        use Type::Utils -all;
    ...
            return $fh;
          };
      }
    
  13. or download this
      use feature qw(state);
      use Type::Params 1.004000 qw(compile_named);
      use Types::Standard qw(HasMethods Str);
    ...
        
        ...;  # rest of the function goes here
      }
    
  14. or download this
      htmlprint(
        file => "/tmp/out.html",  # will be coerced to a filehandle
        text => "Hello world",
      );
    
  15. or download this
      use feature qw(state);
      use Type::Params 1.004000 qw(compile_named);
      use Types::Standard qw(HasMethods Str);
    ...
        
        ...;  # rest of the function goes here
      }
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (1)
As of 2024-04-19 00:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found