use Scalar::Util 'blessed', 'weaken', 'looks_like_number';
-our $VERSION = '0.72';
+our $VERSION = '0.73_01';
our $AUTHORITY = 'cpan:STEVAN';
use base 'Moose::Meta::Method',
- 'Class::MOP::Method::Generated';
+ 'Class::MOP::Method::Constructor';
sub new {
my $class = shift;
|| $class->throw_error("You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT");
my $self = bless {
- # from our superclass
'body' => undef,
'package_name' => $options{package_name},
'name' => $options{name},
- # specific to this subclass
'options' => $options{options},
- 'meta_instance' => $meta->get_meta_instance,
- 'attributes' => [ $meta->compute_all_applicable_attributes ],
- # ...
'associated_metaclass' => $meta,
} => $class;
# needed
weaken($self->{'associated_metaclass'});
- $self->initialize_body;
+ $self->_initialize_body;
return $self;
}
grep { $_ ne $expected_class }
$metaclass->linearized_isa
) {
- my $transformer = $meta->get_immutable_transformer;
+ my $transformer = $meta->immutable_transformer;
# This is actually a false positive if we're in a subclass of
# this class, _and_ the expected class is not overridden (but
return 'Moose::Object';
}
-## accessors
-
-sub options { (shift)->{'options'} }
-sub meta_instance { (shift)->{'meta_instance'} }
-sub attributes { (shift)->{'attributes'} }
-
-sub associated_metaclass { (shift)->{'associated_metaclass'} }
-
## method
-# this was changed in 0.41, but broke MooseX::Singleton, so try to catch
-# any other code using the original broken spelling
-sub intialize_body { $_[0]->throw_error("Please correct the spelling of 'intialize_body' to 'initialize_body'") }
-
-sub _generate_params {
- my ($self, $var, $class_var) = @_;
- "my $var = " . $self->_generate_BUILDARGS($class_var, '@_') . ";\n";
-}
-
-sub _generate_instance {
- my ($self, $var, $class_var) = @_;
- "my $var = " . $self->meta_instance->inline_create_instance($class_var)
- . ";\n";
-}
-
-sub _generate_slot_initializers {
- my ($self) = @_;
- return (join ";\n" => map {
- $self->_generate_slot_initializer($_)
- } 0 .. (@{$self->attributes} - 1)) . ";\n";
-}
-
-sub initialize_body {
+sub _initialize_body {
my $self = shift;
# TODO:
# the %options should also include a both
# because the inlined code is using the index of the attributes
# to determine where to find the type constraint
- my $attrs = $self->attributes;
+ my $attrs = $self->_attributes;
my @type_constraints = map {
$_->can('type_constraint') ? $_->type_constraint : undef
$self->{'body'} = $code;
}
+sub _generate_params {
+ my ( $self, $var, $class_var ) = @_;
+ "my $var = " . $self->_generate_BUILDARGS( $class_var, '@_' ) . ";\n";
+}
+
+sub _generate_instance {
+ my ( $self, $var, $class_var ) = @_;
+ "my $var = "
+ . $self->_meta_instance->inline_create_instance($class_var) . ";\n";
+}
+
+sub _generate_slot_initializers {
+ my ($self) = @_;
+ return (join ";\n" => map {
+ $self->_generate_slot_initializer($_)
+ } 0 .. (@{$self->_attributes} - 1)) . ";\n";
+}
+
sub _generate_BUILDARGS {
my ( $self, $class, $args ) = @_;
sub _generate_triggers {
my $self = shift;
my @trigger_calls;
- foreach my $i (0 .. $#{ $self->attributes }) {
- my $attr = $self->attributes->[$i];
- if ($attr->can('has_trigger') && $attr->has_trigger) {
- if (defined(my $init_arg = $attr->init_arg)) {
- push @trigger_calls => (
- '(exists $params->{\'' . $init_arg . '\'}) && do {' . "\n "
- . '$attrs->[' . $i . ']->trigger->('
- . '$instance, '
- . $self->meta_instance->inline_get_slot_value(
- '$instance',
- $attr->name,
- )
- . ', '
- . '$attrs->[' . $i . ']'
- . ');'
- ."\n}"
- );
- }
- }
+ foreach my $i ( 0 .. $#{ $self->_attributes } ) {
+ my $attr = $self->_attributes->[$i];
+
+ next unless $attr->can('has_trigger') && $attr->has_trigger;
+
+ my $init_arg = $attr->init_arg;
+
+ next unless defined $init_arg;
+
+ push @trigger_calls => '(exists $params->{\''
+ . $init_arg
+ . '\'}) && do {'
+ . "\n "
+ . '$attrs->['
+ . $i
+ . ']->trigger->('
+ . '$instance, '
+ . $self->_meta_instance->inline_get_slot_value(
+ '$instance',
+ $attr->name,
+ )
+ . ', '
+ . ');' . "\n}";
}
- return join ";\n" => @trigger_calls;
+
+ return join ";\n" => @trigger_calls;
}
sub _generate_slot_initializer {
my $self = shift;
my $index = shift;
- my $attr = $self->attributes->[$index];
+ my $attr = $self->_attributes->[$index];
my @source = ('## ' . $attr->name);
}
else {
$source = (
- $self->meta_instance->inline_set_slot_value(
+ $self->_meta_instance->inline_set_slot_value(
'$instance',
$attr->name,
$value
if ($is_moose && $attr->is_weak_ref) {
$source .= (
"\n" .
- $self->meta_instance->inline_weaken_slot_value(
+ $self->_meta_instance->inline_weaken_slot_value(
'$instance',
$attr->name
) .
=head1 DESCRIPTION
-This is a subclass of L<Class::MOP::Method> which handles
-constructing an appropriate Constructor methods. This is primarily
-used in the making of immutable metaclasses, otherwise it is
-not particularly useful.
+This class is a subclass of L<Class::MOP::Class::Constructor> that
+provides additional Moose-specific functionality
+
+To understand this class, you should read the the
+L<Class::MOP::Class::Constructor> documentation as well.
+
+=head1 INHERITANCE
+
+C<Moose::Meta::Method::Constructor> is a subclass of
+L<Moose::Meta::Method> I<and> L<Class::MOP::Method::Constructor>.
=head1 METHODS
=over 4
-=item B<new>
-
-=item B<can_be_inlined>
+=item B<< $metamethod->can_be_inlined >>
-=item B<attributes>
+This returns true if the method can inlined.
-=item B<meta_instance>
+First, it looks at all of the parents of the associated class. If any
+of them have an inlined constructor, then the constructor can be
+inlined.
-=item B<options>
+If none of them have been inlined, it checks to make sure that the
+pre-inlining constructor for the class matches the constructor from
+the expected class.
-=item B<initialize_body>
+By default, it expects this constructor come from L<Moose::Object>,
+but subclasses can change this expectation.
-=item B<associated_metaclass>
+If the constructor cannot be inlined it warns that this is the case.
=back