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:
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.
Heres the relevant code. Any pointers in the right direction appreciated!!!
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;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.