Class::...:Package(3)
๐ Class::...:Package ๐
ok so bestie, welcome to the Class::...:Package page from the User Contributed Perl Documentation set ๐ซถ โ this is the manual for Class::MOP::Package, and no, that title is not a typo, that's literally the name. iykyk ๐
โจ NAME โจ
Class::MOP::Package โ the Package Meta Object, aka your backstage pass to a Perl package's whole vibe ๐
๐ธ VERSION ๐ธ
version 2.4000 โจ
๐ฆ DESCRIPTION ๐ฆ
okay so, the Package Protocol is giving abstraction of a Perl 5 package โ it's literally a whole wrapper situation ๐ซถ
a package is basically just a namespace, fr fr. and this module hands you methods for looking at that namespace's symbol table and changing it. peeking ๐ and editing โ๏ธ. both. iconic.
๐ METHODS ๐
๐ Class::MOP::Package->initialize($package_name, %options)
this one creates a brand new Class::MOP::Package instance that represents the package you specified โจ
but wait โ if a metaclass object for that package already exists? that one gets returned instead. no new one, no drama ๐
and ngl, at the package level no options are valid. none. zero. periodt ๐
๐ Class::MOP::Package->reinitialize($package, %options)
this method forcibly removes any existing metaclass for the package before calling initialize. forcibly!! ๐ฅ
and unlike initialize, you can also pass an existing Class::MOP::Package instance as $package instead of just a plain package name ๐
โ ๏ธ okay bestie listen โ do not call this unless you know what you are doing. that is a direct quote from the source material and it is not a joke ๐
๐ Class::MOP::Package->create($package, %options)
creates a new Class::MOP::Package instance representing the specified package, and also does some initialization of that package ๐
currently, this just does the same thing as initialize, but it's overridden in subclasses โ like Class::MOP::Class, bestie ๐
๐ Class::MOP::Package->create_anon(%options)
creates a new anonymous package ๐ซ๏ธ the valid keys for %options are:
cacheโ if this istrue(and the default isfalse), the instance will be cached inClass::MOP's metaclass cache ๐งบweakenโ if this istrue(the default istruewhencacheisfalse), the instance stored inClass::MOP's metaclass cache will be weakened, so the anonymous package gets garbage collected when the returned instance goes out of scope ๐๏ธโจ
๐ $metapackage->is_anon
returns true if the package is an anonymous package ๐ซ๏ธ
๐ $metapackage->name
returns the package's name โ the exact one you passed to the constructor ๐ท๏ธ
๐ $metapackage->namespace
returns a hash reference to the package's symbol table ๐ฎ
the keys are symbol names, and the values are typeglob references. that's the whole deal ๐ซถ
๐ $metapackage->add_package_symbol($variable_name, $initial_value)
this method accepts a variable name and an optional initial value โจ
the $variable_name must contain a leading sigil. do not skip the sigil, i am begging ๐
it creates the variable in the package's symbol table, and sets it to the initial value if one was provided ๐
๐ $metapackage->get_package_symbol($variable_name)
given a variable name, this returns the variable as a reference โ or undef if it does not exist ๐ซฅ
$variable_name must contain a leading sigil, same rules bestie ๐
๐ $metapackage->get_or_add_package_symbol($variable_name)
given a variable name, this returns the variable as a reference ๐
if it doesn't exist, a default value will be generated if possible โจ
and yep โ $variable_name must contain a leading sigil ๐
๐ $metapackage->has_package_symbol($variable_name)
returns true if there's a package variable defined for $variable_name โ
$variable_name must contain a leading sigil. we've been over this, but the docs keep saying it so i keep saying it ๐ซ
๐ $metapackage->remove_package_symbol($variable_name)
this will remove the package variable specified by $variable_name ๐๏ธ
$variable_name must contain a leading sigil โจ
๐ $metapackage->remove_package_glob($glob_name)
given the name of a glob, this removes that glob from the package's symbol table ๐ฅ
๐ heads up: glob names do not include a sigil. different rules, different queen.
and removing the glob removes all variables and subroutines with the specified name. like, all of them. gone. ๐
๐ $metapackage->list_all_package_symbols($type_filter)
this lists all the glob names associated with the current package ๐
these names do not have leading sigils ๐ซ
you can also provide an optional type filter, which should be one of 'SCALAR', 'ARRAY', 'HASH', or 'CODE' ๐
๐ $metapackage->get_all_package_symbols($type_filter)
this works much like list_all_package_symbols, but it returns a hash reference instead ๐งบ
the keys are glob names and the values are references to the value for that name ๐
๐ Class::MOP::Package->meta
this will return a Class::MOP::Class instance for this class ๐ meta about the meta, we love a layered situation ๐
๐ AUTHORS ๐
absolute legends, every single one of them ๐ซถ
- Stevan Little <stevan@cpan.org>
- Dave Rolsky <autarch@urth.org>
- Jesse Luehrs <doy@cpan.org>
- Shawn M Moore <sartak@cpan.org>
- ืืืื ืงืื'ืื (Yuval Kogman) <nothingmuch@woobling.org>
- Karen Etheridge <ether@cpan.org>
- Florian Ragwitz <rafl@debian.org>
- Hans Dieter Pearcey <hdp@cpan.org>
- Chris Prather <chris@prather.org>
- Matt S Trout <mstrout@cpan.org>
๐ COPYRIGHT AND LICENSE ๐
this software is copyright (c) 2006 by Infinity Interactive, Inc. ๐ธ
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself โจ
and that's the whole page bestie!! ๐ this lil doc came to you via perl v5.42.0, dated 2025-07-25, and it was living in Class::...:Package(3) the whole time ๐ mwah, go write some metaprogramming ๐ฆ๐
๐ฆ where this page comes from
- fedora 43: perl-Moose 2.4000-4.fc43 ยท GPL-1.0-or-later OR Artistic-1.0-Perl
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms