Puppy meta data gets read in from config file using (General::Config) and creates this hash of hashes
$puppy_hashes = {
puppy_blue => { name => 'charlie', age => 4 },
puppy_red => { name => 'sam', age => 9 },
puppy_yellow => { name => 'jerry', age => 2 },
puppy_green => { name => 'phil', age => 5 },
}
the MotherDogRobot package consumes the puppies hash to birth an array of puppy objects (lol)
package MotherDogRobot;
use Moose;
use Puppy;
use Data::Dumper;
#moose includes warn and strict
sub init_puppy{
my($self,%options) = @_;
my $puppy = Puppy->new( %options );
return ($puppy);
}
sub birth_puppies{
my($self,$puppy_hashes) = @_;
my @keys = keys %{$puppy_hashes};
my @puppies = map { $self->init_puppy( $puppy_hashes->{$_} ) } @keys;
return(@puppies);
}
sub show_me_new_puppies{
my($self,$puppy_hashes) @_;
print Dumper($self->birth_puppies($puppy_hashes));
}
Error odd number of arguments
passing %options to Puppy->new(%options)
no luck birthing puppies — which means I can’t put lasers on their heads =/
UPDATE
I think the problem is that I’m passing a Hash Ref to init_puppy() instead of an array or hash, so when I try to pass %options to the new constructor, it’s not getting a proper ( key => value) pair — hence the odd number of arguments error.
But from this standpoint I’ve been looking at this code too long I cant figure out how to dereference this properly.
btw this is my official day 22 of using Perl!
you’re using empty variables as if they’re not empty, that is, you’re not doing anything at all
This assumes that the incomplete snippet you’ve shown is what you’re really using
update: Similarly in sub init_puppy, you never initialize
my($self,%options)=@_;