Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Dear Moose docs...

by 7stud (Deacon)
on Feb 10, 2013 at 03:59 UTC ( #1018018=perlquestion: print w/ replies, xml ) Need Help??
7stud has asked for the wisdom of the Perl Monks concerning the following question:

You are really quite sucky. Why? Well, you start out with a nice simple example, which is good. However, you don't show any code that uses the bright, shiny new classes. This is what I tried:

use strict; use warnings; use 5.012; package Point; use Moose; # automatically turns on strict and warnings has 'x' => (is => 'rw', isa => 'Int'); has 'y' => (is => 'rw', isa => 'Int'); ############ my $p = Point->new(10, 20); say $p->x; say $p->y; --output:-- Use of uninitialized value in say at 2.pl line 44. Use of uninitialized value in say at 2.pl line 45.

Hmmm...how do you call the accessor methods? The Moose docs direct beginners to Moose::Manual. Hey, more of the same in Moose::Manual: class definitions, and no code that creates an object and calls the object's accessor methods. Great! Okay, let's check google for Moose tutorials. Hey, none of the top 1,000 hits includes code that creates an object and calls the object's accessor methods. What about Moose::Cookbook. Nothing!!!

Sorry docs. Please track down Lincoln Stein, and pay him whatever it takes.

Comment on Dear Moose docs...
Download Code
Re: Dear Moose docs... (tired)
by Anonymous Monk on Feb 10, 2013 at 04:04 UTC

    Are you people that out of touch??

    Its not that I disagree with your viewpoint, but I do recognize, its time for a break :)

Re: Dear Moose docs...
by 7stud (Deacon) on Feb 10, 2013 at 04:06 UTC
    I'm still editing and trying to aquire the right tone. :(
Re: Dear Moose docs...
by chromatic (Archbishop) on Feb 10, 2013 at 04:13 UTC
    how do you call the accessor methods?

    Just as you did. The interesting question the documentation hasn't made clear to you is "How do I initialize attributes when I call the constructor?":

    my $p = Point->new( x => 10, y => 20 );

    The Objects chapter in the Modern Perl book may be a more gentle (and complete) introduction to Moose.

Re: Dear Moose docs...
by Your Mother (Canon) on Feb 10, 2013 at 05:10 UTC

    One wonders how much documentation it would take-

    use strict; use warnings; ... use Moose; # automatically turns on strict and warnings

    Not to be snarky, just 'cause it was hanging down.

    Moose doesn't aim to teach OO but to be a platform for it. Reading Conway's OO book or looking for general Perl OO tutorials would probably eliminate the lack of clarity, which I never noticed but can understand once someone else points it out.

    In FOSS you're not gonna find much play in UR TEH SUCK. Better to say, I wanted to do X, I failed to find how in Y, if Z were there or you can point me to it, I'd love that!

      Moose doesn't aim to teach OO

      indeed, but the OPs question falls under how-to use moose, not oo

        Oh, I know but the weakness in the docs was a complete surprise to me because I have the POOP background, heh-heh, heh-hehÖ To someone who has that context, the docs donít need help at all. Fresh eyes were needed to expose it. Friendly eyes would be more likely to rope a sucker like me into Pod edits and pull requests.

Re: Dear Moose docs...
by tobyink (Abbot) on Feb 10, 2013 at 08:51 UTC

    You're right that the docs are a little sparse in that area. There are some examples though - Moose::Manual::Attributes, Moose::Cookbook::Basics::Point_AttributesAndSubclassing, Moose::Cookbook::Basics::BankAccount_MethodModifiersAndSubclassing, etc. If you don't think this is enough, please submit a bug report.

    Out of the box, Moose supports two styles of object construction:

    # Key-value pairs my $point1 = Point->new(x => 10, y => 20); # Hashref my $point2 = Point->new({ x => 10, y => 20 });

    In your class it's possible to override BUILDARGS to add your own argument parsing...

    use v5.12; { package Point; use Moose; has 'x' => (is => 'rw', isa => 'Int'); has 'y' => (is => 'rw', isa => 'Int'); around BUILDARGS => sub { my $orig = shift; my $self = shift; # Allow object to be built by passing two integers... if (@_ == 2 and $_[0] =~ /^[0-9]+$/ and $_[1] =~ /^[0-9]+$/) { return { x => $_[0], y => $_[1] }; } # If not two integers, then fall back to standard Moose BUILDA +RGS... return $self->$orig(@_); }; __PACKAGE__->meta->make_immutable; } # Use our overridden BUILDARGS... print Point->new(10, 20)->dump; # Standard Moose BUILDARGS is fallback... print Point->new(x => 10, y => 20)->dump; print Point->new({ x => 10, y => 20 })->dump;
    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re: Dear Moose docs...
by moritz (Cardinal) on Feb 10, 2013 at 09:16 UTC

    Your rant would be much better placed in Moose's bug tracker, preferrably with a patch attached that improves the docs. Then those people who actually work on Moose would read it, not us "innocent bystanders".

    And it would have the advantage of possibly having a positive effect.

      Your rant would be much better placed in Moose's bug tracker, preferrably with a patch attached that improves the docs.

      How would OP write a patch when OP didn't know the answer?

        The OP could have started reading the Moose test suite to find out, or any working example code in the wild that uses Moose.

        But I don't always expect this level from involvement, which is why I wrote "prefferably", to make it clear it's not a requirement.

        > How would OP write a patch when OP didn't know the answer?

        Asking here, but friendly and constructive and w/o ranting.

        Free software depends on collaboration and not on a "I want my money back" attitude.

        Cheers Rolf

Re: Dear Moose docs...
by syphilis (Canon) on Feb 10, 2013 at 11:23 UTC
    I ... ummmm ... actually work in the dairy industry.
    Take it from me ... you should *all* acquire more Moo stocks !!

    ;-)

    Cheers,
    Rob
Re: Dear Moose docs...
by sundialsvc4 (Abbot) on Feb 10, 2013 at 19:34 UTC

    Why not put your editorial money where your mouth is, and offer a patch to the Perldocs?   Create a document and submit it to the powers-that-be who are maintaining the package.   I’m sure that they would love the help.   Good writers are hard to find.   The only ones who can make Perl better than it is are, “us folks.”   You certainly won’t be the only person who shares your particular difficulty with the documents, but if you write from your point of view the material that you wish you could have read ... the next person who also thinks like you do, thanks to you, won’t have to repeat your negative experience.

Re: Dear Moose docs...
by jmlynesjr (Pilgrim) on Feb 11, 2013 at 01:49 UTC

    The Class::Accessor POD has examples also.

    James

    There's never enough time to do it right, but always enough time to do it over...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1018018]
Approved by bulk88
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-10-25 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (143 votes), past polls