factor codegen stuff out to Eval::Closure
[gitmo/Class-MOP.git] / lib / Class / MOP / Method / Generated.pm
CommitLineData
565f0cbb 1
2package Class::MOP::Method::Generated;
3
4use strict;
5use warnings;
6
7use Carp 'confess';
15961c86 8use Eval::Closure;
565f0cbb 9
a9f48b4b 10our $VERSION = '1.11';
d519662a 11$VERSION = eval $VERSION;
565f0cbb 12our $AUTHORITY = 'cpan:STEVAN';
13
14use base 'Class::MOP::Method';
15
0242e3f9 16## accessors
e3a72dbc 17
0242e3f9 18sub new {
19 confess __PACKAGE__ . " is an abstract base class, you must provide a constructor.";
e3a72dbc 20}
21
1fd40136 22sub _initialize_body {
565f0cbb 23 confess "No body to initialize, " . __PACKAGE__ . " is an abstract base class";
24}
25
15961c86 26sub _generate_description {
27 my ( $self, $context ) = @_;
28 $context ||= $self->definition_context;
d2d9edc0 29
15961c86 30 return "generated method (unknown origin)"
31 unless defined $context;
12f7b801 32
15961c86 33 if (defined $context->{description}) {
34 return "$context->{description} "
35 . "(defined at $context->{file} line $context->{line})";
12f7b801 36 } else {
15961c86 37 return "$context->{file} (line $context->{line})";
12f7b801 38 }
12f7b801 39}
40
41sub _compile_code {
15961c86 42 my ( $self, @args ) = @_;
43 unshift @args, 'source' if @args % 2;
44 my %args = @args;
45
46 my $context = delete $args{context};
47 my $environment = $self->can('_eval_environment')
48 ? $self->_eval_environment
49 : {};
50
51 return eval_closure(
52 environment => $environment,
53 description => $self->_generate_description($context),
54 %args,
55 );
12f7b801 56}
57
565f0cbb 581;
59
60__END__
61
62=pod
63
64=head1 NAME
65
66Class::MOP::Method::Generated - Abstract base class for generated methods
67
68=head1 DESCRIPTION
69
653556ae 70This is a C<Class::MOP::Method> subclass which is subclassed by
71C<Class::MOP::Method::Accessor> and
72C<Class::MOP::Method::Constructor>.
565f0cbb 73
653556ae 74It is not intended to be used directly.
565f0cbb 75
76=head1 AUTHORS
77
78Stevan Little E<lt>stevan@iinteractive.comE<gt>
79
80=head1 COPYRIGHT AND LICENSE
81
3e2c8600 82Copyright 2006-2010 by Infinity Interactive, Inc.
565f0cbb 83
84L<http://www.iinteractive.com>
85
86This library is free software; you can redistribute it and/or modify
87it under the same terms as Perl itself.
88
89=cut
90