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;

In reply to Moose: does not export its sugar to the 'main' package by Angharad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.