From: Brian Manning Date: Mon, 19 May 2008 21:38:34 +0000 (+0000) Subject: - added some rough ideas for changes to the docs as proposed on #moose X-Git-Tag: 0_55~161 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=80cca4cf6fc7308027d5c2ef6564eef6effbedae;p=gitmo%2FMoose.git - added some rough ideas for changes to the docs as proposed on #moose --- diff --git a/lib/Moose/Cookbook/Snack/BUILD.pod b/lib/Moose/Cookbook/Snack/BUILD.pod index a56ddf1..f16d075 100644 --- a/lib/Moose/Cookbook/Snack/BUILD.pod +++ b/lib/Moose/Cookbook/Snack/BUILD.pod @@ -74,6 +74,22 @@ created, a good time to do that is when the object is being created. Why waste resources (CPU, memory) on objects that won't work because of missing resources? +=head2 When would you use an Moose type constraint instead of a custom constructor? + +Using type constraints via L, you can verify +simple relationships when an object is created: + + package Triangle; + use Moose; + + has + +You would want to use the C method in order to verify more complex +relationships: + + package IsoscelesTriangle; + use Moose; + =head2 BUILD method is run only if it is defined in the object If your object does not have a C method, then Moose will skip trying to diff --git a/lib/Moose/Cookbook/Snack/HashRef.pod b/lib/Moose/Cookbook/Snack/HashRef.pod index 93c147b..a6b28fa 100644 --- a/lib/Moose/Cookbook/Snack/HashRef.pod +++ b/lib/Moose/Cookbook/Snack/HashRef.pod @@ -37,7 +37,9 @@ variable as an attribute of a Moose object. The code in this document will work on Moose as advertised, but the developers strongly recommend using something like L or L when working with hash references in order to -help keep your Moose objects nice and encapsulated. +help keep your Moose objects nice and encapsulated. The reason why this POD +exists is to show potential users of L that Moose objects are just like +Plain Ol' Perl Objects (POPO), albeit with some extra metadata syntatic sugar. =head2 Assigning hashes to a HashRef attribute @@ -107,6 +109,7 @@ C attribute. Here's an example of appending new key/value pars: my $avocado = Fruit->new( species => 'P. americana' ); $fruit_aisle_copy{avocado} = $avocado; $store->fruit_aisle( \%fruit_aisle_copy ); + $store->fruit_aisle->{avocado}; And here's an example of deleting existing key/value pairs: @@ -114,6 +117,7 @@ And here's an example of deleting existing key/value pairs: %fruit_aisle_copy = %{$store->fruit_aisle}; delete($fruit_aisle_copy{tomato}); $store->fruit_aisle( \%fruit_aisle_copy ); + delete $mooseObj->hashref->{foo}; Putting the above code into their own object methods would make appending to and deleting from a C a trivial operation.