develooper Front page | perl.moose | Postings from May 2011

Possible Moose::Exporter bug?

Thread Next
From:
Ben Tilly
Date:
May 3, 2011 13:59
Subject:
Possible Moose::Exporter bug?
Message ID:
BANLkTi=D8CMFvEv8d_W=GBiXgjZJOeYdrw@mail.gmail.com
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.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About