2 package Class::MOP::Method::Generated;
10 $VERSION = eval $VERSION;
11 our $AUTHORITY = 'cpan:STEVAN';
13 use base 'Class::MOP::Method';
19 ($options{package_name} && $options{name})
20 || confess "You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT";
22 my $self = $class->_new(\%options);
24 $self->initialize_body;
31 my ( $self, %args ) = @_;
35 if ( my $ctx = ( $args{context} || $self->definition_context ) ) {
37 if ( my $desc = $ctx->{description} ) {
38 $file = "$desc defined at $ctx->{file}";
43 ( $line, $file ) = ( 0, "generated method (unknown origin)" );
46 my $code = $args{code};
48 # if it's an array of lines, join it up
49 # don't use newlines so that the definition context is more meaningful
50 $code = join(@$code, ' ') if ref $code;
52 return qq{#line $line "$file"\n} . $code;
57 my $options = @_ == 1 ? $_[0] : {@_};
59 $options->{is_inline} ||= 0;
60 $options->{body} ||= undef;
62 bless $options, $class;
67 sub is_inline { $_[0]{is_inline} }
69 sub definition_context { $_[0]{definition_context} }
72 confess "No body to initialize, " . __PACKAGE__ . " is an abstract base class";
76 # my ($self, $captures, $sub_body) = @_;
77 my $__captures = $_[1];
82 or die "capture key should start with \@, \% or \$: $_";
83 q!my !.$_.q! = !.$1.q!{$__captures->{'!.$_.q!'}};!;
97 Class::MOP::Method::Generated - Abstract base class for generated methods
101 This is a C<Class::MOP::Method> subclass which is used interally
102 by C<Class::MOP::Method::Accessor> and C<Class::MOP::Method::Constructor>.
108 =item B<new (%options)>
110 This creates the method based on the criteria in C<%options>,
117 This is a boolean to indicate if the method should be generated
118 as a closure, or as a more optimized inline version.
124 This returns the boolean which was passed into C<new>.
126 =item B<initialize_body>
128 This is an abstract method and will throw an exception if called.
134 Stevan Little E<lt>stevan@iinteractive.comE<gt>
136 =head1 COPYRIGHT AND LICENSE
138 Copyright 2006-2008 by Infinity Interactive, Inc.
140 L<http://www.iinteractive.com>
142 This library is free software; you can redistribute it and/or modify
143 it under the same terms as Perl itself.