2 package Class::MOP::Method::Generated;
10 $VERSION = eval $VERSION;
11 our $AUTHORITY = 'cpan:STEVAN';
13 use base 'Class::MOP::Method';
18 confess __PACKAGE__ . " is an abstract base class, you must provide a constructor.";
21 sub is_inline { $_[0]{is_inline} }
23 sub definition_context { $_[0]{definition_context} }
25 sub _initialize_body {
26 confess "No body to initialize, " . __PACKAGE__ . " is an abstract base class";
30 my ($self, $__captures, $sub_body) = @_;
41 or die "capture key should start with \@, \% or \$: $_";
51 $self->_dump_source($source) if $ENV{MOP_PRINT_SOURCE};
61 my ( $self, $source ) = @_;
64 if ( eval { require Perl::Tidy } ) {
67 my $rc_file = File::Spec->catfile(
68 $INC{'Class/MOP/Method/Generated.pm'},
75 destination => \$output,
77 $p{perltidyrc} = $rc_file
80 Perl::Tidy::perltidy(%p);
86 print STDERR "\n", $self->name, ":\n", $output, "\n";
89 sub _add_line_directive {
90 my ( $self, %args ) = @_;
94 if ( my $ctx = ( $args{context} || $self->definition_context ) ) {
96 if ( my $desc = $ctx->{description} ) {
97 $file = "$desc defined at $ctx->{file}";
102 ( $line, $file ) = ( 0, "generated method (unknown origin)" );
105 my $code = $args{code};
107 # if it's an array of lines, join it up
108 # don't use newlines so that the definition context is more meaningful
109 $code = join(@$code, ' ') if ref $code;
111 return qq{#line $line "$file"\n} . $code;
115 my ( $self, %args ) = @_;
117 my $code = $self->_add_line_directive(%args);
119 return $self->_eval_closure($args{environment}, $code);
130 Class::MOP::Method::Generated - Abstract base class for generated methods
134 This is a C<Class::MOP::Method> subclass which is subclassed by
135 C<Class::MOP::Method::Accessor> and
136 C<Class::MOP::Method::Constructor>.
138 It is not intended to be used directly.
142 Stevan Little E<lt>stevan@iinteractive.comE<gt>
144 =head1 COPYRIGHT AND LICENSE
146 Copyright 2006-2010 by Infinity Interactive, Inc.
148 L<http://www.iinteractive.com>
150 This library is free software; you can redistribute it and/or modify
151 it under the same terms as Perl itself.