Commit | Line | Data |
35cb21ab |
1 | package Class::MOP::MiniTrait; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | our $VERSION = '1.08'; |
7 | $VERSION = eval $VERSION; |
8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | |
10 | sub apply { |
11 | my ( $to_class, $trait ) = @_; |
12 | |
13 | for ( grep { !ref } $to_class, $trait ) { |
14 | Class::MOP::load_class($_); |
15 | $_ = Class::MOP::Class->initialize($_); |
16 | } |
17 | |
18 | for my $meth ( $trait->get_all_methods ) { |
19 | my $meth_name = $meth->name; |
20 | |
21 | if ( $to_class->find_method_by_name($meth_name) ) { |
22 | $to_class->add_around_method_modifier( $meth_name, $meth->body ); |
23 | } |
24 | else { |
25 | $to_class->add_method( $meth_name, $meth->clone ); |
26 | } |
27 | } |
28 | } |
29 | |
30 | 1; |
31 | |
32 | __END__ |
33 | |
34 | =pod |
35 | |
36 | =head1 NAME |
37 | |
38 | Class::MOP::MiniTrait - Extremely limited trait application |
39 | |
40 | =head1 DESCRIPTION |
41 | |
42 | This package provides a single function, C<apply>, which does a half-assed job |
43 | of applying a trait to a class. It exists solely for use inside Class::MOP and |
44 | L<Moose> core classes. |
45 | |
46 | =head1 AUTHORS |
47 | |
48 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
49 | |
50 | =head1 COPYRIGHT AND LICENSE |
51 | |
52 | Copyright 2006-2010 by Infinity Interactive, Inc. |
53 | |
54 | L<http://www.iinteractive.com> |
55 | |
56 | This library is free software; you can redistribute it and/or modify |
57 | it under the same terms as Perl itself. |
58 | |
59 | =cut |
60 | |