1 package Moose::Meta::Role::Application::ToInstance;
8 use Scalar::Util 'blessed';
10 our $VERSION = '0.52';
11 our $AUTHORITY = 'cpan:STEVAN';
13 use base 'Moose::Meta::Role::Application::ToClass';
15 __PACKAGE__->meta->add_attribute('rebless_params' => (
16 reader => 'rebless_params',
23 my ($self, $role, $object) = @_;
25 my $anon_role_key = (blessed($object) . $role->name);
28 if (exists $ANON_CLASSES{$anon_role_key} && defined $ANON_CLASSES{$anon_role_key}) {
29 $class = $ANON_CLASSES{$anon_role_key};
32 my $obj_meta = eval { $object->meta } || 'Moose::Meta::Class';
33 $class = $obj_meta->create_anon_class(
34 superclasses => [ blessed($object) ]
36 $ANON_CLASSES{$anon_role_key} = $class;
37 $self->SUPER::apply($role, $class);
40 $class->rebless_instance($object, %{$self->rebless_params});
51 Moose::Meta::Role::Application::ToInstance - Compose a role into an instance
65 =item B<rebless_params>
71 All complex software has bugs lurking in it, and this module is no
72 exception. If you find a bug please either email me, or add the bug
77 Stevan Little E<lt>stevan@iinteractive.comE<gt>
79 =head1 COPYRIGHT AND LICENSE
81 Copyright 2006-2008 by Infinity Interactive, Inc.
83 L<http://www.iinteractive.com>
85 This library is free software; you can redistribute it and/or modify
86 it under the same terms as Perl itself.