X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FCookbook%2FStyle.pod;h=1e5059bdcdbe784ff15e3208b47fbbcff97bb98d;hb=ec6df2e6d65a0dd6edb94c5f4645ff8cc8f5af4a;hp=b29b4d939556b924da36eed969c2d136b83e5652;hpb=d9fa4da96da2cda64ccfd28024a66ea53e4397f1;p=gitmo%2FMoose.git diff --git a/lib/Moose/Cookbook/Style.pod b/lib/Moose/Cookbook/Style.pod index b29b4d9..1e5059b 100644 --- a/lib/Moose/Cookbook/Style.pod +++ b/lib/Moose/Cookbook/Style.pod @@ -2,11 +2,12 @@ =head1 NAME -Moose::Cookbook::Style - How to cook Moose with style +Moose::Cookbook::Style - The latest in trendy Moose cuisine =for authors -Please annotate all bad examples with comments so that they won't be copied by accodent +Please annotate all bad examples with comments so that they won't be copied by +accident =cut @@ -93,8 +94,9 @@ the C to C instead of overwriting it in C. =head2 Use C to alter C<@_> processing -If you need to change the way L<@_> is processed, use C, instead of -wrapping C. This ensures the behavior is subclassible, it keeps this logic +If you need to change the way C<@_> is processed, for example for +C<< Class->new( $single_param ) >>, use C instead of wrapping +C. This ensures the behavior is subclassable, it keeps this logic independent of the other aspects of construction, and can be made efficient using C. @@ -125,12 +127,14 @@ Instead, prefix type name with your project namespace, or class name: Or with L: + use MooseX::Types::Moose qw(Object); + use MooseX::Types ( -declare => [qw(Person)], ); subtype Person() => ( # note parenthesis, "Person" is a function, not a string - as 'Object', + as Object, # MooseX::Types::Moose exported it where { $_->can("name") }, ); @@ -157,7 +161,7 @@ Will add a coercion to B attributes like: coerce => 1, ); -in a specific way. +when the actual coercion applies only to your specific cases. =head1 Clean up your package @@ -171,4 +175,35 @@ For instance: will return true, even though C is not a method. +If you choose L, make sure to keep the C method if you +want to use it for introspection: + + use namespace::clean -except => "meta"; + +=head1 Accept no substitutes + +By substitutes I mean hacks instead of "proper" solutions. + +When you have a tricky requirement, refrain from abusing Moose or MooseX:: or +whatever it is you are using. + +Instead, drop by IRC and discuss it. Most of the time a crazy idea can either +be simplified, or it will spawn a clean, reliable feature to whatever package +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-2009 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