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;
19 # FIXME refactor into a trait when those are introduced to Class::MOP
22 confess __PACKAGE__ . " is an abstract base class, you must provide a constructor.";
25 sub _initialize_body {
26 confess "No body to initialize, " . __PACKAGE__ . " is an abstract base class";
32 $self->{'body'} ||= $self->_initialize_body;
36 # my ($self, $captures, $sub_body) = @_;
37 my $__captures = $_[1];
48 or die "capture key should start with \@, \% or \$: $_";
57 print STDERR "\n", $_[0]->name, ":\n", $source, "\n" if _PRINT_SOURCE;
65 sub _add_line_directive {
66 my ( $self, %args ) = @_;
70 if ( my $ctx = ( $args{context} || $self->definition_context ) ) {
72 if ( my $desc = $ctx->{description} ) {
73 $file = "$desc defined at $ctx->{file}";
78 ( $line, $file ) = ( 0, "generated method (unknown origin)" );
81 my $code = $args{code};
83 # if it's an array of lines, join it up
84 # don't use newlines so that the definition context is more meaningful
85 $code = join(@$code, ' ') if ref $code;
87 return qq{#line $line "$file"\n} . $code;
91 my ( $self, %args ) = @_;
93 my $code = $self->_add_line_directive(%args);
95 return $self->_eval_closure($args{environment}, $code);
99 Carp::cluck('The generate_reader_method method has been made private.'
100 . " The public version is deprecated and will be removed in a future release.\n");
101 shift->_generate_method;
104 sub generate_method_inline {
105 Carp::cluck('The generate_reader_method_inline method has been made private.'
106 . " The public version is deprecated and will be removed in a future release.\n");
107 shift->_generate_method_inline;
110 sub initialize_body {
111 Carp::cluck('The initialize_body method has been made private.'
112 . " The public version is deprecated and will be removed in a future release.\n");
113 shift->_initialize_body;
125 Class::MOP::Method::Generated - Abstract base class for generated methods
129 This is a C<Class::MOP::Method> subclass which is subclassed by
130 C<Class::MOP::Method::Accessor> and
131 C<Class::MOP::Method::Constructor>.
133 It is not intended to be used directly.
137 Stevan Little E<lt>stevan@iinteractive.comE<gt>
139 =head1 COPYRIGHT AND LICENSE
141 Copyright 2006-2009 by Infinity Interactive, Inc.
143 L<http://www.iinteractive.com>
145 This library is free software; you can redistribute it and/or modify
146 it under the same terms as Perl itself.