Re: Possible Moose::Exporter bug?

[email protected] (Jesse Luehrs)
Newsgroups perl.moose
Message-ID <[email protected]>
On Tue, May 03, 2011 at 01:59:33PM -0700, Ben Tilly wrote:
> According to the documentation for Moose::Exporter I would expect the
> following two modules to be equivalent:
> 
>   package TestMooseExporter;
>   use Moose ();
>   use Moose::Exporter;
> 
>   Moose::Exporter->setup_import_methods(
>       with_meta => [qw(
>           hello
>       )],
>       also => "Moose",
>       base_class_roles => ["TestRole"],
>   );
> 
>   sub hello {
>       my $meta = shift;
>       print "Hello, $meta->{package}\n";
>   }
> 
>   1;
> 
> and
> 
>   package TestMooseExporter;
>   use Moose ();
>   use Moose::Exporter;
>   use Moose::Util::MetaRole;
> 
>   Moose::Exporter->setup_import_methods(
>       with_meta => [qw(
>           hello
>       )],
>       also => "Moose",
>   );
> 
>   sub hello {
>       my $meta = shift;
>       print "Hello, $meta->{package}\n";
>   }
> 
>   sub init_meta {
>       shift;
>       my %args = @_;
>       Moose->init_meta(%args);
>       Moose::Util::MetaRole::apply_base_class_roles(
>           for   => $args{for_class},
>           roles => ['TestRole'],
>       );
> 
>       return $args{for_class}->meta;
>   }
> 
>   1;
> 
> But they are not.  The second forces TestRole to be applied to any
> class that uses the module, and the first does not.
> 
> Looking inside of Moose::Exporter::_make_init_meta I see the following
> section of code that should set up the role:
> 
>         Moose::Util::MetaRole::apply_base_class_roles(
>             for_class => $options{for_class},
>             %base_class_roles,
>             )
>             if Class::MOP::class_of( $options{for_class} )
>                 ->isa('Moose::Meta::Class');
> 
> I have no idea why that inline if is there, but it seems to be
> preventing Moose from working like the documentation lead me to expect
> it would.

See http://rt.cpan.org/Public/Bug/Display.html?id=51561. This will
hopefully be fixed soon (maybe by 2.02?), but for right now, you have to
write your own init_meta method if you're doing "also => ['Moose']".

-doy
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.