Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Modules 101 :: Using a Local Module from CPAN

by GrandFather (Saint)
on Dec 07, 2022 at 02:36 UTC ( [id://11148634]=note: print w/replies, xml ) Need Help??


in reply to Modules 101 :: Using a Local Module from CPAN

Just to elaborate a little on hippo's reply, when you use SomePackage;, you aren't "running the SomePackage script", you are effectively including the source code for SomePackage in your own script. There is more magic that goes on than that, but the essence is that SomePackage packages up some Perly goodness for you and makes it easy to use from your script.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^2: Modules 101 :: Using a Local Module from CPAN
by stevieb (Canon) on Dec 07, 2022 at 04:51 UTC

    What GrandFather said. My code isn't a script. In Perl parlance, it's a module. In general programming parlance, it's a library.

    In Perl, a script is something that is executed; ie. a 'binary'. A module is something that is loaded into the script, and you can use its functionality via its Application Programming Interface (ie. API). We include a library in perl script by use of the use or require "pragma". Other programming languages have similar techniques, named differently (eg. 'import', 'include' etc).

    In this specific module (Script::Singleton), things are a bit different. There is no API. Just by loading (ie. 'use') the module, all of its functionality is executed inline during the compile phase of the script build. If you're interested, I wrote an explanation of the build/run phases of a perl script many years ago. I can't vouch for how good it is though as I've not time to read it right now ;)

    OP: you're coming far young grasshopper. Keep up the good work.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11148634]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-26 06:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found