2 package Class::MOP::Method::Generated;
10 $VERSION = eval $VERSION;
11 our $AUTHORITY = 'cpan:STEVAN';
13 use base 'Class::MOP::Method';
15 use constant _PRINT_SOURCE => $ENV{MOP_PRINT_SOURCE} ? 1 : 0;
20 confess __PACKAGE__ . " is an abstract base class, you must provide a constructor.";
23 sub is_inline { $_[0]{is_inline} }
25 sub definition_context { $_[0]{definition_context} }
27 sub _initialize_body {
28 confess "No body to initialize, " . __PACKAGE__ . " is an abstract base class";
32 # my ($self, $captures, $sub_body) = @_;
33 my $__captures = $_[1];
44 or die "capture key should start with \@, \% or \$: $_";
53 print STDERR "\n", $_[0]->name, ":\n", $source, "\n" if _PRINT_SOURCE;
61 sub _add_line_directive {
62 my ( $self, %args ) = @_;
66 if ( my $ctx = ( $args{context} || $self->definition_context ) ) {
68 if ( my $desc = $ctx->{description} ) {
69 $file = "$desc defined at $ctx->{file}";
74 ( $line, $file ) = ( 0, "generated method (unknown origin)" );
77 my $code = $args{code};
79 # if it's an array of lines, join it up
80 # don't use newlines so that the definition context is more meaningful
81 $code = join(@$code, ' ') if ref $code;
83 return qq{#line $line "$file"\n} . $code;
87 my ( $self, %args ) = @_;
89 my $code = $self->_add_line_directive(%args);
91 return $self->_eval_closure($args{environment}, $code);
102 Class::MOP::Method::Generated - Abstract base class for generated methods
106 This is a C<Class::MOP::Method> subclass which is subclassed by
107 C<Class::MOP::Method::Accessor> and
108 C<Class::MOP::Method::Constructor>.
110 It is not intended to be used directly.
114 Stevan Little E<lt>stevan@iinteractive.comE<gt>
116 =head1 COPYRIGHT AND LICENSE
118 Copyright 2006-2010 by Infinity Interactive, Inc.
120 L<http://www.iinteractive.com>
122 This library is free software; you can redistribute it and/or modify
123 it under the same terms as Perl itself.