Use dzil Authority plugin - remove $AUTHORITY from code
[gitmo/Moose.git] / lib / Class / MOP / Method / Generated.pm
1
2 package Class::MOP::Method::Generated;
3
4 use strict;
5 use warnings;
6
7 use Carp 'confess';
8 use Eval::Closure;
9
10 use base 'Class::MOP::Method';
11
12 ## accessors
13
14 sub new {
15     confess __PACKAGE__ . " is an abstract base class, you must provide a constructor.";
16 }
17
18 sub _initialize_body {
19     confess "No body to initialize, " . __PACKAGE__ . " is an abstract base class";
20 }
21
22 sub _generate_description {
23     my ( $self, $context ) = @_;
24     $context ||= $self->definition_context;
25
26     return "generated method (unknown origin)"
27         unless defined $context;
28
29     if (defined $context->{description}) {
30         return "$context->{description} "
31              . "(defined at $context->{file} line $context->{line})";
32     } else {
33         return "$context->{file} (line $context->{line})";
34     }
35 }
36
37 sub _compile_code {
38     my ( $self, @args ) = @_;
39     unshift @args, 'source' if @args % 2;
40     my %args = @args;
41
42     my $context = delete $args{context};
43     my $environment = $self->can('_eval_environment')
44         ? $self->_eval_environment
45         : {};
46
47     return eval_closure(
48         environment => $environment,
49         description => $self->_generate_description($context),
50         %args,
51     );
52 }
53
54 1;
55
56 __END__
57
58 =pod
59
60 =head1 NAME 
61
62 Class::MOP::Method::Generated - Abstract base class for generated methods
63
64 =head1 DESCRIPTION
65
66 This is a C<Class::MOP::Method> subclass which is subclassed by
67 C<Class::MOP::Method::Accessor> and
68 C<Class::MOP::Method::Constructor>.
69
70 It is not intended to be used directly.
71
72 =cut
73