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 is true (and the default is false), the instance will be cached in Class::MOP's metaclass cache ๐Ÿงบ
  • weaken โ€” if this is true (the default is true when cache is false), the instance stored in Class::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>

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