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

Re: [PATCH] making Exporter simpler to use

Thread Previous | Thread Next
From:
Tim Bunce
Date:
February 13, 2003 02:13
Subject:
Re: [PATCH] making Exporter simpler to use
Message ID:
20030213101236.GE62780@dansat.data-plan.com
On Thu, Feb 13, 2003 at 01:29:31AM +0000, Fergal Daly wrote:
> 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);
> 
> True.
> 
> Looking through the builtin modules I see this over and over again
> 
> our(@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
> BEGIN {
>     use Exporter   ();
>     @EXPORT      = qw(getservbyname getservbyport getservent getserv);
>     @EXPORT_OK   = qw( $s_name @s_aliases $s_port $s_proto );
>     %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] );
> }
> use vars      @EXPORT_OK;
> 
> the BEGIN is needed for the use vars to work. At the moment User/pwent.pm does 
> this
> 
> 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?

The current code isn't broken. It might not meet your aesthetic values, but
it's not broken.

Of course I've no problem with Exporter::Easy being on CPAN to be
used by those who share your values.

Tim.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About