Moose#

📦 std

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_map and is_stub called 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_map on an object with no package entry treats it as undefined, as perl does for an undefined one; perl crashes.

  • is_stub on 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_reexport does nothing to what is not a reference, and _export_is_flagged answers 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_amagic no 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.