in reply to Re: Help!!!! POOP is confusing me!
in thread Help!!!! POOP is confusing me!

Hey there, thank you all for your answers, i was not sure if variables where stored as references in the class or not, and i was trying to store an array into a scalar value containing the reference, the result was that i was storing the size of the array.
push @{ $self->{farmBirds} }, @_;
was what i should have been writting

Also returning it i ended up returning the reference (which ended up being the size of the array), instead of returning it like   return @{ $self->{farmBirds} };

As for Moose it seems to be making object creating and handling much easier, but what troubles me is that it does not seem to be following a c++/java style of handling objects which programers coming from such languages might be used to, i ll play around with it though

Thank you for all your help

Replies are listed 'Best First'.
Re^3: Help!!!! POOP is confusing me!
by stvn (Monsignor) on Jul 16, 2008 at 15:49 UTC
    As for Moose it seems to be making object creating and handling much easier, but what troubles me is that it does not seem to be following a c++/java style of handling objects which programers coming from such languages might be used to, i ll play around with it though

    Not following the C++/Java way is a good thing IMO. Moose strives to be more Perl-ish and is derived largely from the Perl 6 spec (along with contributions from other languages such as Ruby, OCaml, Java, etc). Here is what your code looks like in Moose

    package Farm; use Moose; has 'farmName' => ( is => 'rw', isa => 'Str', default => sub { "" }, ); has 'farmBirds' => ( is => 'rw', isa => 'ArrayRef', default => sub { [] }, ); has 'farmMammals' => ( is => 'rw', isa => 'ArrayRef', default => sub { [] }, ); 1;
    When you call Farm->new everything will be initialized for you and so you can start writing code with thart object right away, like so:
    my $farm = Farm->new; $farm->farmName('Old Mac Donald'); push @{$farm->farmBirds} => 'Chicken'; push @{$farm->farmMammals} => 'Pig';
    You can even initialize the attributes on your own from the constructor, like so:
    my $farm = Farm->new( farmName => 'Old Mac Donald', farmBirds => [ 'Chicken', 'Duck' ], farmMammals => [ 'Pig', 'Cow' ], );
    The core goal of Moose is to take the tedium out of Perl 5 OOP (which you actually commented on in your original post) by making Perl OOP less about coding the mechanisms of OOP and more about creating the objects and modeling your problem domain.

    -stvn