X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FCookbook%2FStyle.pod;h=67da29dbafa2c7923521d52d53385e00e76efe9c;hb=bb6c833559f9e6ac403628d8ec4d09af2a0477e1;hp=4a28aaaf5a85683ed185b2fb6896c734a878d919;hpb=9632a49e67c27a6dd37947a3858a2f25d4d02574;p=gitmo%2FMoose.git diff --git a/lib/Moose/Cookbook/Style.pod b/lib/Moose/Cookbook/Style.pod index 4a28aaa..67da29d 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 subclassible, it keeps this logic independent of the other aspects of construction, and can be made efficient using C. @@ -125,15 +127,19 @@ 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") }, ); +=head3 Coerce in a subtype + Likewise use fully qualified subtypes of other types for defining coercions, so that they won't affect unrelated code, causing action at a distance. @@ -155,6 +161,44 @@ 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 + +Use C or C to remove the sugar exports. + +This will make sure the sugar isn't accidentally called as methods on your objects. + +For instance: + + $obj->can("has"); + +will return true, even though C is not a method. + +=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-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