1 package Moose::Meta::Role::Application::ToInstance;
7 use Scalar::Util 'blessed';
9 our $AUTHORITY = 'cpan:STEVAN';
11 use base 'Moose::Meta::Role::Application';
13 __PACKAGE__->meta->add_attribute('rebless_params' => (
14 reader => 'rebless_params',
19 my ( $self, $role, $object, $args ) = @_;
21 my $obj_meta = Class::MOP::class_of($object) || 'Moose::Meta::Class';
23 # This is a special case to handle the case where the object's metaclass
24 # is a Class::MOP::Class, but _not_ a Moose::Meta::Class (for example,
25 # when applying a role to a Moose::Meta::Attribute object).
26 $obj_meta = 'Moose::Meta::Class'
27 unless $obj_meta->isa('Moose::Meta::Class');
29 my $class = $obj_meta->create_anon_class(
30 superclasses => [ blessed($object) ],
31 roles => [ $role, keys(%$args) ? ($args) : () ],
35 $class->rebless_instance( $object, %{ $self->rebless_params } );
40 # ABSTRACT: Compose a role into an instance
58 =item B<rebless_params>
64 See L<Moose/BUGS> for details on reporting bugs.