Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  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($_))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement