Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Exporting

by chipmunk (Parson)
on Dec 13, 2000 at 02:57 UTC ( [id://46342]=note: print w/replies, xml ) Need Help??

in reply to Exporting
in thread Module Submission for CPAN

Here's a quick, off-the-cuff explanation of exporting/importing:

First, exporting and importing are the same thing; like emigrating/immigrating, it just depends which side you're looking from. :)

Exporting/importing is simply the process of making a link from a symbol (or part of a symbol) in one package to a symbol in another package, so that the symbol can be accessed from either package. For example, if you import CPAN's install method, then CPAN exports it (by using Exporter) with this assignment: (*{"${callpkg}::$sym"} = \&{"${pkg}::$sym"}. That actually makes an assignment to the symbol table for the calling package. Assuming $callpkg is main, now main::install and CPAN::install refer to the same subroutine. The \& on the RHS of the assignment means that only the subroutine part of the CPAN::install symbol was duplicated; the scalar, array, hash, and other parts were not. Exporter does separate assignments for each data type, so that only what was asked for is imported.

The reason for exporting/importing is simply to make accessing symbols in other packages easier, by bringing them into your package. Someone using the functional interface to CGI, for example, would have to write out CGI::header(), CGI::start_html(), CGI::param(), etc., for every function, if they couldn't import the methods.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2024-05-28 14:50 GMT
Find Nodes?
    Voting Booth?

    No recent polls found