diff options
author | matthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2008-01-25 04:19:52 +0000 |
---|---|---|
committer | matthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2008-01-25 04:19:52 +0000 |
commit | 9b2f40541c4439bbc5829d9f131f558b56b58567 (patch) | |
tree | 93b7e642306cc86de86a68ad5690244811ed8431 /lib | |
parent | fd86f68125ddf7cd521943242a0505c12826ae79 (diff) | |
download | reaction-9b2f40541c4439bbc5829d9f131f558b56b58567.tar.gz reaction-9b2f40541c4439bbc5829d9f131f558b56b58567.zip |
clean up implements implementation by providing an add_method_to_target method in Reaction::Class that Reaction::Role can override
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Reaction/Class.pm | 7 | ||||
-rw-r--r-- | lib/Reaction/Role.pm | 15 |
2 files changed, 15 insertions, 7 deletions
diff --git a/lib/Reaction/Class.pm b/lib/Reaction/Class.pm index b3cf253..7813f48 100644 --- a/lib/Reaction/Class.pm +++ b/lib/Reaction/Class.pm @@ -168,7 +168,7 @@ sub setup_and_cleanup { eval "package ${package}; no $unimport_class;"; confess "$unimport_class unimport from ${package} failed: $@" if $@; foreach my $m (@methods) { - $package->meta->add_method(@$m); + $self->add_method_to_target($package, $m); } foreach my $a (@apply_after) { my $call = shift(@$a); @@ -176,6 +176,11 @@ sub setup_and_cleanup { } } +sub add_method_to_target { + my ($self, $target, $method) = @_; + $target->meta->add_method(@$method); +} + sub delayed_methods { return (qw/has with extends before after around override augment/); } diff --git a/lib/Reaction/Role.pm b/lib/Reaction/Role.pm index ea5b948..f5e89b5 100644 --- a/lib/Reaction/Role.pm +++ b/lib/Reaction/Role.pm @@ -4,10 +4,8 @@ use Moose::Role (); use Reaction::ClassExporter; use Reaction::Class; use Moose::Meta::Class; + #TODO: review for Reaction::Object switch / Reaction::Meta::Class -*Moose::Meta::Role::add_method = sub { - Moose::Meta::Class->can("add_method")->(@_); -}; class Role which { @@ -18,11 +16,16 @@ class Role which { $exports{role} = sub { $self->do_role_sub($package, @_); }; return %exports; }; - + override next_import_package => sub { 'Moose::Role' }; - + override default_base => sub { () }; + override add_method_to_target => sub { + my ($self, $target, $method) = @_; + $target->meta->alias_method(@$method); + }; + implements do_role_sub => as { my ($self, $package, $role, $which, $setup) = @_; confess "Invalid role declaration, should be: role Role which { ... }" @@ -31,7 +34,7 @@ class Role which { }; }; - + 1; =head1 NAME |