Moose#
The compiled part of Moose and Class::MOP: the attribute readers of the metaclass objects, the method map cache, and a few helpers of Moose::Exporter, the type constraints and role application.
Moose’s own .pm files load this when Class::MOP is loaded; it is not used directly. Class::MOP::get_code_info is the one function meant to be called by other code.
This is a native implementation of Moose 2.4001’s mop.c and xs/*.xs; its .pm files are used unchanged.
Synopsis#
use Class::MOP;
my ($package, $name) = Class::MOP::get_code_info(\&Foo::bar); # ('Foo', 'bar')
my $meta = Class::MOP::Class->initialize('Foo');
print $meta->name, "\n"; # Foo
print $meta->get_method('bar')->is_stub ? "stub\n" : "defined\n";
Differences from upstream#
_method_mapandis_stubcalled on something that is not a reference to a hash die with the readers’ messages, “can’t call _method_map as a class method” and “object is not a hashref”; perl crashes._method_mapon an object with nopackageentry treats it as undefined, as perl does for an undefined one; perl crashes.is_stubon a method whose body is not a code reference dies “method body is not a CODE reference”; perl crashes, or reads the value as code and answers at random.Moose::Exporter’s
_flag_as_reexportdoes nothing to what is not a reference, and_export_is_flaggedanswers false for it; perl crashes on both.Applying a role to an instance that is not a blessed reference (
_reset_amagic) does nothing; perl crashes._reset_amagicno longer walks every scalar of the program looking for other references to the object: in perl 5.44 the overloading flag it sets on each of them lives on the class, which the first one has already set. The result is the same, without a cost that grows with the size of the program.