fixes for the applied_attribute stuff in moose 2
Jesse Luehrs [Fri, 4 Mar 2011 19:31:34 +0000 (13:31 -0600)]
lib/Reaction/Class.pm
lib/Reaction/Meta/Role.pm [new file with mode: 0644]
lib/Reaction/Role.pm
lib/Reaction/Role/Meta/Role.pm [new file with mode: 0644]
lib/Reaction/Role/Parameterized.pm [new file with mode: 0644]
lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm
lib/Reaction/UI/ViewPort/Field/Role/Mutable/Simple.pm

index f2f8c3a..7077522 100644 (file)
@@ -221,10 +221,10 @@ sub import {
   my $self = shift;
   my $pkg = caller;
   my @args = @_;
-  &strict::import;
-  &warnings::import;
+  strict->import;
+  warnings->import;
   $self->do_import($pkg, \@args);
-  goto &{$self->next_import};
+  goto &{$self->next_import} if $self->next_import;
 }
 
 sub next_import {
diff --git a/lib/Reaction/Meta/Role.pm b/lib/Reaction/Meta/Role.pm
new file mode 100644 (file)
index 0000000..b9bbe61
--- /dev/null
@@ -0,0 +1,14 @@
+package Reaction::Meta::Role;
+
+use Moose;
+use Reaction::Meta::Attribute;
+
+extends 'Moose::Meta::Role';
+
+with 'Reaction::Role::Meta::Role';
+
+no Moose;
+
+__PACKAGE__->meta->make_immutable;
+
+1;
index 7da166f..c2f16f4 100644 (file)
@@ -25,6 +25,15 @@ override add_method_to_target => sub {
   my ($self, $target, $method) = @_;
   $target->meta->add_method(@$method);
 };
+override next_import => sub {
+  my ($self) = @_;
+  my $import = super;
+  # ugh
+  return sub {
+      push @_, '-metaclass' => 'Reaction::Meta::Role';
+      goto $import;
+  };
+};
 sub do_role_sub {
   my ($self, $package, $role, $which, $setup) = @_;
   confess "Invalid role declaration, should be: role Role which { ... }"
diff --git a/lib/Reaction/Role/Meta/Role.pm b/lib/Reaction/Role/Meta/Role.pm
new file mode 100644 (file)
index 0000000..8708abb
--- /dev/null
@@ -0,0 +1,12 @@
+package Reaction::Role::Meta::Role;
+
+use Moose::Role;
+
+around initialize => sub {
+    my $super = shift;
+    my $class = shift;
+    my $pkg   = shift;
+    $super->($class, $pkg, 'applied_attribute_metaclass' => 'Reaction::Meta::Attribute', @_ );
+};
+
+1;
diff --git a/lib/Reaction/Role/Parameterized.pm b/lib/Reaction/Role/Parameterized.pm
new file mode 100644 (file)
index 0000000..98074cd
--- /dev/null
@@ -0,0 +1,68 @@
+package Reaction::Role::Parameterized;
+
+use MooseX::Role::Parameterized ();
+use Reaction::ClassExporter;
+use Reaction::Class;
+use Moose::Meta::Class;
+
+use namespace::clean -except => [ qw(meta) ];
+
+override exports_for_package => sub {
+  my ($self, $package) = @_;
+  my %exports = $self->SUPER::exports_for_package($package);
+  delete $exports{class};
+  return %exports;
+};
+
+override default_base => sub { () };
+
+override exporter_for_package => sub {
+    my ($self) = @_;
+    my ($import) = Moose::Exporter->build_import_methods(
+        also        => ['MooseX::Role::Parameterized'],
+        with_caller => ['role'],
+    );
+    $import;
+};
+
+override next_import => sub { };
+
+sub role (&) {
+    my $caller = shift;
+    my ($code) = @_;
+    &MooseX::Role::Parameterized::role($caller, sub {
+        my ($p, %args) = @_;
+        $args{operating_on} = Moose::Util::MetaRole::apply_metaroles(
+            for            => $args{operating_on}->name,
+            role_metaroles => {
+                applied_attribute => ['Reaction::Role::Meta::Attribute'],
+            },
+        ) if Moose->VERSION >= 1.9900;
+        $code->($p, %args);
+    });
+}
+
+__PACKAGE__->meta->make_immutable;
+
+
+1;
+
+=head1 NAME
+
+Reaction::Role
+
+=head1 DESCRIPTION
+
+=head1 SEE ALSO
+
+L<Moose::Role>
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut
index 6e7e90e..c5176eb 100644 (file)
@@ -1,6 +1,6 @@
 package Reaction::UI::ViewPort::Field::Role::Mutable;
 
-use MooseX::Role::Parameterized;
+use Reaction::Role::Parameterized;
 
 use aliased 'Reaction::InterfaceModel::Action';
 use aliased 'Reaction::Meta::InterfaceModel::Action::ParameterAttribute';
index 0295b82..758caf5 100644 (file)
@@ -1,6 +1,6 @@
 package Reaction::UI::ViewPort::Field::Role::Mutable::Simple;
 
-use MooseX::Role::Parameterized;
+use Reaction::Role::Parameterized;
 
 use aliased 'Reaction::UI::ViewPort::Field::Role::Mutable';