Guest User

Untitled

a guest
Jun 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Benchmark 'cmpthese';
  6. use Method::Signatures ':DEBUG';
  7.  
  8. sub sub_empty { }
  9. func func_empty {}
  10.  
  11. sub sub_empty_method { my $self = shift; }
  12. method meth_empty_method {}
  13.  
  14.  
  15. sub sub_one_arg_method {
  16. my ($self, $xpto) = @_;
  17.  
  18. die unless $xpto == 42;
  19. }
  20.  
  21. sub sub_one_arg_method_opt {
  22. my $self = shift;
  23. my $xpto = $_[0];
  24.  
  25. die unless $xpto == 42;
  26. }
  27.  
  28. method meth_one_arg_method_opt ($xpto?) { die unless $xpto == 42 }
  29. method meth_one_arg_method ($xpto) { die unless $xpto == 42 }
  30.  
  31. cmpthese(
  32. -2,
  33. { 'sub_empty' => sub { sub_empty() },
  34. 'func_empty' => sub { func_empty() },
  35.  
  36. 'sub_empty_method' => sub { main->sub_empty_method() },
  37. 'meth_empty_method' => sub { main->meth_empty_method() },
  38.  
  39. 'sub_one_arg_method' => sub { main->sub_one_arg_method(42) },
  40. 'sub_one_arg_method_opt' => sub { main->sub_one_arg_method_opt(42) },
  41. 'meth_one_arg_method' => sub { main->meth_one_arg_method(42) },
  42. 'meth_one_arg_method_opt' => sub { main->meth_one_arg_method(42) },
  43. }
  44. );
Add Comment
Please, Sign In to add comment