bump version to 0.86
[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';
8
8e863a0a 9our $VERSION = '0.86';
d519662a 10$VERSION = eval $VERSION;
565f0cbb 11our $AUTHORITY = 'cpan:STEVAN';
12
13use base 'Class::MOP::Method';
14
0242e3f9 15## accessors
e3a72dbc 16
0242e3f9 17sub new {
18 confess __PACKAGE__ . " is an abstract base class, you must provide a constructor.";
e3a72dbc 19}
20
d9d99689 21sub is_inline { $_[0]{is_inline} }
22
23sub definition_context { $_[0]{definition_context} }
565f0cbb 24
1fd40136 25sub _initialize_body {
565f0cbb 26 confess "No body to initialize, " . __PACKAGE__ . " is an abstract base class";
27}
28
7f8de9b4 29sub _eval_closure {
0c6f3280 30 # my ($self, $captures, $sub_body) = @_;
31 my $__captures = $_[1];
a6eef5a3 32 eval join(
0c6f3280 33 "\n",
2507ef3a 34 (
35 map {
36 /^([\@\%\$])/
37 or die "capture key should start with \@, \% or \$: $_";
38 q[my ]
39 . $_ . q[ = ]
40 . $1
41 . q[{$__captures->{']
42 . $_
43 . q['}};];
44 } keys %$__captures
45 ),
0c6f3280 46 $_[2]
47 );
7f8de9b4 48}
565f0cbb 49
12f7b801 50sub _add_line_directive {
51 my ( $self, %args ) = @_;
52
53 my ( $line, $file );
54
55 if ( my $ctx = ( $args{context} || $self->definition_context ) ) {
56 $line = $ctx->{line};
57 if ( my $desc = $ctx->{description} ) {
58 $file = "$desc defined at $ctx->{file}";
59 } else {
60 $file = $ctx->{file};
61 }
62 } else {
63 ( $line, $file ) = ( 0, "generated method (unknown origin)" );
64 }
65
66 my $code = $args{code};
67
68 # if it's an array of lines, join it up
69 # don't use newlines so that the definition context is more meaningful
70 $code = join(@$code, ' ') if ref $code;
71
72 return qq{#line $line "$file"\n} . $code;
73}
74
75sub _compile_code {
76 my ( $self, %args ) = @_;
77
78 my $code = $self->_add_line_directive(%args);
79
80 $self->_eval_closure($args{environment}, $code);
81}
82
565f0cbb 831;
84
85__END__
86
87=pod
88
89=head1 NAME
90
91Class::MOP::Method::Generated - Abstract base class for generated methods
92
93=head1 DESCRIPTION
94
653556ae 95This is a C<Class::MOP::Method> subclass which is subclassed by
96C<Class::MOP::Method::Accessor> and
97C<Class::MOP::Method::Constructor>.
565f0cbb 98
653556ae 99It is not intended to be used directly.
565f0cbb 100
101=head1 AUTHORS
102
103Stevan Little E<lt>stevan@iinteractive.comE<gt>
104
105=head1 COPYRIGHT AND LICENSE
106
070bb6c9 107Copyright 2006-2009 by Infinity Interactive, Inc.
565f0cbb 108
109L<http://www.iinteractive.com>
110
111This library is free software; you can redistribute it and/or modify
112it under the same terms as Perl itself.
113
114=cut
115