1 package Moose::Meta::Role::Application::ToInstance;
8 use Scalar::Util 'blessed';
10 our $VERSION = '0.02';
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 $class = Moose::Meta::Class->create_anon_class(
33 superclasses => [ blessed($object) ]
35 $ANON_CLASSES{$anon_role_key} = $class;
36 $self->SUPER::apply($role, $class);
39 $class->rebless_instance($object, %{$self->rebless_params});
50 Moose::Meta::Role::Application::ToInstance - Compose a role into an instance
64 =item B<rebless_params>
70 All complex software has bugs lurking in it, and this module is no
71 exception. If you find a bug please either email me, or add the bug
76 Stevan Little E<lt>stevan@iinteractive.comE<gt>
78 =head1 COPYRIGHT AND LICENSE
80 Copyright 2006-2008 by Infinity Interactive, Inc.
82 L<http://www.iinteractive.com>
84 This library is free software; you can redistribute it and/or modify
85 it under the same terms as Perl itself.