Implement the "eval $VERSION" trick from perlmodstyle so CPAN doesn't
[gitmo/Moose.git] / lib / Moose / Meta / Role / Application / ToMetaclassInstance.pm
CommitLineData
5b5187e0 1package Moose::Meta::Role::Application::ToMetaclassInstance;
2
3use strict;
4use warnings;
5use metaclass;
6
7use Scalar::Util 'blessed';
8
75b95414 9our $VERSION = '0.55_01';
10$VERSION = eval $VERSION;
5b5187e0 11our $AUTHORITY = 'cpan:STEVAN';
12
13use base 'Moose::Meta::Role::Application::ToClass';
14
15__PACKAGE__->meta->add_attribute('rebless_params' => (
16 reader => 'rebless_params',
17 default => sub { {} }
18));
19
20my %ANON_CLASSES;
21
22sub apply {
23 my ( $self, $role, $meta ) = @_;
24
25 my $anon_role_key = (blessed($meta) . $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 {
32 my $metaclass_class
33 = ( ref $meta )->can('create_anon_class')
34 ? ref $meta
35 : 'Moose::Meta::Class';
36 $class = $metaclass_class->create_anon_class(
37 superclasses => [ blessed($meta) ],
38 );
39
40 $ANON_CLASSES{$anon_role_key} = $class;
41 $self->SUPER::apply( $role, $class );
42 }
43
44 $class->rebless_instance( $meta, %{ $self->rebless_params } );
45}
46
471;
48
49__END__
50
51=pod
52
53=head1 NAME
54
55Moose::Meta::Role::Application::ToMetaclassInstance - Compose a role into a metaclass instance
56
57=head1 DESCRIPTION
58
59=head2 METHODS
60
61=over 4
62
63=item B<new>
64
65=item B<meta>
66
67=item B<apply>
68
69=item B<rebless_params>
70
71=back
72
73=head1 BUGS
74
75All complex software has bugs lurking in it, and this module is no
76exception. If you find a bug please either email me, or add the bug
77to cpan-RT.
78
79=head1 AUTHOR
80
81Stevan Little E<lt>stevan@iinteractive.comE<gt>
82
83=head1 COPYRIGHT AND LICENSE
84
85Copyright 2006-2008 by Infinity Interactive, Inc.
86
87L<http://www.iinteractive.com>
88
89This library is free software; you can redistribute it and/or modify
90it under the same terms as Perl itself.
91
92=cut
93