Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Factor out apply modifier into common code
  • Loading branch information
bobtfish committed Sep 18, 2009
1 parent c2e11ea commit c2bf7cb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
14 changes: 0 additions & 14 deletions lib/MooseX/MethodAttributes/Role/Meta/Role.pm
Expand Up @@ -74,20 +74,6 @@ around method_metaclass => sub {
)->name();
};

around 'apply' => sub {
my ($orig, $self, $thing, %opts) = @_;
die("MooseX::MethodAttributes does not currently support method exclusion or aliasing.")
if ($opts{alias} or $opts{exclude});
$thing = $self->_apply_metaclasses($thing);
my $ret = $self->$orig($thing, %opts);
$self->_copy_attributes($thing);
return $ret;
};

#requires qw/
# _method_attribute_list
# _method_attribute_map
#/;

sub _copy_attributes {
my ($self, $thing) = @_;
Expand Down
16 changes: 16 additions & 0 deletions lib/MooseX/MethodAttributes/Role/Meta/Role/Application.pm
Expand Up @@ -7,6 +7,22 @@ use MooseX::MethodAttributes ();
use MooseX::MethodAttributes::Role ();
use namespace::clean -except => 'meta';

requires qw/
_copy_attributes
apply
/;

around 'apply' => sub {
my ($orig, $self, $thing, %opts) = @_;
$thing = $self->_apply_metaclasses($thing);

my $ret = $self->$orig($thing, %opts);

$self->_copy_attributes($thing);

return $ret;
};

sub _apply_metaclasses {
my ($self, $thing) = @_;
if ($thing->isa('Moose::Meta::Class')) {
Expand Down
Expand Up @@ -5,18 +5,6 @@ use namespace::clean -except => 'meta';

with 'MooseX::MethodAttributes::Role::Meta::Role::Application';

around 'apply' => sub {
my ($orig, $self, $thing, %opts) = @_;
$thing = $self->_apply_metaclasses($thing);

my $ret = $self->$orig($thing);

$self->_copy_attributes($thing);

return $ret;

};

sub _copy_attributes {
my ($self, $thing) = @_;
for my $role (@{ $self->get_roles }) {
Expand Down

0 comments on commit c2bf7cb

Please sign in to comment.