Method::Accessor throw_error code
[gitmo/Moose.git] / lib / Moose / Meta / Method.pm
1 package Moose::Meta::Method;
2
3 use strict;
4 use warnings;
5
6 our $VERSION   = '0.50';
7 our $AUTHORITY = 'cpan:STEVAN';
8
9 use base 'Class::MOP::Method';
10
11 sub throw_error {
12     my $self = shift;
13     my $inv = ( ref $self && ( $self->associated_attribute || $self->associated_class ) ) || "Moose::Meta::Class";
14     unshift @_, "message" if @_ % 2 == 1;
15     unshift @_, method => $self if ref $self;
16     unshift @_, $inv;
17     goto $inv->can("throw_error"); # to avoid incrementing depth by 1
18 }
19
20 sub _inline_throw_error {
21     my ( $self, $msg, $args ) = @_;
22     "\$meta->throw_error($msg" . ($args ? ", $args" : "") . ")"; # FIXME makes deparsing *REALLY* hard
23 }
24
25 1;
26
27 __END__
28
29 =pod
30
31 =head1 NAME
32
33 Moose::Meta::Method - A Moose Method metaclass
34
35 =head1 DESCRIPTION
36
37 For now, this is nothing but a subclass of Class::MOP::Method, 
38 but with the expanding role of the method sub-protocol, it might 
39 be more useful later on. 
40
41 =head1 METHODS
42
43 =over 4
44
45 =item throw_error $msg, %args
46
47 =item _inline_throw_error $msg_expr, $args_expr
48
49 =back
50
51 =head1 BUGS
52
53 All complex software has bugs lurking in it, and this module is no 
54 exception. If you find a bug please either email me, or add the bug
55 to cpan-RT.
56
57 =head1 AUTHOR
58
59 Stevan Little E<lt>stevan@iinteractive.comE<gt>
60
61 =head1 COPYRIGHT AND LICENSE
62
63 Copyright 2006-2008 by Infinity Interactive, Inc.
64
65 L<http://www.iinteractive.com>
66
67 This library is free software; you can redistribute it and/or modify
68 it under the same terms as Perl itself.
69
70 =cut