Angharad has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Moose: does not export its sugar to the 'main' package
by ikegami (Patriarch) on Jun 29, 2010 at 16:37 UTC | |
by merlyn (Sage) on Jun 29, 2010 at 17:12 UTC | |
by toolic (Bishop) on Jun 29, 2010 at 17:24 UTC | |
|
Re: Moose: does not export its sugar to the 'main' package
by Anonymous Monk on Jun 29, 2010 at 17:51 UTC |