files/perl/possible-around-bug.pl
Plain text
| Download
- package SuperTest;
- use Moose;
-
- #==============================================================================
- package Sugar;
- use Moose;
- use Moose::Exporter;
-
- Moose::Exporter->setup_import_methods(
- with_meta => [qw/ test_with_meta /],
- also => 'Moose',
- );
-
- sub test_with_meta {
- warn "test_with_meta: ", join "|", @_;
- }
-
- sub init_meta {
- shift;
- my %options = @_;
-
- Moose->init_meta(%options);
-
- # it works as expected with SuperTest, but not with Catalyst::Controller
- $options{'for_class'}->meta->superclasses(qw/Catalyst::Controller/);
- #$options{'for_class'}->meta->superclasses(qw/SuperTest/);
-
- warn "init_meta: ", $options{'for_class'}->meta;
-
- return $options{'for_class'}->meta;
- }
-
- #==============================================================================
- package Class;
-
- Sugar->import;
- warn "Class->meta: ", Class->meta;
-
- test_with_meta('42');
- has(test_attr => ( is => 'rw' ));
- sub test_method { return join '|', @_ }
- around(test_method => sub {});
-
- warn "after around: ", Class->meta;
-
- __DATA__
- #===========================
- # output from warn messages:
- #===========================
- init_meta: Class::MOP::Class::__ANON__::SERIAL::5=HASH(0x1567888) at possible-around-bug.pl line 28.
- Class->meta: Class::MOP::Class::__ANON__::SERIAL::5=HASH(0x1567888) at possible-around-bug.pl line 37.
- test_with_meta: Class::MOP::Class::__ANON__::SERIAL::5=HASH(0x1567888)|42 at possible-around-bug.pl line 15.
- after around: Class::MOP::Class::__ANON__::SERIAL::5=HASH(0x1aef4e8) at possible-around-bug.pl line 44.
- # why is the meta object changed after sugar?