Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: What I Most Recently Learned in Perl, But Should Have Already Known

by graff (Chancellor)
on Mar 18, 2007 at 00:05 UTC ( #605318=note: print w/replies, xml ) Need Help??

in reply to What I Most Recently Learned in Perl, But Should Have Already Known

Cool thread. My latest revelation was about Exporter. I've written some modules that don't need it at all, and I've written some that do need it, in order for a caller script to just use a given function. But it wasn't till a few days ago that I finally learned (or figured out / absorbed / understood) what the difference is between needing Exporter vs. not needing it:

The ones that didn't need Exporter were OO-style; the "ModuleName->new()" or "new ModuleName" method never needs to be explicitly exported, and the returned object reference provides the caller with simple and direct access to the module's methods.

The modules that aren't OO-style don't supply that sort of handy object reference, so Exporter is needed in order for the module's function names to be accessible to the caller without the clunky "ModuleName::" prefix.

At least, that's how I've come to understand it (finally). I must have known some part of this before (when writing those OO-style modules), but it turns out I don't write modules all that often, and I actually did scratch my head a bit recently when writing a simple "functions-only" module, trying to recall what incantation to use involving Exporter, and seeing that some of my older modules didn't use it at all (yet these never needed the "ModuleName::" syntax when being used).

I attribute my surprise to my habitually "procedural" mindset, which Perl supports so effectively.

  • Comment on Re: What I Most Recently Learned in Perl, But Should Have Already Known

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://605318]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2018-02-21 16:20 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (283 votes). Check out past polls.