Hello Ukhas,
 
When a module uses the exporter module, it can use the following syntax:
 
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw( mysubA mysubB $myvar1 $myvar2 );
our @EXPORT_OK = qw( myOnlyOnRequestSubA myOnlyOnRequestSubB );
our %EXPORT_TAGS = (
  all => [ qw( subA subB subC subD subE subF ) ],
  html => [ qw( subHTMLA subHTMLB subHTMLC ) ]
);
 
In the previous example you can note the following points:
 
1. All subs and variables specified in @EXPORT, will be automatically imported into the script calling the module.
2. Subs and variables specified in @EXPORT_OK will be imported into the script calling the module ONLY if they are called like this: use mymodule qw( myOnlyOnRequestSubA ), importing only the ones specified.
3. %EXPORT_TAGS allows you to set groups of subrutines and variables so you can call a group instead of every element of it, like this: use mymodule qw(:all :html), importing into the script calling the module all the elements of such groups (tags).
 
In the case you see something like this:
 
@EXPORT_OK = ( @{ $EXPORT_TAGS{all} } );
 
...it means the following: That line is specifying all the existing elements of $EXPORT_TAGS{all} (which is an array reference, that's why it is called like @{..}) into @EXPORT_OK, so the programmer doesn't have to write the same stuff twice. Example:
 
our %EXPORT_TAGS = (
        all => [ qw ( sub1 sub2 sub3 sub 4 sub5 sub6 $var1 $var2 $var3 $var4 ) ],
        tools => [ qw( sub7 sub8 sub9 $var5 $var6 ) ]
);
our @EXPORT_OK = qw( sub1 sub2 sub3 sub4 sub5 sub6 sub7 sub8 sub9 $var1 $var2 $var3 $var4 $var5 $var6 );
 
...is exactly the same as:
 
our %EXPORT_TAGS = (
        all => [ qw( sub1 sub2 sub3 sub 4 sub5 sub6 $var1 $var2 $var3 $var4 ) ],
        tools => [ qw( sub7 sub8 sub9 $var5 $var6 ) ]
);
our @EXPORT_OK = ( @{ $EXPORT_TAGS{all} }, @{ $EXPORT_TAGS{tools} );
 
This allows you to chose all the elements of the tags 'all' and/or 'html' by calling: use mymodule qw(:all :html), or call only certain elements (that exists in :all and/or :html) by calling: use mymodule qw(sub1 sub4 $var2).
 
Finally, in the exact case you are explaining, that just doesn't do anything, since there are no elements in the $EXPORT_TAGS{all} key. So, no element is inserted into @EXPORT_OK. Maybe the programmer thought that those variables should be at least declared when using the Exporter module (which is really not necessary if they will be empty).
 
Hope this helps. ;-)
 
Paco Zarabozo
 
 
----- Original Message -----
From: ukhas jean
Sent: Monday, August 28, 2006 12:01 AM
Subject: perplexed with code containing %EXPORT_TAGS and @EXPORT_OK

Hello all ...
 
I have a prewritten .pm file which contains the following code :-
 
our %EXPORT_TAGS = ( 'all' => [ qw(  
) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
I know @EXPORT_OK and %EXPORT_TAGS stand for ... but I am not sure
 
1. why the key 'all' in %EXPORT_TAGS is having an empty value.
2. why the value $EXPORT_TAGS{'all'} is written into @EXPORT_OK.
 
Kindly help.
 
Thanks and Regards,
Jenson Samuel.


Stay in the know. Pulse on the new Yahoo.com. Check it out.


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to