Commit | Line | Data |
565f0cbb |
1 | |
2 | package Class::MOP::Method::Generated; |
3 | |
4 | use strict; |
5 | use warnings; |
6 | |
7 | use Carp 'confess'; |
15961c86 |
8 | use Eval::Closure; |
565f0cbb |
9 | |
a9f48b4b |
10 | our $VERSION = '1.11'; |
d519662a |
11 | $VERSION = eval $VERSION; |
565f0cbb |
12 | our $AUTHORITY = 'cpan:STEVAN'; |
13 | |
14 | use base 'Class::MOP::Method'; |
15 | |
0242e3f9 |
16 | ## accessors |
e3a72dbc |
17 | |
0242e3f9 |
18 | sub new { |
19 | confess __PACKAGE__ . " is an abstract base class, you must provide a constructor."; |
e3a72dbc |
20 | } |
21 | |
1fd40136 |
22 | sub _initialize_body { |
565f0cbb |
23 | confess "No body to initialize, " . __PACKAGE__ . " is an abstract base class"; |
24 | } |
25 | |
15961c86 |
26 | sub _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 | |
41 | sub _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 |
58 | 1; |
59 | |
60 | __END__ |
61 | |
62 | =pod |
63 | |
64 | =head1 NAME |
65 | |
66 | Class::MOP::Method::Generated - Abstract base class for generated methods |
67 | |
68 | =head1 DESCRIPTION |
69 | |
653556ae |
70 | This is a C<Class::MOP::Method> subclass which is subclassed by |
71 | C<Class::MOP::Method::Accessor> and |
72 | C<Class::MOP::Method::Constructor>. |
565f0cbb |
73 | |
653556ae |
74 | It is not intended to be used directly. |
565f0cbb |
75 | |
76 | =head1 AUTHORS |
77 | |
78 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
79 | |
80 | =head1 COPYRIGHT AND LICENSE |
81 | |
3e2c8600 |
82 | Copyright 2006-2010 by Infinity Interactive, Inc. |
565f0cbb |
83 | |
84 | L<http://www.iinteractive.com> |
85 | |
86 | This library is free software; you can redistribute it and/or modify |
87 | it under the same terms as Perl itself. |
88 | |
89 | =cut |
90 | |