X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FManual%2FMooseX.pod;h=c47d15fe3b5da8f28dbab3f08b5b7315850b3a21;hb=1e62ec3bf60b5f85bc0a567958dda1be8df93e84;hp=607bf35138cf6193cd6e87206676dceace618341;hpb=dab940632264ba728cdd882436a2c972f001fecf;p=gitmo%2FMoose.git diff --git a/lib/Moose/Manual/MooseX.pod b/lib/Moose/Manual/MooseX.pod index 607bf35..c47d15f 100644 --- a/lib/Moose/Manual/MooseX.pod +++ b/lib/Moose/Manual/MooseX.pod @@ -1,8 +1,10 @@ -=pod +package Moose::Manual::MooseX; + +# ABSTRACT: Recommended Moose extensions -=head1 NAME +__END__ -Moose::Manual::MooseX - Recommended Moose extensions +=pod =head1 MooseX? @@ -23,31 +25,21 @@ This document covers a few of the ones we like best. =head1 L -If you only look at one extension, it should be this one. It provides -the equivalent of delegation for all of Perl's native data types, such -as array reference, hash references, numbers, strings, etc. +The functionality of this MooseX module has been moved into Moose core. +See L. -This lets you create I cleaner and fluent APIs. +=head1 L - package User; +MooseX::AttributeHelpers, but turned inside out, Moose::Autobox provides +methods on both arrays/hashes/etc. but also references to them, using +Moose roles, allowing you do to things like: - use Moose; - use MooseX::AttributeHelpers; - - has '_orders' => ( - metaclass => 'Collection::Array', - is => 'ro', - isa => 'ArrayRef', - default => sub { [] }, - provides => { - push => 'add_order', - shift => 'next_order', - elements => 'orders', - }, - ); + use Moose::Autobox; -Instead of directly exposing an array reference, we have three -well-named, easy to use methods. + $somebody_elses_object->orders->push($order); + +Lexically scoped and not to everybody's taste, but very handy for sugaring +up other people's APIs and your own code. =head1 L @@ -72,7 +64,12 @@ silently ignored. =head1 L We have high hopes for the future of L and -L. However, for now we recommend the decidedly more +L. However, these modules, while used regularly in +production by some of the more insane members of the community, are +still marked alpha just in case backwards incompatible changes need to +be made. + +If you don't want to risk that, for now we recommend the decidedly more clunky (but also faster and simpler) L. This module lets you apply Moose types and coercions to any method arguments. @@ -80,7 +77,7 @@ arguments. package User; use Moose; - use MooseX::Params::Validate qw( validatep ); + use MooseX::Params::Validate; sub login { my $self = shift; @@ -130,9 +127,13 @@ From the command line, someone can execute the script: =head1 L -To be honest, using a singleton is often a hack, but it sure is a -handy hack. L lets you have a Moose class that's a -singleton: +To be honest, using a singleton is just a way to have a magic global +variable in languages that don't actually have global variables. + +In perl, you can just as easily use a global. However, if your +colleagues are Java-infected, they might prefer a singleton. Also, if +you have an existing class that I a singleton but should be, +using L is the easiest way to convert it. package Config; @@ -166,13 +167,13 @@ cool, but still new and experimental. This extension helps you build a type library for your application. It also lets you predeclare type names and use them as barewords. - use MooseX::Types -declare => ['PosInt']; + use MooseX::Types -declare => ['PositiveInt']; use MooseX::Types::Moose 'Int'; - subtype PositiveInt - => as Int, - => where { $_ > 0 } - => message {"Int is not larger than 0"}; + subtype PositiveInt, + as Int, + where { $_ > 0 }, + message { "Int is not larger than 0" }; One nice feature is that those bareword names are actually namespaced in Moose's type registry, so multiple applications can use the same @@ -211,6 +212,16 @@ attributes. class_has 'Cache' => ( ... ); +Note however that this class attribute does I inherit like a +L or similar attribute - calling + + $subclass->Cache($cache); + +will set it for the superclass as well. Additionally, class data is usually +The Wrong Thing To Do in a strongly OO program since it makes testing a +lot harder - consider carefully whether you'd be better off with an object +that's passed around instead. + =head2 L This is a role that provides a number of methods useful for creating a @@ -221,7 +232,7 @@ file, and signal handling. If you find yourself wanting a role that customizes itself for each consumer, this is the tool for you. With this module, you can create a -role that accepts parameters and generates attributes, methods, etc on +role that accepts parameters and generates attributes, methods, etc. on a customized basis for each consumer. =head2 L @@ -240,17 +251,12 @@ Automatically names all accessors I-style, Automatically names all accessors with an explicit set and implicit get, "size" and "set_size". -=head1 AUTHOR - -Dave Rolsky Eautarch@urth.orgE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2009 by Infinity Interactive, Inc. - -L +=head2 L -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. +MooseX::NonMoose allows for easily subclassing non-Moose classes with Moose, +taking care of the annoying details connected with doing this, such as +setting up proper inheritance from Moose::Object and installing +(and inlining, at make_immutable time) a constructor that makes sure things +like BUILD methods are called. =cut