X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FCookbook%2FBasics%2FRecipe5.pod;h=46acef4325318c71e9d6c247e638000c9b56198e;hb=01062d8a9c752c413210277e06128d4c87224e81;hp=c8f457c023a244b7887a804572d5f4fd5e8fc62f;hpb=de51f1923eaf51531a30642e23d3a7100dd7a408;p=gitmo%2FMoose.git diff --git a/lib/Moose/Cookbook/Basics/Recipe5.pod b/lib/Moose/Cookbook/Basics/Recipe5.pod index c8f457c..46acef4 100644 --- a/lib/Moose/Cookbook/Basics/Recipe5.pod +++ b/lib/Moose/Cookbook/Basics/Recipe5.pod @@ -76,7 +76,7 @@ First, we create the subtype to which we will coerce the other types: subtype 'My::Types::HTTP::Headers' => as class_type('HTTP::Headers'); We are creating a subtype rather than using C as a type -directly. The reason we do this is coercions are global, and a +directly. The reason we do this is that coercions are global, and a coercion defined for C in our C class would then be defined for I Moose-using classes in the current Perl interpreter. It's a L to @@ -96,7 +96,7 @@ We could go ahead and use this new type directly: has 'headers' => ( is => 'rw', - isa => 'HTTP::Headers', + isa => 'My::Types::HTTP::Headers', default => sub { HTTP::Headers->new } ); @@ -106,7 +106,7 @@ L. The constructor for L accepts a list of key-value pairs representing the HTTP header fields. In Perl, such a list could be stored in an ARRAY or HASH reference. We want our C attribute -to accept those data structure instead of an B +to accept those data structures instead of an B instance, and just do the right thing. This is exactly what coercion is for: @@ -170,7 +170,7 @@ return value. If L didn't return a L object (for whatever reason), Moose would throw a type constraint error. -The other coercion takes a string and converts to a L. In this +The other coercion takes a string and converts it to a L. In this case, we are using the coercion to apply a default behavior, where a string is assumed to be an C URI. @@ -190,7 +190,7 @@ caution. Sometimes it's better to reject a value than just guess at how to DWIM. We also showed the use of the C sugar function as a -shortcut for defining a new subtype of C +shortcut for defining a new subtype of C. =head1 FOOTNOTES @@ -201,7 +201,7 @@ shortcut for defining a new subtype of C This particular example could be safer. Really we only want to coerce an array with an I number of elements. We could create a new C type, and then coerce from that type, as -opposed to from a plain C +opposed to a plain C =back