bump version to 0.91
[gitmo/Moose.git] / lib / Moose / Meta / Role / Application / ToInstance.pm
CommitLineData
fb1e11d5 1package Moose::Meta::Role::Application::ToInstance;
2
3use strict;
4use warnings;
5use metaclass;
6
9b28d20b 7use Scalar::Util 'blessed';
fb1e11d5 8
113d3174 9our $VERSION = '0.91';
e606ae5f 10$VERSION = eval $VERSION;
fb1e11d5 11our $AUTHORITY = 'cpan:STEVAN';
12
1c9db35c 13use base 'Moose::Meta::Role::Application::ToClass';
14
3a79f0e9 15__PACKAGE__->meta->add_attribute('rebless_params' => (
16 reader => 'rebless_params',
17 default => sub { {} }
18));
19
d71ba374 20my %ANON_CLASSES;
1c9db35c 21
22sub apply {
23 my ($self, $role, $object) = @_;
24
d71ba374 25 my $anon_role_key = (blessed($object) . $role->name);
26
27 my $class;
28 if (exists $ANON_CLASSES{$anon_role_key} && defined $ANON_CLASSES{$anon_role_key}) {
29 $class = $ANON_CLASSES{$anon_role_key};
30 }
31 else {
37b3097c 32 my $obj_meta = Class::MOP::class_of($object) || 'Moose::Meta::Class';
c87f0c7f 33 $class = $obj_meta->create_anon_class(
d71ba374 34 superclasses => [ blessed($object) ]
35 );
36 $ANON_CLASSES{$anon_role_key} = $class;
37 $self->SUPER::apply($role, $class);
38 }
39
3a79f0e9 40 $class->rebless_instance($object, %{$self->rebless_params});
1c9db35c 41}
fb1e11d5 42
431;
44
45__END__
46
47=pod
48
49=head1 NAME
50
ab76842e 51Moose::Meta::Role::Application::ToInstance - Compose a role into an instance
fb1e11d5 52
53=head1 DESCRIPTION
54
55=head2 METHODS
56
57=over 4
58
59=item B<new>
60
61=item B<meta>
62
1c9db35c 63=item B<apply>
64
3a79f0e9 65=item B<rebless_params>
66
fb1e11d5 67=back
68
69=head1 BUGS
70
71All complex software has bugs lurking in it, and this module is no
72exception. If you find a bug please either email me, or add the bug
73to cpan-RT.
74
75=head1 AUTHOR
76
77Stevan Little E<lt>stevan@iinteractive.comE<gt>
78
79=head1 COPYRIGHT AND LICENSE
80
2840a3b2 81Copyright 2006-2009 by Infinity Interactive, Inc.
fb1e11d5 82
83L<http://www.iinteractive.com>
84
85This library is free software; you can redistribute it and/or modify
86it under the same terms as Perl itself.
87
88=cut
89