RT#83929: fix memory leak in union types
[gitmo/Moose.git] / lib / Moose / Meta / Method.pm
CommitLineData
8ee73eeb 1package Moose::Meta::Method;
2
3use strict;
4use warnings;
5
d2782813 6use Class::MOP::MiniTrait;
7
8ee73eeb 8use base 'Class::MOP::Method';
9
d2782813 10Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait');
11
3e504337 12sub _error_thrower {
13 my $self = shift;
bcc04ae1 14 require Moose::Meta::Class;
18748ad6 15 ( ref $self && $self->associated_metaclass ) || "Moose::Meta::Class";
3e504337 16}
17
cee532a1 18sub throw_error {
19 my $self = shift;
3e504337 20 my $inv = $self->_error_thrower;
cee532a1 21 unshift @_, "message" if @_ % 2 == 1;
22 unshift @_, method => $self if ref $self;
23 unshift @_, $inv;
ffa3d7bf 24 my $handler = $inv->can("throw_error");
25 goto $handler; # to avoid incrementing depth by 1
cee532a1 26}
27
28sub _inline_throw_error {
29 my ( $self, $msg, $args ) = @_;
bcc04ae1 30
31 my $inv = $self->_error_thrower;
32 # XXX ugh
33 $inv = 'Moose::Meta::Class' unless $inv->can('_inline_throw_error');
34
35 # XXX ugh ugh UGH
36 my $class = $self->associated_metaclass;
37 if ($class) {
38 my $class_name = B::perlstring($class->name);
39 my $meth_name = B::perlstring($self->name);
40 $args = 'method => Class::MOP::class_of(' . $class_name . ')'
41 . '->find_method_by_name(' . $meth_name . '), '
42 . (defined $args ? $args : '');
43 }
44
45 return $inv->_inline_throw_error($msg, $args)
cee532a1 46}
47
8ee73eeb 481;
49
ad46f524 50# ABSTRACT: A Moose Method metaclass
51
8ee73eeb 52__END__
53
54=pod
55
39b3bc94 56=head1 DESCRIPTION
57
bef3ee55 58This class is a subclass of L<Class::MOP::Method> that provides
e3177578 59additional Moose-specific functionality, all of which is private.
39b3bc94 60
bef3ee55 61To understand this class, you should read the the L<Class::MOP::Method>
e3177578 62documentation.
cee532a1 63
d4b1449e 64=head1 INHERITANCE
65
66C<Moose::Meta::Method> is a subclass of L<Class::MOP::Method>.
67
39b3bc94 68=head1 BUGS
69
d4048ef3 70See L<Moose/BUGS> for details on reporting bugs.
39b3bc94 71
cee532a1 72=cut