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