Perl always expects each :: in a module name to translate to a path separator in the directory hierarchy. So for the module Script::Singleton it will look for the file Singleton.pm in a subdirectory named Script underneath one of the directories specified in @INC.

So if you want to reference it from /home/demo/pullWorkload/scpLRSIControllerDir/toys, you need to create /home/demo/pullWorkload/scpLRSIControllerDir/toys/Script (with mkdir), and put the file Singleton.pm in that directory.

I would recommend this as a temporary solution only. For CPAN modules it is almost always preferable to keep them in a separate place - see other people's suggestions for how to do that.

The handling of :: in module names is not trivial to find in the documentation. From perldoc -f use you will see that use Script::Singleton; is exactly equivalent to BEGIN { require Script::Singleton; Script::Singleton->import(); }. You then need to understand that since Script::Singleton is not in quotes, it is what perl calls a "bareword", and then find the part of perldoc -f require that describes this:

If EXPR is a bareword, "require" assumes a .pm extension a +nd replaces "::" with "/" in the filename for you, to make it + easy to load standard modules.

In reply to Re^3: Modules 101 :: Using a Local Module from CPAN by hv
in thread Modules 101 :: Using a Local Module from CPAN by redapplesonly

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.