fix setting associated_metaclass and attribute on accessor objects
[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     ( ref $self && $self->associated_metaclass ) || "Moose::Meta::Class";
15 }
16
17 sub throw_error {
18     my $self = shift;
19     my $inv = $self->_error_thrower;
20     unshift @_, "message" if @_ % 2 == 1;
21     unshift @_, method => $self if ref $self;
22     unshift @_, $inv;
23     my $handler = $inv->can("throw_error");
24     goto $handler; # to avoid incrementing depth by 1
25 }
26
27 sub _inline_throw_error {
28     my ( $self, $msg, $args ) = @_;
29     "\$meta->throw_error($msg" . ($args ? ", $args" : "") . ")"; # FIXME makes deparsing *REALLY* hard
30 }
31
32 1;
33
34 # ABSTRACT: A Moose Method metaclass
35
36 __END__
37
38 =pod
39
40 =head1 DESCRIPTION
41
42 This class is a subclass of L<Class::MOP::Method> that provides
43 additional Moose-specific functionality, all of which is private.
44
45 To understand this class, you should read the the L<Class::MOP::Method>
46 documentation.
47
48 =head1 INHERITANCE
49
50 C<Moose::Meta::Method> is a subclass of L<Class::MOP::Method>.
51
52 =head1 BUGS
53
54 See L<Moose/BUGS> for details on reporting bugs.
55
56 =cut