files/perl/possible-around-bug.pl

Plain text | Download

  1. package SuperTest;
  2. use Moose;
  3.  
  4. #==============================================================================
  5. package Sugar;
  6. use Moose;
  7. use Moose::Exporter;
  8.  
  9. Moose::Exporter->setup_import_methods(
  10.     with_meta => [qw/ test_with_meta /],
  11.     also => 'Moose',
  12. );
  13.  
  14. sub test_with_meta {
  15.     warn "test_with_meta: ", join "|", @_;
  16. }
  17.  
  18. sub init_meta {
  19.     shift;
  20.     my %options = @_;
  21.  
  22.     Moose->init_meta(%options);
  23.  
  24.     # it works as expected with SuperTest, but not with Catalyst::Controller
  25.     $options{'for_class'}->meta->superclasses(qw/Catalyst::Controller/);
  26.     #$options{'for_class'}->meta->superclasses(qw/SuperTest/);
  27.  
  28.     warn "init_meta: ", $options{'for_class'}->meta;
  29.  
  30.     return $options{'for_class'}->meta;
  31. }
  32.  
  33. #==============================================================================
  34. package Class;
  35.  
  36. Sugar->import;
  37. warn "Class->meta: ", Class->meta;
  38.  
  39. test_with_meta('42');
  40. has(test_attr => ( is => 'rw' ));
  41. sub test_method { return join '|', @_ }
  42. around(test_method => sub {});
  43.  
  44. warn "after around: ", Class->meta;
  45.  
  46. __DATA__
  47. #===========================
  48. # output from warn messages:
  49. #===========================
  50. init_meta: Class::MOP::Class::__ANON__::SERIAL::5=HASH(0x1567888) at possible-around-bug.pl line 28.
  51. Class->meta: Class::MOP::Class::__ANON__::SERIAL::5=HASH(0x1567888) at possible-around-bug.pl line 37.
  52. test_with_meta: Class::MOP::Class::__ANON__::SERIAL::5=HASH(0x1567888)|42 at possible-around-bug.pl line 15.
  53. after around: Class::MOP::Class::__ANON__::SERIAL::5=HASH(0x1aef4e8) at possible-around-bug.pl line 44.
  54. # why is the meta object changed after sugar?