API for import?

K

kj

Where can one find good documetation on the API for the import
function and whatever other information one must know to write
one's own import function? (Neither 'perldoc -f import' and pointers
therein, nor reading the Export.pm source code were particularly
illuminating on this question.)

Thanks!

kj
 
B

Ben Morrow

kj said:
Where can one find good documetation on the API for the import
function and whatever other information one must know to write
one's own import function? (Neither 'perldoc -f import' and pointers
therein, nor reading the Export.pm source code were particularly ^^ er
illuminating on this question.)

perldoc -f use
perldoc perlmod

Think carefully before you start though: is it *really* necessary to
write your own? Exporter covers most cases...

Ben
 
B

Brian McCauley

kj said:
Where can one find good documetation on the API for the import
function

When you write your own import() you get to define your own API!

In older versions of Perl you needed to do version checking but
this is now handled by a separate VERSION method.

Old modules' import() still may need keep the legacy version checking
code to support the legacy syntax:

use Module VERSION, LIST

New modules don't need to worry about this as new code will use one of:

use Module VERSION LIST
use Module VERSION

This means you have a completely free hand in your import's API.
and whatever other information one must know to write
one's own import function?

You need to know what you want it to do. You have to supply that
information yourself.
(Neither 'perldoc -f import' and pointers
therein, nor reading the Export.pm source code were particularly
illuminating on this question.)

I'm not quite sure what "this question" is. I suspect it doesn't
really exist, you only imagine it does. Getting answers to questions
whose existanve you are imagining is often very difficult.

That said you may also want to consult:

perldoc -f use
perldoc perlmod

The only bit I found unclear was how Perl manages to DWIM for both:

use Module VERSION
use Module LIST [where LIST contains a single element]

From experimentation it seems that if the abiguous argument is a
number literal or a version literal it is seen as VERSION otherwise
it's seen as LIST. Which seems right from a DWIM standpoint.

If you want to force something that would usually
be treated as a VERSION to be treated as sigle element LIST the
parentheses or a unary plus seem to do the trick.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top