# perldoc > Class::MOP

---
type: CommandReference
command: Class::MOP
mode: perldoc
section: ""
source: perldoc
---

## Quick Reference
- `Class::MOP::class_of($instance_or_class_name)` — Get metaclass of an instance or class name
- `Class::MOP::get_code_info($code)` — Return (package, name) of a code reference
- `Class::MOP::get_metaclass_by_name($name)` — Retrieve cached metaclass by name
- `Class::MOP::store_metaclass_by_name($name, $meta)` — Store metaclass in cache
- `Class::MOP::remove_metaclass_by_name($name)` — Remove metaclass from cache
- `Class::MOP::get_all_metaclasses()` — Hash of all cached metaclasses keyed by package name
- `Class::MOP::weaken_metaclass($name)` — Weaken the cached reference to a metaclass
- `Class::MOP::does_metaclass_exist($name)` — Check if a metaclass is cached

## Name
Class::MOP - A Meta Object Protocol for Perl 5

## Synopsis
This module is a fully functioning meta object protocol for the Perl 5 object system. It is not intended for direct use by end users, but by module authors to build class builders (e.g., Moose). It provides introspection and manipulation of classes, attributes, methods, and instances without modifying the existing object system.

## Protocols
The meta-object protocol is divided into four main sub-protocols:

- **Class protocol** — Manipulate and introspect a Perl 5 class. See [Class::MOP::Class](https://metacpan.org/pod/Class::MOP::Class).
- **Attribute protocol** — Consistent representation for a class attribute. See [Class::MOP::Attribute](https://metacpan.org/pod/Class::MOP::Attribute).
- **Method protocol** — Manipulate and introspect methods. See [Class::MOP::Method](https://metacpan.org/pod/Class::MOP::Method).
- **Instance protocol** — Abstraction for creating object instances. See [Class::MOP::Instance](https://metacpan.org/pod/Class::MOP::Instance).

## Functions

### Utility functions

- `Class::MOP::get_code_info($code)` — Returns a two-element list: the package name and the name of the given code reference.
- `Class::MOP::class_of($instance_or_class_name)` — Returns the metaclass of the given instance or class name. If the class lacks a metaclass, returns `undef`. Prefer `Moose::Util::find_meta` instead.

### Metaclass cache functions

- `Class::MOP::get_all_metaclasses()` — Returns a hash of all cached metaclass instances, keyed by package name.
- `Class::MOP::get_all_metaclass_instances()` — Returns a list of all cached metaclass instances.
- `Class::MOP::get_all_metaclass_names()` — Returns a list of all cached metaclass names.
- `Class::MOP::get_metaclass_by_name($name)` — Returns the cached `Class::MOP::Class` instance for `$name`, or nothing.
- `Class::MOP::store_metaclass_by_name($name, $meta)` — Stores a metaclass in the cache under the key `$name`.
- `Class::MOP::weaken_metaclass($name)` — Weakens the reference to the metaclass stored under `$name` (useful for anonymous metaclasses).
- `Class::MOP::metaclass_is_weak($name)` — Returns true if the metaclass for `$name` has been weakened.
- `Class::MOP::does_metaclass_exist($name)` — Returns true if a metaclass is stored under `$name`, false otherwise.
- `Class::MOP::remove_metaclass_by_name($name)` — Removes the metaclass stored under `$name`.

## Examples

perl
use Class::MOP;

# Get the metaclass of a class
my $meta = Class::MOP::class_of('SomeClass');

# Get code info for a subroutine
my ($package, $name) = Class::MOP::get_code_info(\&some_sub);

# Store and retrieve a metaclass manually
Class::MOP::store_metaclass_by_name('MyClass', $meta);
my $same_meta = Class::MOP::get_metaclass_by_name('MyClass');
## See Also

- [Class::MOP::Class](https://metacpan.org/pod/Class::MOP::Class) — Class introspection and manipulation
- [Class::MOP::Attribute](https://metacpan.org/pod/Class::MOP::Attribute) — Attribute protocol
- [Class::MOP::Method](https://metacpan.org/pod/Class::MOP::Method) — Method protocol
- [Class::MOP::Instance](https://metacpan.org/pod/Class::MOP::Instance) — Instance protocol
- [Moose](https://metacpan.org/pod/Moose) — Class builder built on Class::MOP
- [Class::Load](https://metacpan.org/pod/Class::Load) — Class loading utilities extracted from Class::MOP
- [Moose::Util::MetaRole](https://metacpan.org/pod/Moose::Util::MetaRole) — Apply roles to metaclasses
- [The Art of the Meta Object Protocol](https://en.wikipedia.org/wiki/The_Art_of_the_Metaobject_Protocol) — Book on MOP concepts
- "Uniform and safe metaclass composition" — Paper on metaclass compatibility (SCG University of Bern)