Do I need to specify "use Moose" in every package I define in that .pm file?

I'd say so. use Moose; will, among other things, import functions like has into the current package, and although I'm sure there are ways to be tricky about it, IMO the best thing really is to put a use Moose; in every package using it.

All those "our" declarations and the "require", generated by h2xs

It depends, OO modules usually don't export stuff as well, so personally I would remove the require Exporter; and the our declarations, except for our $VERSION.

Also, note that it's usually considered good practice to only have one package per file. Since Moose also turns on strict and warnings, the bare minimum you need in a .pm file using it is:

package Foo::Bar; use Moose; # your code here 1;

(The use 5.022; might be helpful because it turns on the 5.22 feature bundle, if you're sure you want to limit the minimum Perl version to that.)


In reply to Re: Moose in a module created with h2xs by haukex
in thread Moose in a module created with h2xs by rpaskudniak

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.