Angharad has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I've been trying to teach myself Moose today and am following a tutorial.
However, I've come across this error and can't find any explanation as to what it means:
However, I've come across this error and can't find any explanation as to what it means:
Heres the relevant code. Any pointers in the right direction appreciated!!!Mouse does not export its sugar to the 'main' package. Can't locate object method "new" via package "Mouse" at test.pl line 2 +2.
package Animal; use Moose::Role; has 'name' => (is => 'rw'); has 'color' => (is => 'rw', default => sub { shift->default_colour }); requires 'default_colour'; sub speak { my $self = shift; print $self->name, " goes ", $self->sound, "\n"; } # sub sound { confess shift, " should have defined sound!"; } requires 'sound'; no Moose::Role; 1;
package Mouse; use Moose; with 'Animal'; sub default_colour { 'white'; } sub sound { 'squeak'; } after 'speak' => sub { print "[but you can barely hear it!]\n"; }; no Moose; 1;
#!/usr/local/bin/perl -w use strict; use Moose; use Animal; use Horse; use Sheep; use Mouse; my $talking = Horse->new(name => 'Mr. Ed'); $talking->speak; # says "Mr. Ed goes neigh" my $baab = Sheep->new(colour => 'white', name => 'Baab'); $baab->speak; # prints "Baab goes baaaah" my $mickey = Mouse->new(name => 'Mickey'); $mickey->speak;
Back to
Seekers of Perl Wisdom