MOP - A Meta Object Protocol for Perl 5
version 0.11
use MOP; my $m = MOP::Class->new( 'Foo' ); printf 'Introspecting %s package with version %s', $m->name, $m->version; foreach my $s ( $m->all_slots ) { printf 'Found slot %s', $s->name; } foreach my $m ( $m->all_methods ) { printf 'Found method %s', $m->name; }
This module implements a Meta Object Protocol for Perl 5 with minimal overhead and no non-core dependencies (eventually).
A Meta Object Protocol, or MOP, is an API to the various parts of the an object system.
There are only a few key concepts in the MOP, which are described below.
A role is simply a package which may have methods, may have slot defintions, and may consume other roles.
A class does all the things a role does, with the addition of inheritance and instance construction.
A slot is best thought of as representing a single entry in the package scoped %HAS variable. This is basically just building upon the conceptual model laid out by UNIVERSAL::Object.
%HAS
A method is simply a wrapper around a reference to a CODE slot inside a given package.
This module uses the UNIVERSAL::Object module as the chosen instance construction protocol, but also in its introspection assumes that a class uses the conventions of UNIVERSAL::Object specifically with regards to slot storage.
Almost 10 years ago I wrote Class::MOP, whose purpose was also to bring a MOP to Perl 5. While these modules may have had the same goal, they have different requirements and priorities and so shouldn't be compared directly.
Stevan Little <stevan@cpan.org>
This software is copyright (c) 2017 by Stevan Little.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install MOP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MOP
CPAN shell
perl -MCPAN -e shell install MOP
For more information on module installation, please visit the detailed CPAN module installation guide.