Remove all trailing whitespace
[gitmo/Moose.git] / lib / Class / MOP / MiniTrait.pm
CommitLineData
38bf2a25 1package Class::MOP::MiniTrait;
2
3use strict;
4use warnings;
5
b5ae7c00 6use Class::Load qw(load_class);
7
38bf2a25 8sub apply {
9 my ( $to_class, $trait ) = @_;
10
11 for ( grep { !ref } $to_class, $trait ) {
b5ae7c00 12 load_class($_);
38bf2a25 13 $_ = Class::MOP::Class->initialize($_);
14 }
15
16 for my $meth ( $trait->get_all_methods ) {
17 my $meth_name = $meth->name;
18
19 if ( $to_class->find_method_by_name($meth_name) ) {
20 $to_class->add_around_method_modifier( $meth_name, $meth->body );
21 }
22 else {
23 $to_class->add_method( $meth_name, $meth->clone );
24 }
25 }
26}
27
28# We can't load this with use, since it may be loaded and used from Class::MOP
29# (via CMOP::Class, etc). However, if for some reason this module is loaded
30# _without_ first loading Class::MOP we need to require Class::MOP so we can
31# use it and CMOP::Class.
32require Class::MOP;
33
341;
35
064a13a3 36# ABSTRACT: Extremely limited trait application
37
38bf2a25 38__END__
39
40=pod
41
38bf2a25 42=head1 DESCRIPTION
43
44This package provides a single function, C<apply>, which does a half-assed job
45of applying a trait to a class. It exists solely for use inside Class::MOP and
46L<Moose> core classes.
47
48=cut
49