Think that the object is oriented here.
Think of the exporter not as a module, but as a class. Think of ISA as the meaning of "is", as in "My module is a subclass of the exporter class ."
What you do declares your module as a subclass of the Exporter class, which means that you can use the import method of the Exporter class, which is useful.
In order to really explain what Exporter does, you must understand that Perl uses a namespace. Imagine that your program has a variable 1 called $total , but also the module you are using. Your $total variable will interfere with the $total module variable.
To prevent this, Perl uses namespaces. Your program runs in the default namespace main . Your modules use the package function to declare a new namespace. Now you and your module can safely use a variable called $total . In your program, this is really $main::total , and in the package it is $ Package :: Name :: total . If you want to use something from one _namespace_ in another, you can prepend the _namespace_ on it. Think of the . If you want to use something from one _namespace_ in another, you can prepend the _namespace_ on it. Think of the . If you want to use something from one _namespace_ in another, you can prepend the _namespace_ on it. Think of the $ File :: Find :: name and $ File :: Find :: dir variables you have when you use File :: find`.
What the Exporter import method does is copy your routines (and if you wish, your variables) from your namespace to the current namespace. Imagine that you are using the File::Copy module without the ability to copy the copy routine to the main namespace. You can use it anyway, but you need to specify the namespace name on it:
use File::Copy; ... File::Copy::copy( $from_file, $to_file );
Thanks to Exporter (and the import method), any routines that you put in your @EXPORT package @EXPORT are copied to the current namespace. Thus, you can access the File :: Copy s copy` routine as follows:
use File::Copy; ... copy ( $from_file, $to_file );
This is why you should declare all of these variables as our , not my . my variables are lexically limited and cannot be accessed outside of where they are declared. Package variables (e.g. $File::Find::name ) may be. For Exporter , to find the @EXPORT and @EXPORT_OK , they must be package variables.
Now it becomes desirable to export functions ...
The oldest modules that we know and love export routines are perforce. You use File :: Copy, File :: Path, File :: Find and have immediate access to their routines. This is because they put their routines in the @EXPORT array. This was once considered desirable because it immediately provided you with these features.
Newer modules, such as File::Temp , require declaring the routines you want to import:
use File::Temp qw(tempdir); ... my $temp_dir = tempdir;
If I did not have this qw(tempdir) , I could not use the tempdir function.
This is considered polite. The module asks for your permission to import this feature. This is done by putting the routines in @EXPORT_OK . They will be exported only upon request.
This is better because you do not need to import everything, just what you need. And you document where these functions are defined.
Object-oriented modules do not export anything and do not require the use of Export. This has been a long time since I wrote a module that uses Exporter.
- 1 Here we are talking about package variables. Package variables are visible everywhere.