shift;
my $pkg = caller();
+ # we should never export to main
+ return if $pkg eq 'main';
+
Moose::Util::TypeConstraints->import($pkg);
my $meta;
});
$meta->alias_method('after' => subname 'Moose::after' => sub {
my $code = pop @_;
- $meta->add_after_method_modifier($_, $code) for @_;
+ $meta->add_after_method_modifier($_, $code) for @_;
});
$meta->alias_method('around' => subname 'Moose::around' => sub {
my $code = pop @_;
- $meta->add_around_method_modifier($_, $code) for @_;
+ $meta->add_around_method_modifier($_, $code) for @_;
});
+ # next methods ...
+ $meta->alias_method('next_method' => subname 'Moose::next_method' => sub {
+ my $method_name = (split '::' => (caller(1))[3])[-1];
+ my $next_method = $meta->find_next_method_by_name($method_name);
+ (defined $next_method)
+ || confess "Could not find next-method for '$method_name'";
+ $next_method->(@_);
+ });
+
# make sure they inherit from Moose::Object
$meta->superclasses('Moose::Object')
unless $meta->superclasses();
my ($super_meta) = $metaclass->superclasses();
my ($super_mixin) = $mixin->superclasses();
($super_meta->isa($super_mixin))
- || confess "The superclass ($super_meta) must extend a subclass of the superclass of the mixin ($super_mixin)"
+ || confess "The superclass ($super_meta) must extend a subclass of the " .
+ "superclass of the mixin ($super_mixin)"
if defined $super_mixin && defined $super_meta;
+ # check for conflicts here ...
+
+ $metaclass->has_attribute($_)
+ && confess "Attribute conflict ($_)"
+ foreach $mixin->get_attribute_list;
+
+ foreach my $method_name ($mixin->get_method_list) {
+ # skip meta, cause everyone has that :)
+ next if $method_name =~ /meta/;
+ $metaclass->has_method($method_name) && confess "Method conflict ($method_name)";
+ }
+
# collect all the attributes
# and clone them so they can
- # associate with the new class
- my @attributes = map {
- $mixin->get_attribute($_)->clone()
- } $mixin->get_attribute_list;
-
- my %methods = map {
- my $method = $mixin->get_method($_);
- # we want to ignore accessors since
- # they will be created with the attrs
- (blessed($method) && $method->isa('Class::MOP::Attribute::Accessor'))
- ? () : ($_ => $method)
- } $mixin->get_method_list;
-
- # NOTE:
- # I assume that locally defined methods
- # and attributes get precedence over those
- # from the mixin.
-
+ # associate with the new class
# add all the attributes in ....
- foreach my $attr (@attributes) {
- $metaclass->add_attribute($attr)
- unless $metaclass->has_attribute($attr->name);
- }
+ foreach my $attr ($mixin->get_attribute_list) {
+ $metaclass->add_attribute(
+ $mixin->get_attribute($attr)->clone()
+ );
+ }
# add all the methods in ....
- foreach my $method_name (keys %methods) {
- $metaclass->alias_method($method_name => $methods{$method_name})
- unless $metaclass->has_method($method_name);
+ foreach my $method_name ($mixin->get_method_list) {
+ # no need to mess with meta
+ next if $method_name eq 'meta';
+ my $method = $mixin->get_method($method_name);
+ # and ignore accessors, the
+ # attributes take care of that
+ next if blessed($method) && $method->isa('Class::MOP::Attribute::Accessor');
+ $metaclass->alias_method($method_name => $method);
}
}