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