X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FClass%2FMOP%2FMethod%2FConstructor.pm;h=d0279387c24dc2667dee82c5775cf44e09466fee;hb=b92a71799ca54c614ac3b3b2f9ddb9a2a930c6a2;hp=6ede4b3b754dd9edc0682fe0ea20cdc5430a62cc;hpb=fc76ff60c182b715e632403e0105edbd13566f8c;p=gitmo%2FClass-MOP.git diff --git a/lib/Class/MOP/Method/Constructor.pm b/lib/Class/MOP/Method/Constructor.pm index 6ede4b3..d027938 100644 --- a/lib/Class/MOP/Method/Constructor.pm +++ b/lib/Class/MOP/Method/Constructor.pm @@ -7,7 +7,7 @@ use warnings; use Carp 'confess'; use Scalar::Util 'blessed', 'weaken', 'looks_like_number'; -our $VERSION = '0.75'; +our $VERSION = '0.78'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -107,18 +107,12 @@ sub generate_constructor_method_inline { $source .= ";\n" . '}'; warn $source if $self->options->{debug}; - my $code; - { - # NOTE: - # create the nessecary lexicals - # to be picked up in the eval + my $code = $self->_eval_closure( + $close_over, + $source + ); + confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@" if $@; - $code = $self->_eval_closure( - $close_over, - $source - ); - confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@" if $@; - } return $code; } @@ -158,12 +152,12 @@ sub _generate_slot_initializer { 'if(exists $params->{\'' . $attr->init_arg . '\'}){' . "\n" . $self->meta_instance->inline_set_slot_value( '$instance', - ("'" . $attr->name . "'"), + $attr->name, '$params->{\'' . $attr->init_arg . '\'}' ) . "\n" . '} ' . (!defined $default ? '' : 'else {' . "\n" . $self->meta_instance->inline_set_slot_value( '$instance', - ("'" . $attr->name . "'"), + $attr->name, $default ) . "\n" . '}') ); @@ -171,7 +165,7 @@ sub _generate_slot_initializer { return ( $self->meta_instance->inline_set_slot_value( '$instance', - ("'" . $attr->name . "'"), + $attr->name, $default ) . "\n" ); } else { return '' } @@ -203,58 +197,58 @@ Class::MOP::Method::Constructor - Method Meta Object for constructors =head1 DESCRIPTION -This is a subclass of C which deals with -class constructors. This is used when making a class immutable -to generate an optimized constructor. +This is a subclass of C which generates +constructor methods. =head1 METHODS =over 4 -=item B $meta, options => \%options)> +=item B<< Class::MOP::Method::Constructor->new(%options) >> -=item B +This creates a new constructor object. It accepts a hash reference of +options. -This returns the options HASH which is passed into C. +=over 8 -=item B +=item * metaclass -This returns the metaclass which is passed into C. +This should be a L object. It is required. -=item B +=item * name -This returns the list of attributes which are associated with the -metaclass which is passed into C. +The method name (without a package name). This is required. -=item B +=item * package_name -This returns the meta instance which is associated with the -metaclass which is passed into C. +The package name for the method. This is required. -=item B +=item * is_inline -This returns a boolean, but since constructors are very rarely -not inlined, this always returns true for now. +This indicates whether or not the constructor should be inlined. This +defaults to false. -=item B +=back -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. +=item B<< $metamethod->is_inline >> -=item B +Returns a boolean indicating whether or not the constructor is +inlined. -This creates the code reference for the constructor itself. +=item B<< $metamethod->associated_metaclass >> -=back +This returns the L object for the method. -=head2 Method Generators +=item B<< $metamethod->is_inline >> -=over 4 +Returns a boolean indicating whether or not the constructor is +inlined. -=item B +=item B<< $metamethod->can_be_inlined >> -=item B +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 @@ -264,7 +258,7 @@ Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE -Copyright 2006-2008 by Infinity Interactive, Inc. +Copyright 2006-2009 by Infinity Interactive, Inc. L