use Carp 'confess';
use Scalar::Util 'blessed', 'weaken', 'looks_like_number';
-our $VERSION = '0.78';
+our $VERSION = '0.78_02';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
$source .= "\n" . 'my $instance = ' . $self->meta_instance->inline_create_instance('$class');
$source .= ";\n" . (join ";\n" => map {
$self->_generate_slot_initializer($_, $close_over)
- } 0 .. (@{$self->attributes} - 1));
+ } @{$self->attributes});
$source .= ";\n" . 'return $instance';
$source .= ";\n" . '}';
warn $source if $self->options->{debug};
- return $self->_eval_closure(
+ my $code = $self->_eval_closure(
$close_over,
$source
);
+ confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@" if $@;
+
+ return $code;
}
sub _generate_slot_initializer {
my $self = shift;
- my $index = shift;
+ my $attr = shift;
my $close = shift;
- my $attr = $self->attributes->[$index];
-
my $default;
if ($attr->has_default) {
# NOTE:
=head1 DESCRIPTION
-This is a subclass of C<Class::MOP::Method> which deals with
-class constructors. This is used when making a class immutable
-to generate an optimized constructor.
+This is a subclass of C<Class::MOP::Method> which generates
+constructor methods.
=head1 METHODS
=over 4
-=item B<new (metaclass => $meta, options => \%options)>
-
-=item B<options>
+=item B<< Class::MOP::Method::Constructor->new(%options) >>
-This returns the options HASH which is passed into C<new>.
+This creates a new constructor object. It accepts a hash reference of
+options.
-=item B<associated_metaclass>
+=over 8
-This returns the metaclass which is passed into C<new>.
+=item * metaclass
-=item B<attributes>
+This should be a L<Class::MOP::Class> object. It is required.
-This returns the list of attributes which are associated with the
-metaclass which is passed into C<new>.
+=item * name
-=item B<meta_instance>
+The method name (without a package name). This is required.
-This returns the meta instance which is associated with the
-metaclass which is passed into C<new>.
+=item * package_name
-=item B<is_inline>
+The package name for the method. This is required.
-This returns a boolean, but since constructors are very rarely
-not inlined, this always returns true for now.
+=item * is_inline
-=item B<can_be_inlined>
-
-This method always returns true in this class. It exists so that
-subclasses (like in Moose) can override and do some sort of checking
-to determine whether or not inlining the constructor is safe.
+This indicates whether or not the constructor should be inlined. This
+defaults to false.
-=item B<initialize_body>
+=back
-This creates the code reference for the constructor itself.
+=item B<< $metamethod->is_inline >>
-=back
+Returns a boolean indicating whether or not the constructor is
+inlined.
-=head2 Method Generators
+=item B<< $metamethod->associated_metaclass >>
-=over 4
+This returns the L<Class::MOP::Class> object for the method.
-=item B<generate_constructor_method>
+=item B<< $metamethod->can_be_inlined >>
-=item B<generate_constructor_method_inline>
+This method always returns true in this class. It exists so that
+subclasses (as in Moose) can do some sort of checking to determine
+whether or not inlining the constructor is safe.
=back
=head1 COPYRIGHT AND LICENSE
-Copyright 2006-2008 by Infinity Interactive, Inc.
+Copyright 2006-2009 by Infinity Interactive, Inc.
L<http://www.iinteractive.com>