From: Stevan Little Date: Wed, 2 Jul 2008 15:45:53 +0000 (+0000) Subject: some doc cleanup X-Git-Tag: 0_55~61 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=47b195703a79d662e3a92fd6dd1e230addfb68bb;p=gitmo%2FMoose.git some doc cleanup --- diff --git a/Changes b/Changes index 32ef3a0..2af4daf 100644 --- a/Changes +++ b/Changes @@ -1,7 +1,18 @@ Revision history for Perl extension Moose 0.52 + * Moose::Cookbook::Snacks::* + - removed some of the unfinished snacks that should + not have been released yet. Added some more examples + and explination to the 'Keywords' snack. (Stevan) + + * Moose + - added "FEATURE REQUESTS" section to the Moose docs + to properly direct people (Stevan) (RT #34333) + * Moose::Cookbook::Style + - added general Moose "style guide" of sorts to the + cookbook (nothingmuch) (RT #34335) 0.51 Thurs. Jun 26, 2008 * Moose::Role @@ -41,6 +52,7 @@ Revision history for Perl extension Moose * Moose::Meta::TypeConstraint * Moose::Meta::TypeCoercion - Attempt to work around the ??{ } vs. threads issue + (not yet fixed) - Some null_constraint optimizations 0.50 Thurs. Jun 11, 2008 diff --git a/MANIFEST b/MANIFEST index ba59067..fe1b401 100644 --- a/MANIFEST +++ b/MANIFEST @@ -26,11 +26,7 @@ lib/Moose/Cookbook/Recipe5.pod lib/Moose/Cookbook/Recipe6.pod lib/Moose/Cookbook/Recipe7.pod lib/Moose/Cookbook/Recipe9.pod -lib/Moose/Cookbook/Snack/ArrayRef.pod -lib/Moose/Cookbook/Snack/BUILD.pod -lib/Moose/Cookbook/Snack/HashRef.pod lib/Moose/Cookbook/Snack/Keywords.pod -lib/Moose/Cookbook/Snack/Perl5ObjsVsMooseObjs.pod lib/Moose/Cookbook/Snack/Types.pod lib/Moose/Cookbook/WTF.pod lib/Moose/Meta/Attribute.pm diff --git a/Makefile.PL b/Makefile.PL index 0619502..f704e63 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,6 +1,6 @@ use strict; use warnings; -use inc::Module::Install 0.75; +use inc::Module::Install; name 'Moose'; all_from 'lib/Moose.pm'; diff --git a/lib/Moose.pm b/lib/Moose.pm index 21b3f64..f4cd595 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -973,6 +973,15 @@ All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. +=head1 FEATURE REQUESTS + +We are very strict about what features we add to the Moose core, especially +the user-visible features. Instead we have made sure that the underlying +meta-system of Moose is as extensible as possible so that you can add your +own features easily. That said, occasionally there is a feature needed in the +meta-system to support your planned extension, in which case you should +either email the mailing list or join us on irc at #moose to discuss. + =head1 AUTHOR Stevan Little Estevan@iinteractive.comE diff --git a/lib/Moose/Cookbook/Snack/ArrayRef.pod b/lib/Moose/Cookbook/Snack/ArrayRef.pod deleted file mode 100644 index 6dc2bab..0000000 --- a/lib/Moose/Cookbook/Snack/ArrayRef.pod +++ /dev/null @@ -1,162 +0,0 @@ - -=pod - -=head1 NAME - -Moose::Cookbook::Snack::ArrayRef - Using the ArrayRef type constraint - -=head1 SYNOPSIS - - package Fruit; - use Moose; - - has 'name' => (is => 'rw', required => 1); - has 'species' => (is => 'rw', required => 1); - - package ProduceStore; - use Moose; - use Moose::Util::TypeConstraints; - - has 'fruit_aisle' => (isa => 'ArrayRef[Fruit]', is => 'rw'); - - package main; - - # we need something to put in the fruit aisle - my $orange = Fruit->new(name => 'orange', species => 'C. sinensis'); - my $apple = Fruit->new(name => 'apple', species => 'M. domestica'); - my @fruit = ($apple, $orange); - my $store = ProduceStore->new(fruit_aisle => \@fruit); - -=head1 DESCRIPTION - -The ArrayRef type constraint is used to store a reference to a Perl list or -array variable as an attribute of a Moose object. - -=head2 Disclaimer - -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 array references in order to -help keep your Moose objects nice and encapsulated. - -=head2 Assigning arrays to an ArrayRef attribute - -Once a Moose-based object with an C attribute has been created, you -can pass an array (by reference) to that object attribute using that -attribute's accessor. This is how we assign the apple and orange to the -store's C C attribute, we pass an array containing both -objects by reference to the C attribute: - - my @fruit = ($apple, $orange); - my $store = ProduceStore->new(fruit_aisle => \@fruit); - -Or you can pass an anonymous array to the C attribute as well. If -you created two new objects, C<$grape> and C<$tomato>, and assigned them to -the C, they would replace the apple and the orange in the store's -fruit aisle: - - $store->fruit_aisle( [$grape, $tomato] ); - -Our C C is parameterized, meaning, that the -C C can contain nothing but C objects as array -values. If you try to pass in a reference to a array using C objects as -array values for example, Moose will complain: - - Attribute (fruit_aisle) does not pass the type constraint (ArrayRef[Str]) - -=head2 Dumping the contents of an ArrayRef - -In order to dump the contents of a C object attribute, you must first -de-reference the C, and then enumerate over it's keys. You can add -this method for showing the store's inventory to the C -object shown in the SYNOPSIS: - - sub show_inventory { - my $self = shift; - foreach my $item ( @{$self->fruit_aisle} ) { - # ... access each Fruit object - } - } - -=head2 Assigning arrays to an ArrayRef will overwrite existing arrays - -Once you create an object containing a C attribute, if you assign a -new array reference to that attribute, it will replace any existing array -reference: - - # replace existing inventory - my $grape = Fruit->new(name => 'grape', species => 'V. vinifera'); - my $tomato = Fruit->new(name => 'tomato', species => 'S. lycopersicum'); - $store->fruit_aisle( [$grape, $tomato] ); - -=head2 Appending/Deleting values to/from an ArrayRef - -In order to append new elements to an array referred to by the C -attribute, you will need to make a copy of the array first, add your new array -elements, then assign your modified copy back to the C attribute: - - my @fruit_aisle_copy = @{$store->fruit_aisle}; - my $avocado = Fruit->new(name => 'avocado', species => 'P. americana'); - push(@fruit_aisle_copy, $avocado); - $store->fruit_aisle( \@fruit_aisle_copy ); - -And here's an example of deleting an object stored in an ArrayRef: - - my @fruit_aisle_copy = @{$store->fruit_aisle}; - # new array to hold the fruit objects that won't be deleted - my @reworked_fruit_aisle; - for my $fruit_obj ( @fruit_aisle_copy ) { - if ( $fruit_obj->name ne 'tomato' ) { - push(@reworked_fruit_aisle, $fruit_obj); - } - } - $store->fruit_aisle( \@reworked_fruit_aisle ); - -Putting the above code into their own object methods would make appending to or deleting from an C a trivial operation. - -=head2 Clearing an ArrayRef - -Assigning C to clear an C will not work because the attribute -was originally defined with a type constraint, meaning that attribute must have -0 or more of that type of value to be valid. C in Perl is not a value, -so it won't work for clearing the C. - -If you assign an empty anonymous hash to a C attribute, this will -clear out that attribute yet still satisfy the type constraint. - - # this clears the ArrayRef - $store->fruit_aisle( [ ] ); - -=head1 SEE ALSO - -=over 4 - -=item L - Subtypes, and modeling a simple Company -class hierarchy - -=item L - Snippets of code for using Types and -Type Constraints - -=item L - Type constraints that Moose can use -and the tools to extend them or create your own. - -=item L - Autoboxed wrappers for Native Perl datatypes - -=item L - Extends attribute interfaces - -=back - -=head1 AUTHOR - -Brian Manning - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006-2008 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - -=cut diff --git a/lib/Moose/Cookbook/Snack/BUILD.pod b/lib/Moose/Cookbook/Snack/BUILD.pod deleted file mode 100644 index f16d075..0000000 --- a/lib/Moose/Cookbook/Snack/BUILD.pod +++ /dev/null @@ -1,134 +0,0 @@ - -=pod - -=head1 NAME - -Moose::Cookbook::Snack::BUILD - Custom initialization methods for Moose objects - -=head1 SYNOPSIS - - package Build::Demo; - use Moose; - - # once the object has been created, don't allow - # changes to 'example_file' - has 'example_file' => (is => 'ro', required => 1); - - sub BUILD { - my $self = shift; - # create the object only if the 'example_file' exists - if (-e $self->example_file) { - return $self; - } - else { - die('ERROR: file _' . $self->example_file . '_ does not exist'); - } - } - - package main; - use Moose; - - # the name of this script, which works - my $first_test = Build::Demo->new(example_file => $0); - # this should fail (unless there's a file named 'foo' - # in the current directory) - my $second_test = Build::Demo->new(example_file => 'foo'); - -=head1 DESCRIPTION - -The C method allows you to write your own initialization methods for -your Moose objects. - -=head2 Creating new objects in Perl and Moose - -By convention, most objects in Perl are created by calling a C method -inside that object: - - package My::Perl::Class; - - sub new { - # object blessing and initialization code goes here... - } - - package main; - my $object = My::Perl::Class->new(); - -Moose is no different in this respect. However, since Moose handles the -C method for you, how do you change the default behaivor of the -C method in Moose? This is what the C method was designed -for. - - package My::Moose::Class; - - sub BUILD { - # object initialization code goes here... - } - - package main; - my $object = My::Moose::Class->new(); - -=head2 Why would you want a custom constructor? - -If your object needs to verify some behaivor or internal state before it is -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 -run it. - -=head2 What is 'BUILDALL'? - -(Taken from L) The C method will call every BUILD -method in the inheritance hierarchy, and pass it a hash-ref of the the -C<%params> passed to the C method. - -=head1 SEE ALSO - -=over 4 - -=item L - The base object for Moose (BUILDALL) - -=item L - Frequently asked questions about Moose -(How do I write custom constructors with Moose?) - -=item L - Subtypes, and modeling a simple -Company class heirarchy (Example usage of BUILD in action) - -=item L - For when things go wrong with Moose -('Roles' section describes BUILD/BUILDALL) - -=back - -=head1 AUTHOR - -Brian Manning - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006-2008 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - -=cut diff --git a/lib/Moose/Cookbook/Snack/HashRef.pod b/lib/Moose/Cookbook/Snack/HashRef.pod deleted file mode 100644 index a6b28fa..0000000 --- a/lib/Moose/Cookbook/Snack/HashRef.pod +++ /dev/null @@ -1,167 +0,0 @@ - -=pod - -=head1 NAME - -Moose::Cookbook::Snack::HashRef - Using the HashRef type constraint - -=head1 SYNOPSIS - - package Fruit; - use Moose; - - has 'species' => ( is => 'rw', required => 1 ); - - package ProduceStore; - use Moose; - use Moose::Util::TypeConstraints; - - has 'fruit_aisle' => ( is => 'rw', isa => 'HashRef[Fruit]' ); - - package main; - use Moose; - - # we need something to put in the fruit aisle - my $orange = Fruit->new( species => 'C. sinensis' ); - my $apple = Fruit->new( species => 'M. domestica' ); - my %fruit = ( orange => $orange, apple => $apple ); - my $store = ProduceStore->new( fruit_aisle => \%fruit ); - -=head1 DESCRIPTION - -The HashRef type constraint is used to store a reference to a Perl hash -variable as an attribute of a Moose object. - -=head2 Disclaimer - -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. 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 - -Once a Moose-based object with a C attribute has been created, you -can pass a hash (by reference) to that attribute using that attribute's -accessor. This is how we assign the apple and orange to the store's -C C attribute, we pass a hash containing both objects by -reference to the C attribute: - - my %fruit = ( orange => $orange, apple => $apple ); - my $store = ProduceStore->new( fruit_aisle => \%fruit ); - -Or you can pass an anonymous hash to the C attribute as well. If you -created two new objects, C<$grape> and C<$tomato>, and assigned them to the -C, they would replace the apple and the orange in the store's fruit -aisle: - - $store->fruit_aisle( { grape => $grape, tomato => $tomato } ); - -Our C C example is parameterized, meaning, that the -C C can contain nothing but C objects as hash -values. If you try to pass in a reference to a hash using C objects as -hash values for example, Moose will complain: - - Attribute (fruit_aisle) does not pass the type constraint (HashRef[Int]) - -=head2 Dumping the contents of the HashRef - -In order to dump the contents of a C object attribute, you must first -de-reference the C, and then enumerate over it's keys. - - foreach my $item ( keys(%{$self->fruit_aisle}) ) { - my $fruit = $self->{fruit_aisle}{$item}; - print "Item: $item, type: " . $fruit->meta->name - . " species: " . $fruit->species . "\n"; - } - -If the above de-referencing of the C C is a little too -noisy, you could create a copy of it, and then enumerate over that copy: - - my %fruit_aisle_copy = %{$self->fruit_aisle}; - foreach my $item ( keys(%fruit_aisle_copy) ) { - my $fruit = $fruit_aisle_copy{$item}; - print "Item: $item, type: " . $fruit->meta->name - . " species: " . $fruit->species . "\n"; - } - -=head2 Assigning to a HashRef attribute will overwrite - -Once you create an object containing a C attribute, if you assign a -new hash reference to that attribute, it will replace any existing hash -reference: - - # this replaces the existing HashRef contents - my $grape = Fruit->new( species => 'V. vinifera' ); - my $tomato = Fruit->new( species => 'S. lycopersicum'); - $store->fruit_aisle( { grape => $grape, tomato => $tomato } ); - -=head2 Appending/Deleting key/value pairs to a HashRef - -In order to append or delete key/value pairs to the hash referred to by the -C attribute, you will need to make a copy of the hash first, add or -delete the desired key/value pairs, then assign your modified copy back to the -C attribute. Here's an example of appending new key/value pars: - - my %fruit_aisle_copy = %{$store->fruit_aisle}; - 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: - - # delete an attribute from the HashRef - %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. - -=head2 Clearing the HashRef - -Assigning C to clear a C will not work because the attribute -was originally defined with a type constraint, meaning that attribute must have -0 or more of that type of value to be valid. B in Perl is not a value, -so it won't work for clearing the C. - -If you assign an empty anonymous hash to a C attribute, this will -clear out that attribute yet still satisfy the type constraint. - - # this clears the HashRef - $store->fruit_aisle( { } ); - -=head1 SEE ALSO - -=over 4 - -=item L - Snippets of code for using Types and -Type Constraints - -=item L - Type constraints that Moose can use -and the tools to extend them or create your own. - -=item L - Autoboxed wrappers for Native Perl datatypes - -=item L - Extends attribute interfaces - -=back - -=head1 AUTHOR - -Brian Manning - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006-2008 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - -=cut diff --git a/lib/Moose/Cookbook/Snack/Keywords.pod b/lib/Moose/Cookbook/Snack/Keywords.pod index 11178a3..a5e9ddb 100644 --- a/lib/Moose/Cookbook/Snack/Keywords.pod +++ b/lib/Moose/Cookbook/Snack/Keywords.pod @@ -4,23 +4,22 @@ Moose::Cookbook::Snack::Keywords - Restricted keywords in Moose -=cut - =head1 DESCRIPTION -There are several keywords exported in L that cause clashes against -any barewords such as attribute names, sub names, and globs. - +There are several keywords exported by L that can cause clashes +against other user-defined barewords. The following document provides +a list of those keywords in a single place for easy reference. =head2 The 'meta' keyword While most of the reserved keywords collisions can be avoided, however -I is the only one you B override. Do not attempt to override -I. +I is the only one you B override. Do not attempt to override +I, it will break the Moose internals. =head2 Moose Keywords -If you are using Moose its best to avoid these keywords +If you are using L or L its best to avoid these +keywords: =over 4 @@ -54,7 +53,7 @@ If you are using Moose its best to avoid these keywords =head2 Moose::Util::TypeConstraints Keywords -If you are using Moose::Util::TypeConstraints its best to avoid +If you are using L its best to avoid these keywords =over 4 @@ -90,43 +89,82 @@ these keywords =back =head2 Avoiding collisions - + =head3 Turning off Moose -To remove the keywords Moose exports using no Moose at the bottom of your code +To remove the keywords L exports just add C at the bottom of +your code, like so: + + package Thing; + use Moose; - package Thing; - use Moose; + # code here - # code here + no Moose; - no Moose; +This will un-export the keywords that L originally exported. The same +will also work for L and L. It is +general L policy that this feature is used. =head3 Sub::Exporter -The L module can rename keywords +L, L and L all use +L to handle all their exporting needs. This means that all the +features that L provides are also available to them. - package LOL::Cat; - use Moose 'has' => { -as => 'i_can_haz' }; +For instance, with L you can rename keywords, like so: - i_can_haz 'cheeseburger' => ( - is => 'rw', - trigger => sub { print "NOM NOM" } - ); + package LOL::Cat; + use Moose 'has' => { -as => 'i_can_haz' }; + + i_can_haz 'cheeseburger' => ( + is => 'rw', + trigger => sub { print "NOM NOM" } + ); + + LOL::Cat->new->cheeseburger('KTHNXBYE'); - LOL::Cat->new->cheeseburger('KTHNXBYE');; +See the L docs for more information. =head3 namespace::clean -You can use L to clean up the namespace +You can also use L to clean up your namespace, but you must +be careful not to remove C with this. Here is an example of that usage: + + package Foo; + use Moose; + use namespace::clean -except => 'meta'; + # ... + +=head1 SEE ALSO + +=over 4 + +=item L -=head1 AUTHOR AND COPYRIGHT +=item L + +=item L + +=item L + +=item L + +=back + +=head1 AUTHOR John Goulah Cjgoulah@cpan.org> -=head1 LICENSE +Stevan Little Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006-2008 by Infinity Interactive, Inc. + +L -This program is free software; you can redistribute it and/or modify -it under the same terms as perl itself. +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. =cut diff --git a/lib/Moose/Cookbook/Snack/Perl5ObjsVsMooseObjs.pod b/lib/Moose/Cookbook/Snack/Perl5ObjsVsMooseObjs.pod deleted file mode 100644 index 2f75e4d..0000000 --- a/lib/Moose/Cookbook/Snack/Perl5ObjsVsMooseObjs.pod +++ /dev/null @@ -1,185 +0,0 @@ - -=pod - -=head1 NAME - -Moose::Cookbook::Snack::Perl5ObjsVsMooseObjs - Short comparison between Perl 5 -objects and Moose objects - -=head1 SYNOPSIS - - package Moose::Demo; - use Moose; # automagically sets 'strict' and 'warnings' - - has 'script_name' => ( is => 'rw', required => 1); - - package main; - - # '$0' is the name of this script, set automatically by Perl - my $demo = Moose::Demo->new( script_name => $0 ); - - print "My name is " . $demo->script_name . "\n"; - print "I am a " . $demo->meta->name . " type of object\n"; - -=head1 DESCRIPTION - -So what's the big stink about Moose? Perl 5 comes with objects and object -oriented programming already. Given the above Moose code, what would similar -code look like in the existing Perl 5 object-oriented style of programming? -Let's take a look and find out... - -=head2 Perl 5 OO Example - - # Perl 5 Object, as taught by the 'perltoot' POD page - package Perl5::Demo; - use strict; - use warnings; - - - sub new { - my $class = shift; - # assign the rest of the method arguments to a temp hash - my %args = @_; - - # create the object out of a blessed hash reference - my $self = bless ( {}, ref($class) || $class ); - # create the script_name attribute - $self->{script_name} = undef; - - # verify that the user passed in the 'script_name' attribute - if ( exists $args{script_name} ) { - $self->script_name($args{script_name}); - } - else { - die "ERROR: can't create object without 'script_name' "; - } - - # return the object reference back to the caller - return $self; - } - - sub script_name { - my $self = shift; - # check for arguments; use the argument - # if passed in, otherwise return the - # existing value (if any) - if (@_) { - $self->{script_name} = shift; - } - return $self->{script_name}; - } - - package main; - use strict; - use warnings; - - my $demo = Perl5::Demo->new( script_name => $0 ); - - print "My name is " . $demo->script_name . "\n"; - print "I am a " . ref($demo) . " type of object\n"; - -Looks more complex, right? Moose does a lot of the labor when working with -Perl objects, so that you don't have to. What are some of the specific -differences between Moose and Perl 5 Objects? - -=head3 Difference #1 - declaration of object attributes - -Both the Moose and Perl 5 objects have one attribute, C. It's a -good programming practice to always validate user input, so we have the Perl 5 -object check to make sure that the user passes in the C attribute -to it when the object is created. The Moose object automatically checks this -for us when we set C 1> in the C function for the Moose -object. - -In more advanced Moose usage, you can use something called 'type constraints' -when creating your Moose objects. Type constraints are used to validate what -the user passes in when setting Moose object attributes. If the user passes -in a type of data that Moose is not expecting, then the type constraints in -Moose (specifically, the L module) will let the -user know this in no uncertain terms. Type constraints in Moose can be as -simple as strings or numbers, or as complex as other Moose objects. - -=head3 Difference #2 - strict and warning pragmas - -Moose sets the 'strict' and 'warnings' pragmas for you automatically. We have -to do this for ourselves in the Perl 5 example. - -=head3 Difference #3 - Determining an object's class name - -The C function in Perl 5 is how you determine an object's class name. -The proper way to do this with Moose is C<$object-Emeta-Ename>; - - # an object's class name in Perl 5 OO - print "I am a " . ref($demo) . " type of object\n"; - - # an object's class name in Moose - print "I am a " . $demo->meta->name . " type of object\n"; - -Moose builds on C to provide a rich introspection API that -goes way beyond just getting the class name. Check out the -C documentation for more details. - -=head3 Difference #4 - Assigning values to Moose object attributes - -When you wish to assign a value directly to an object attribute for a Perl 5 -object, you can either create an object method that handles the value for you; - - package Perl5Object; - sub set_x { # some code here that sets 'x' } - package main; - # later on... - $self->set_x(0); - -or you can assign the value directly to the Perl 5 object attribute like this: - - $self->{x} = 0; - -Moose creates object methods for handling attributes for you, as long as you -specified C rw> for each C statement inside the object -declaration. This is mentioned in L, in the section -labeld B, but briefly: - - package MooseObject; - has 'x' => (is => 'rw'); - package main; - # later on... - $self->x(0); - -The syntax shown for the Perl 5 object (C<$self-E{x} = 0>) will -also work on the Moose object, as Moose objects are, by default, -blessed hashes just like the average Perl object is. However, if you -access the object's hash reference directly via the latter syntax you -will have several problems. - -First, Moose will no longer be able to enforce attribute constraints, -such as read-only or type constraints. Second, you've broken that -object's encapsulation, and encapsulation is one of the reasons you -want to use objects in the first place, right? - -=head1 SEE ALSO - -=over 4 - -=item L - The 'Point' object example - -=item L - Type constraints that Moose can use -and the tools to extend them or create your own. - -=item L - For when things go wrong with Moose - -=back - -=head1 AUTHOR - -Brian Manning - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006-2008 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - -=cut diff --git a/lib/Moose/Cookbook/Style.pod b/lib/Moose/Cookbook/Style.pod index 160ac2a..9530472 100644 --- a/lib/Moose/Cookbook/Style.pod +++ b/lib/Moose/Cookbook/Style.pod @@ -186,3 +186,17 @@ you are using. This will improve your code and also share the benefit with others. +=head1 AUTHOR + +Yuval (nothingmuch) Kogman + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006-2008 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut