1 package Moose::Meta::Role::Application::ToInstance;
7 use Scalar::Util 'blessed';
10 $VERSION = eval $VERSION;
11 our $AUTHORITY = 'cpan:STEVAN';
13 use base 'Moose::Meta::Role::Application';
15 __PACKAGE__->meta->add_attribute('rebless_params' => (
16 reader => 'rebless_params',
21 my ( $self, $role, $object, $args ) = @_;
23 my $obj_meta = Class::MOP::class_of($object) || 'Moose::Meta::Class';
25 # This is a special case to handle the case where the object's metaclass
26 # is a Class::MOP::Class, but _not_ a Moose::Meta::Class (for example,
27 # when applying a role to a Moose::Meta::Attribute object).
28 $obj_meta = 'Moose::Meta::Class'
29 unless $obj_meta->isa('Moose::Meta::Class');
31 my $class = $obj_meta->create_anon_class(
32 superclasses => [ blessed($object) ],
33 roles => [ $role, keys(%$args) ? ($args) : () ],
37 $class->rebless_instance( $object, %{ $self->rebless_params } );
48 Moose::Meta::Role::Application::ToInstance - Compose a role into an instance
62 =item B<rebless_params>
68 See L<Moose/BUGS> for details on reporting bugs.
72 Stevan Little E<lt>stevan@iinteractive.comE<gt>
74 =head1 COPYRIGHT AND LICENSE
76 Copyright 2006-2010 by Infinity Interactive, Inc.
78 L<http://www.iinteractive.com>
80 This library is free software; you can redistribute it and/or modify
81 it under the same terms as Perl itself.