I'm trying the following code from Programming Perl, but I'm get the 
error "Can't call method "type" on unblessed reference at untitled text 10 line 
23".  I've checked the errata page, but there's nothing listed for it.  
Searching on the error message brings up pages about unblessed references, but 
I can't make heads or tails out of them.  Does anyone know what the problem is?

Thanks,
Marc


use v5.14;
use strict;
use warnings;

package Stables 1.01 {
    use Moose;
    has "animals" => (
        traits  => ["Array"],
        is      => "rw",
        isa     => "ArrayRef[Animal]",
        default => sub { [] },
        handles => {
            add_animal  => "push",
            add_animals => "push",
        },
    );
    sub roll_call {
        my($self) = @_;
        for my $animal($self->animals) {
            say "Some ", $animal->type,
                " named ", $animal->name,
                " is in the stable";
        }
    }
}

package Animal 1.01 {
    use Moose;
    has "name" => (
        is       => "rw",
        isa      => "Str",
        required => 1,
    );
    has "type" => (
        is      => "rw",
        isa     => "Str",
        default => "animal",
    );
}

my $stables = Stables->new;

$stables->add_animal(
    Animal->new(name => "Mr. Ed", type => "horse")
);

$stables->add_animals(
    Animal->new(name => "Donkey",   type => "donkey"),
    Animal->new(name => "Lampwick", type => "donkey"),
    Animal->new(name => "Trigger",  type => "horse" ),
);

$stables->roll_call;
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to