develooper Front page | perl.perl5.porters | Postings from February 2003

Re: [PATCH] making Exporter simpler to use

Thread Previous | Thread Next
Fergal Daly
February 12, 2003 17:27
Re: [PATCH] making Exporter simpler to use
Message ID:
On Wednesday 12 February 2003 22:40, Graham Barr wrote:
> On Wed, Feb 12, 2003 at 09:54:29PM +0000, Fergal Daly wrote:
> > That said I actually think the nicest thing about it is that exporting
> > just a couple of symbols can be done in 1 line instead of 4,
> Well with recent perls it can be done in two without the code bloat
>   use base qw(Exporter);
>   our @EXPORT = qw(symbols);


Looking through the builtin modules I see this over and over again

    use Exporter   ();
    @EXPORT      = qw(getservbyname getservbyport getservent getserv);
    @EXPORT_OK   = qw( $s_name @s_aliases $s_port $s_proto );
use vars      @EXPORT_OK;

the BEGIN is needed for the use vars to work. At the moment User/ does 

use vars grep /^\$pw_/, @EXPORT_OK;

which is not pleasant and I'd guess there's worse to be found elsewhere.

This can be replaced with

use Exporter::Easy (
  EXPORT => [qw(getservbyname getservbyport getservent getserv)],
  OK => [qw( $s_name @s_aliases $s_port $s_proto )],
  ALL => 'FIELDS',

It will automatically do a "use vars" on all the variables that are mentioned 
on the basis that if you're exporting them they're going to have be somewhere 
else in your module too. Of course you can turn this off if you want or use 
tags to select which vars you want to do a "use vars" on.

I've started cleaning up the builtin modules and I've written test scripts to 
check that the same symbols are exported before and after clean up. Should I 
continue? Would the changes be accepted?


Do you need someone with lots of Unix sysadmin and/or lots of OO software 
development experience? Go on, giz a job.
My CV -

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About