perldoc > Moose::Cookbook

📄 NAME

Moose::Cookbook - How to cook a Moose

🚀 Quick Reference

Use CaseCommandDescription
Define an attributehas 'name' => (is => 'rw', isa => 'Str')Declare a read-write string attribute
Create a custom subtypesubtype 'PositiveInt' => as 'Int' => where { $_ > 0 }Define a constrained integer type
Apply a role to a classwith 'Comparable';Compose a role into the current class
Make a class immutable__PACKAGE__->meta->make_immutable();Optimize accessors and construction
Use a method modifier (before)before 'method' => sub { ... };Run code before a method call
Use a method modifier (after)after 'method' => sub { ... };Run code after a method call
Use a method modifier (around)around 'method' => sub { my $orig = shift; $orig->(@_); };Wrap a method call
Define a type coercioncoerce 'ArrayRef' => from 'Str' => via { [split /,/] };Automatically convert a string to an array
Use lazy_buildhas 'data' => (is => 'ro', lazy_build => 1);Deferred attribute initialization with builder
Extend a non-Moose classextends 'DateTime';Subclass a class that does not use Moose

🔖 VERSION

version 2.2200

📝 DESCRIPTION

The Moose cookbook is a series of recipes showing various Moose features. Most recipes present some code demonstrating some feature, and then explain the details of the code.

You should probably read the Moose::Manual first. The manual explains Moose concepts without being too code-heavy.

🍳 RECIPES

🐭 Basic Moose

These recipes will give you a good overview of Moose's capabilities, starting with simple attribute declaration, and moving on to more powerful features like laziness, types, type coercion, method modifiers, and more.

🎭 Moose Roles

These recipes will show you how to use Moose roles.

🔧 Meta Moose

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

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.

🧩 Extending Moose

These recipes cover some more ways to extend Moose, and will be useful if you plan to write your own "MooseX" module.

🍿 SNACKS

📜 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.

👁️ SEE ALSO

<http://www.gsph.com/index.php?Lang=En&ID=291>

👤 AUTHORS

⚖️ 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.

Moose::Cookbook
📄 NAME 🚀 Quick Reference 🔖 VERSION 📝 DESCRIPTION 🍳 RECIPES
🐭 Basic Moose 🎭 Moose Roles 🔧 Meta Moose 🧩 Extending Moose
🍿 SNACKS 📜 Legacy Recipes 👁️ SEE ALSO 👤 AUTHORS ⚖️ COPYRIGHT AND LICENSE

Generated by phpman v4.9.26-5-g7740029 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-24 17:51 @216.73.217.23
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!

^_top_^