make github the primary repository
[gitmo/Moose.git] / lib / Moose / Meta / Method.pm
1 package Moose::Meta::Method;
2
3 use strict;
4 use warnings;
5
6 use Class::MOP::MiniTrait;
7
8 use base 'Class::MOP::Method';
9
10 Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait');
11
12 sub _error_thrower {
13     my $self = shift;
14     require Moose::Meta::Class;
15     ( ref $self && $self->associated_metaclass ) || "Moose::Meta::Class";
16 }
17
18 sub throw_error {
19     my $self = shift;
20     my $inv = $self->_error_thrower;
21     unshift @_, "message" if @_ % 2 == 1;
22     unshift @_, method => $self if ref $self;
23     unshift @_, $inv;
24     my $handler = $inv->can("throw_error");
25     goto $handler; # to avoid incrementing depth by 1
26 }
27
28 sub _inline_throw_error {
29     my ( $self, $msg, $args ) = @_;
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)
46 }
47
48 1;
49
50 # ABSTRACT: A Moose Method metaclass
51
52 __END__
53
54 =pod
55
56 =head1 DESCRIPTION
57
58 This class is a subclass of L<Class::MOP::Method> that provides
59 additional Moose-specific functionality, all of which is private.
60
61 To understand this class, you should read the the L<Class::MOP::Method>
62 documentation.
63
64 =head1 INHERITANCE
65
66 C<Moose::Meta::Method> is a subclass of L<Class::MOP::Method>.
67
68 =head1 BUGS
69
70 See L<Moose/BUGS> for details on reporting bugs.
71
72 =cut