my $constructor_class = $options->{constructor_class}
|| 'Class::MOP::Method::Constructor';
- $metaclass->add_method(
- $options->{constructor_name},
- $constructor_class->new(
- options => $options,
- metaclass => $metaclass,
- is_inline => 1,
- package_name => $metaclass->name,
- name => $options->{constructor_name}
- )
+ my $constructor = $constructor_class->new(
+ options => $options,
+ metaclass => $metaclass,
+ is_inline => 1,
+ package_name => $metaclass->name,
+ name => $options->{constructor_name},
);
+ $metaclass->add_method( $options->{constructor_name} => $constructor )
+ if $constructor->can_be_inlined;
}
sub _inline_destructor {
}, $class;
}
+sub can_be_inlined { 1 }
+
## accessors
sub options { (shift)->{'options'} }
This returns a boolean, but since constructors are very rarely
not inlined, this always returns true for now.
+=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.
+
=item B<initialize_body>
This creates the code reference for the constructor itself.