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

Re: Issue with Exporter

by ferreira (Chaplain)
on Jan 11, 2007 at 13:23 UTC ( [id://594146]=note: print w/replies, xml ) Need Help??


in reply to Issue with Exporter

Don't forget to say

use strict; use warnings;
at the beginning of your modules and scripts, unless you have a very good reason not to do it.

Probably, method1 from one.pm is not getting called, but instead a stub that does nothing -- this is a "goodness" of not using strict (a promiscuous way to being too forgiven with unresolved symbols).

You will realize that if use strict; use warnings; were added, this will work as you expect, printing "its heremethod1 greets hellohere". But it is not right yet. The remaining issue is that to tell a package is inheriting the exporter capabilities from Exporter, you need

require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(method1);

The require statement will load Exporter.pm for you. (And our will be need if you're "strict".) Why does it work only inserting use strict; use warnings; in two.pl? Because some of these load Exporter and it becomes accessible as a side effect to the remaining of the script. This is not a thing to rely on. So I suggest you do the right thing: being strict, calling for warnings, requiring what you need. This will work always, not sometimes.

Replies are listed 'Best First'.
Re^2: Issue with Exporter
by palette (Scribe) on Jan 11, 2007 at 13:35 UTC
    It works. Thankyou. I shud adhere to the rules of being strict and use warnings.

    I would like to know why it is not working with use and working with require. Anyway use is require and import together right.

    Thanks

      It works for me with use Exporter; instead of require Exporter;. The point is that use'ing is not necessary when what you want is to inherit from Exporter in package one.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-03-28 09:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found