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 _initialize_body {
22 confess "No body to initialize, " . __PACKAGE__ . " is an abstract base class";
26 my ($self, $__captures, $sub_body) = @_;
37 or die "capture key should start with \@, \% or \$: $_";
47 $self->_dump_source($source) if $ENV{MOP_PRINT_SOURCE};
57 my ( $self, $source ) = @_;
60 if ( eval { require Perl::Tidy } ) {
63 my $rc_file = File::Spec->catfile(
64 $INC{'Class/MOP/Method/Generated.pm'},
71 destination => \$output,
73 $p{perltidyrc} = $rc_file
76 Perl::Tidy::perltidy(%p);
82 print STDERR "\n", $self->name, ":\n", $output, "\n";
85 sub _add_line_directive {
86 my ( $self, %args ) = @_;
90 if ( my $ctx = ( $args{context} || $self->definition_context ) ) {
92 if ( my $desc = $ctx->{description} ) {
93 $file = "$desc defined at $ctx->{file}";
98 ( $line, $file ) = ( 0, "generated method (unknown origin)" );
101 my $code = $args{code};
103 # if it's an array of lines, join it up
104 # don't use newlines so that the definition context is more meaningful
105 $code = join(@$code, ' ') if ref $code;
107 return qq{#line $line "$file"\n} . $code;
111 my ( $self, %args ) = @_;
113 my $code = $self->_add_line_directive(%args);
115 return $self->_eval_closure($args{environment}, $code);
126 Class::MOP::Method::Generated - Abstract base class for generated methods
130 This is a C<Class::MOP::Method> subclass which is subclassed by
131 C<Class::MOP::Method::Accessor> and
132 C<Class::MOP::Method::Constructor>.
134 It is not intended to be used directly.
138 Stevan Little E<lt>stevan@iinteractive.comE<gt>
140 =head1 COPYRIGHT AND LICENSE
142 Copyright 2006-2010 by Infinity Interactive, Inc.
144 L<http://www.iinteractive.com>
146 This library is free software; you can redistribute it and/or modify
147 it under the same terms as Perl itself.