daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use strict;
  2. use warnings;
  3.  
  4. use Type::Params 'compile', 'Invocant';
  5. use Types::Standard 'InstanceOf', 'Str', 'Int';
  6. use Test::MockObject;
  7. my $mock = Test::MockObject->new();
  8.  
  9. use feature 'state';
  10.  
  11. print foo($mock, 'bar');
  12.  
  13. sub foo {
  14.     state $check = compile( Invocant, Int );
  15.     my ( $self, $id ) = $check->(@_);
  16.     return $id . "_foo\n";
  17. }
  18.  
  19. __END__
  20.  
  21. Dies with error:
  22.  
  23. Value "bar" did not pass type constraint "Int" (in $_[1]) at test.pl line 11
  24.     "Int" is a subtype of "Num"
  25.     "Num" is a subtype of "LaxNum"
  26.     Value "bar" did not pass type constraint "LaxNum" (in $_[1])
  27.     "LaxNum" is defined as: (defined($_) && !ref($_) && Scalar::Util::looks_like_number($_))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top