use strict;
use warnings;
+our $VERSION = '0.65';
+$VERSION = eval $VERSION;
+our $AUTHORITY = 'cpan:STEVAN';
+
use List::MoreUtils qw( all );
+my @Classes = qw( constructor_class destructor_class error_class );
+
sub apply_metaclass_roles {
my %options = @_;
my $for = $options{for_class};
- my $meta = _make_new_metaclass( $for, \%options );
+ my %old_classes
+ = map { $_ => $for->meta->$_ } grep { $for->meta->can($_) } @Classes;
- for my $tor_class ( grep { $options{ $_ . '_roles' } }
- qw( constructor_class destructor_class ) ) {
+ my $meta = _make_new_metaclass( $for, \%options );
- my $class = _make_new_class(
- $meta->$tor_class(),
- $options{ $tor_class . '_roles' }
- );
+ for my $c ( grep { $meta->can($_) } @Classes ) {
+ if ( $options{ $c . '_roles' } ) {
+ my $class = _make_new_class(
+ $meta->$c(),
+ $options{ $c . '_roles' }
+ );
- $meta->$tor_class($class);
+ $meta->$c($class);
+ }
+ else {
+ $meta->$c( $old_classes{$c} );
+ }
}
return $meta;
return $existing_class unless $roles;
- my $meta = $existing_class->meta();
+ my $meta = Class::MOP::Class->initialize($existing_class);
return $existing_class
if $meta->can('does_role') && all { $meta->does_role($_) } @{$roles};
This utility module is designed to help authors of Moose extensions
write extensions that are able to cooperate with other Moose
extensions. To do this, you must write your extensions as roles, which
-can then be dynamically applyied to the caller's metaclasses.
+can then be dynamically applied to the caller's metaclasses.
This module makes sure to preserve any existing superclasses and roles
already set for the meta objects, which means that any number of