moose-test.pl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env perl
  2. # while compiling out of memory
  3. # endless recursion with B::HV::save
  4. # 7 0x521293e4 in Perl_pp_entersub () at pp_hot.c:2806
  5. # GVGV::GV = 0x14c3ad0 "B::HV" :: "save", DEPTH = 44817
  6. {
  7. package Foo::Moose;
  8. use Moose;
  9. has bar => (is => 'rw');
  10. # __PACKAGE__->meta->make_immutable;
  11. }
  12. {
  13. package TypedFoo::Moose;
  14. use Moose;
  15. has bar => (is => 'rw', isa => 'Int');
  16. # __PACKAGE__->meta->make_immutable;
  17. }
  18. {
  19. package Foo::Manual;
  20. sub new { bless {} => shift }
  21. sub bar {
  22. my $self = shift;
  23. return $self->{bar} unless @_;
  24. $self->{bar} = shift;
  25. }
  26. }
  27. my $foo1 = Foo::Moose->new;
  28. sub moose {
  29. $foo1->bar(32);
  30. my $x = $foo1->bar;
  31. }
  32. my $foo2 = TypedFoo::Moose->new;
  33. sub moosetyped {
  34. $foo2->bar(32);
  35. my $x = $foo2->bar;
  36. }
  37. my $foo = Foo::Manual->new;
  38. sub manual {
  39. $foo->bar(32);
  40. my $x = $foo->bar;
  41. }
  42. use Benchmark 'timethese';
  43. print "Testing Perl $]\n";
  44. timethese(
  45. 50_000,
  46. {
  47. moose => \&moose,
  48. moosetyped => \&moosetyped,
  49. manual => \&manual,
  50. }
  51. );