Moose::Cookbook(3)

๐Ÿ’– Moose::Cookbook ๐Ÿ’–

okay bestie, welcome to the Moose::Cookbook page โ€” it's part of the User Contributed Perl Documentation, and it's literally your recipe box for cooking a Moose ๐ŸซŽโœจ

version 2.4000 โ€” yes, that's the VERSION, and yes, it slaps.


โœจ DESCRIPTION โœจ

So the Moose cookbook is a whole series of recipes showing off the various features Moose has to offer. Most recipes hand you some code that demonstrates a feature, and then break down the details of that code for you. Very demure, very mindful.

real talk though: you should probably read the Moose::Manual first. The manual explains Moose concepts without being too code-heavy โ€” think of it as the vibe check before the main event. ๐Ÿ“š


๐Ÿณ RECIPES ๐Ÿณ

๐ŸŒฑ Basic Moose

These recipes give you a genuinely good overview of what Moose can do โ€” starting with simple attribute declaration and then levelling up to the powerful stuff like laziness, types, type coercion, method modifiers, and more. Character development arc, honestly. ๐Ÿ‘‘

  • Moose::Cookbook::Basics::Point_AttributesAndSubclassing โ€” a simple Moose-based class. Demonstrates basic Moose attributes and subclassing. Starter pack energy.
  • Moose::Cookbook::Basics::BankAccount_MethodModifiersAndSubclassing โ€” a slightly more complex Moose class. Demonstrates using a method modifier in a subclass. ๐Ÿ’ธ
  • Moose::Cookbook::Basics::BinaryTree_AttributeFeatures โ€” demonstrates several attribute features, including types, weak references, predicates ("does this object have a foo?"), defaults, laziness, and triggers. That's a lot of features, she's doing numbers. ๐ŸŒณ
  • Moose::Cookbook::Basics::Company_Subtypes โ€” introduces the creation and use of custom types, a BUILD method, and the use of override in a subclass. This recipe also shows how to model a set of classes that could be used to model companies, people, employees, etc. Corporate slay ๐Ÿข
  • Moose::Cookbook::Basics::HTTP_SubtypesAndCoercion โ€” this recipe covers more subtype creation, including the use of type coercions.
  • Moose::Cookbook::Basics::Immutable โ€” making a class immutable greatly increases the speed of accessors and object construction. speed. ๐ŸŽ๏ธโœจ
  • Moose::Cookbook::Basics::BinaryTree_BuilderAndLazyBuild - Builder methods and lazy_build โ€” the builder feature provides an inheritable and role-composable way to provide a default attribute value. iykyk.
  • Moose::Cookbook::Basics::Genome_OverloadingSubtypesAndCoercion โ€” demonstrates using operator overloading, coercion, and subtypes to model how eye color is determined during reproduction. ๐Ÿงฌ๐Ÿ‘๏ธ genetics but make it OOP.
  • Moose::Cookbook::Basics::Person_BUILDARGSAndBUILD โ€” this recipe demonstrates the use of BUILDARGS and BUILD to hook into object construction. constructor girlies rise ๐Ÿซถ
  • Moose::Cookbook::Basics::DateTime_ExtendingNonMooseParent โ€” in this recipe, we make a Moose-based subclass of DateTime, a module which does not use Moose itself. crossing the friend groups, iconic behavior โฐ
  • Moose::Cookbook::Basics::Document_AugmentAndInner โ€” demonstrates the use of augment method modifiers, a way of turning the usual method overriding style "inside-out". ๐Ÿ™ƒ

๐ŸŽญ Moose Roles

These recipes show you how to use Moose roles. Roles are the code-reuse besties.

  • Moose::Cookbook::Roles::Comparable_CodeReuse โ€” demonstrates roles, which are also sometimes known as traits or mix-ins. Roles provide a method of code re-use which is orthogonal to subclassing. different axis, same excellence ๐Ÿ’…
  • Moose::Cookbook::Roles::Restartable_AdvancedComposition โ€” sometimes you just want to include part of a role in your class. Sometimes you want the whole role but one of its methods conflicts with one in your class. With method exclusion and aliasing, you can work around these problems. conflict resolution queen ๐Ÿ‘‘
  • Moose::Cookbook::Roles::ApplicationToInstance โ€” in this recipe, we apply a role to an existing object instance. not the class, the instance. she's specific.

๐Ÿ”ฎ Meta Moose

These recipes show you how to write your own meta classes, which lets you extend the object system provided by Moose. very meta of you fr fr

  • Moose::Cookbook::Meta::WhyMeta โ€” if you're wondering what all this "meta" stuff is, and why you should care about it, read this "recipe". ๐Ÿซ 
  • Moose::Cookbook::Meta::Labeled_AttributeTrait โ€” extending Moose's attribute metaclass is a great way to add functionality. However, attributes can only have one metaclass. Applying roles to the attribute metaclass lets you provide composable attribute functionality. one metaclass only, so we compose instead โ€” problem solved โœจ
  • Moose::Cookbook::Meta::Table_MetaclassTrait โ€” this recipe takes the class metaclass we saw in the previous recipe and reimplements it as a metaclass trait.
  • Moose::Cookbook::Meta::PrivateOrPublic_MethodMetaclass โ€” this recipe shows a custom method metaclass that implements making a method private. ๐Ÿคซ
  • Moose::Cookbook::Meta::GlobRef_InstanceMetaclass โ€” this recipe shows an example of how you create your own meta-instance class. The meta-instance determines the internal structure of object instances and provide access to attribute slots.
    • In this particular instance, we use a blessed glob reference as the instance instead of a blessed hash reference. plot twist!! ๐ŸŒ€
  • Hooking into immutabilization (TODO) โ€” Moose has a feature known as "immutabilization". By calling __PACKAGE__->meta()->make_immutable() after defining your class (attributes, roles, etc), you tell Moose to optimize things like object creation, attribute access, and so on.
    • If you are creating your own metaclasses, you may need to hook into the immutabilization system. This cuts across a number of spots, including the metaclass class, meta method classes, and possibly the meta-instance class as well.
    • This recipe shows you how to write extensions which immutabilize properly.
๐Ÿšจ note the (TODO) up there โ€” that recipe is a work in progress, bestie. don't come for me.

๐Ÿงฐ Extending Moose

These recipes cover some more ways to extend Moose, and will be useful if you plan to write your own MooseX module. yes, you. you could do this. ๐Ÿซถ

  • Moose::Cookbook::Extending::ExtensionOverview โ€” there are quite a few ways to extend Moose. This recipe provides an overview of each method, and provides recommendations for when each is appropriate. the map before the quest ๐Ÿ—บ๏ธ
  • Moose::Cookbook::Extending::Debugging_BaseClassRole โ€” many base object class extensions can be implemented as roles. This example shows how to provide a base object class debugging role that is applied to any class that uses a notional MooseX::Debugging module. ๐Ÿ›
  • Moose::Cookbook::Extending::Mooseish_MooseSugar โ€” this recipe shows how to provide a replacement for Moose.pm. You may want to do this as part of the API for a MooseX module, especially if you want to default to a new metaclass class or base object class. sugar, but make it Moose ๐Ÿฌ

๐Ÿ“ SNACKS ๐Ÿ“

little bite-sized ones, perfect between meals:

  • Moose::Cookbook::Snack::Keywords
  • Moose::Cookbook::Snack::Types

๐Ÿ‘ต Legacy Recipes

These cover topics that are no longer considered best practice. We've kept them in case in you encounter these usages in the wild. archive vibes, museum vibes, "we don't do this anymore but someone out there still does" vibes ๐Ÿš๏ธ

  • Moose::Cookbook::Legacy::Labeled_AttributeMetaclass
  • Moose::Cookbook::Legacy::Table_ClassMetaclass
  • Moose::Cookbook::Legacy::Debugging_BaseClassReplacement

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€


๐Ÿ’œ AUTHORS ๐Ÿ’œ

the legends, the icons, the ones who cooked:

  • 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. free as in freedom, bestie ๐Ÿ•Š๏ธ


okay that's the whole page, no cap ๐Ÿ’– this was the Moose::Cookbook(3) manpage, cooked and served by perl v5.42.0, dated 2025-07-25. go forth and write some Moose, you absolute main character. ๐ŸŒˆ๐Ÿฆ‹๐Ÿ’…

๐Ÿ“ฆ where this page comes from