make github the primary repository
[gitmo/Moose.git] / lib / Class / MOP / Method / Overload.pm
CommitLineData
2683d371 1
2package Class::MOP::Method::Overload;
3
4use strict;
5use warnings;
6
7use Carp 'confess';
8
9use base 'Class::MOP::Method';
10
11sub wrap {
12 my $class = shift;
13 my (@args) = @_;
14 unshift @args, 'body' if @args % 2 == 1;
15 my %params = @args;
16
644d6eaa 17 confess "operator is required"
18 unless exists $params{operator};
2683d371 19
20 return $class->SUPER::wrap(
644d6eaa 21 name => "($params{operator}",
2683d371 22 %params,
23 );
24}
25
26sub _new {
27 my $class = shift;
28 return Class::MOP::Class->initialize($class)->new_object(@_)
29 if $class ne __PACKAGE__;
30
31 my $params = @_ == 1 ? $_[0] : {@_};
32
33 return bless {
34 # inherited from Class::MOP::Method
35 'body' => $params->{body},
36 'associated_metaclass' => $params->{associated_metaclass},
37 'package_name' => $params->{package_name},
38 'name' => $params->{name},
39 'original_method' => $params->{original_method},
40
41 # defined in this class
644d6eaa 42 'operator' => $params->{operator},
2683d371 43 } => $class;
44}
45
461;
bdd1acbd 47
48# ABSTRACT: Method Meta Object for methods which implement overloading
49
50__END__
51
52=pod
53
54=head1 DESCRIPTION
55
56This is a L<Class::MOP::Method> subclass which represents methods that
57implement overloading.
58
59=head1 METHODS
60
61=over 4
62
63=item B<< Class::MOP::Method::Overload->wrap($metamethod, %options) >>
64
65This is the constructor. The options accepted are identical to the ones
66accepted by L<Class::MOP::Method>, except that it also required an C<operator>
67parameter, which should be an operator as defined by the L<overload> pragma.
68
69=item B<< $metamethod->operator >>
70
71This returns the operator that was passed to new.
72
73=back
74
75=cut