1 package Moose::Meta::Role::Application::ToInstance;
8 use Scalar::Util 'blessed';
10 our $VERSION = '0.55_03';
11 $VERSION = eval $VERSION;
12 our $AUTHORITY = 'cpan:STEVAN';
14 use base 'Moose::Meta::Role::Application::ToClass';
16 __PACKAGE__->meta->add_attribute('rebless_params' => (
17 reader => 'rebless_params',
24 my ($self, $role, $object) = @_;
26 my $anon_role_key = (blessed($object) . $role->name);
29 if (exists $ANON_CLASSES{$anon_role_key} && defined $ANON_CLASSES{$anon_role_key}) {
30 $class = $ANON_CLASSES{$anon_role_key};
33 my $obj_meta = eval { $object->meta } || 'Moose::Meta::Class';
34 $class = $obj_meta->create_anon_class(
35 superclasses => [ blessed($object) ]
37 $ANON_CLASSES{$anon_role_key} = $class;
38 $self->SUPER::apply($role, $class);
41 $class->rebless_instance($object, %{$self->rebless_params});
52 Moose::Meta::Role::Application::ToInstance - Compose a role into an instance
66 =item B<rebless_params>
72 All complex software has bugs lurking in it, and this module is no
73 exception. If you find a bug please either email me, or add the bug
78 Stevan Little E<lt>stevan@iinteractive.comE<gt>
80 =head1 COPYRIGHT AND LICENSE
82 Copyright 2006-2008 by Infinity Interactive, Inc.
84 L<http://www.iinteractive.com>
86 This library is free software; you can redistribute it and/or modify
87 it under the same terms as Perl itself.