Module design question (use Exporter vs require Exporter) 
Author Message
 Module design question (use Exporter vs require Exporter)

I've seen various module authors use the following constructs (not
simultaneously!):

use Exporter;

and also

require Exporter;

My questions are:

What is (if any) the difference (besides the documented compile-time vs.
run-time semantic differences) between the two usages?

Why would I want to use one form instead of the other for a module I am
authoring?

--
# Michael King

# To reply, remove the NOSPAM_ in the address in the line above
# Or, check out my WWW site at:
# http-colon-slash-slash-walden-dot-mo-dot-net-slash-tilde-mike808
#
# These are my views and do not necessarly reflect those of anyone else.
#
# Copyright 1998 Michael King. St. Louis, MO USA
# Internet repost/archive freely permitted.
# Hardcopy newspaper, magazine, etc. quoting requires permission.
==================================================================
By US Code Title 47, Sec.227(a)(2)(B), a computer/modem/printer
meets the definition of a telephone fax machine. By Sec.227(b)
(1)(C), it is unlawful to send any unsolicited adverti{*filter*}t to
such equipment, punishable by action to recover actual monetary
loss, or $500, whichever is greater, for EACH violation.
==================================================================



Fri, 21 Jul 2000 03:00:00 GMT  
 Module design question (use Exporter vs require Exporter)


<What is (if any) the difference (besides the documented compile-time vs.
<run-time semantic differences) between the two usages?

Well, perldoc -f use says

Imports some semantics into the current package from the named module,
generally by aliasing certain subroutine or variable names into your
package.  It is exactly equivalent to

    BEGIN { require Module; import Module LIST; }    

<Why would I want to use one form instead of the other for a module I am
<authoring?

When I write a module, I rely on h2xs to produce a stub that I can complete.

63  5:51    h2xs -XAfn Foobar
64  5:51    cd Foobar/
65  5:51    more Foobar.pm  

And it spits out require.

HTH,
Eric
--
Eric D. Friedman



Sat, 22 Jul 2000 03:00:00 GMT  
 Module design question (use Exporter vs require Exporter)

Quote:

> I've seen various module authors use the following constructs (not
> simultaneously!):

> use Exporter;

> and also

> require Exporter;

> What is (if any) the difference (besides the documented compile-time vs.
> run-time semantic differences) between the two usages?

Well the "use" will additionally try to import names into your
package.  If you don't want to import any names from a module named
"Module" then do this:

    use Module ();

For more info, see the perlfunc man page for use().

Quote:
> Why would I want to use one form instead of the other for a module I am
> authoring?

From the user's perspective it probably doesn't matter since they'll
invoke your module via a use which means any "use" or "require" you
have in your module will happen at compile-time.

Stylistically, I think most choose "use" over "require".

--
Jay Rogers



Sat, 22 Jul 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Module design question (use Exporter vs require Exporter)

2. Using Exporter

3. using Exporter

4. Using Exporter...

5. Using Exporter under Win32 PRK

6. ANN: module Exporter::VA

7. module "Exporter.pm"

8. Exporter, strict, and module "my" variable

9. Basic Exporter question

10. Exporter question

11. Exporter/package question

12. Exporter Question

 

 
Powered by phpBB® Forum Software