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

RE: [PATCH] making Exporter simpler to use

Thread Previous | Thread Next
From:
Brent Dax
Date:
February 11, 2003 16:53
Subject:
RE: [PATCH] making Exporter simpler to use
Message ID:
008801c2d234$4ae1a770$7b01a8c0@deepblue
Fergal Daly:
# On Tuesday 11 February 2003 20:07, John Peacock wrote:
# > I think Brent is just more concerned about what happens 
# when a module 
# > uses the new interface, but the user doesn't have that version of 
# > Exporter available. Having an ugly effect on earlier Perl's is not 
# > good, no matter how nice the improvements are.
# 
# I think Brent's point was that if people start taking 
# advantage of this nice 
# interface for their modules, then their modules will not work 
# on earlier 
# Perl's that don't have it. My point is that people can 
# totally ignore this 
# interface, it has zero effect on any module that doesn't 
# about know it. It 
# might be enough to just tell module authors not to use it if 
# they are going 
# to distribute their module to users of older Perls.

No, John interpreted correctly.  I'm worried about people using this
feature without realizing that it's not backwards-compatible[1].

# It's no worse than writing modules that use 5.6 style 
# attributes when there 
# were lots of people who didn't have 5.6.
# 
# > > Alternatively, I could just move the whole thing into 
# EasyExporter 
# > > or Exporter::Easy as it is totally independent of the guts of 
# > > Exporter. That makes it easy for people to install it on an old 
# > > version too.
# >
# > I suggest you follow this route and create Exporter::Easy as you 
# > mentioned; then, if the pumpking deems this a worthy 
# addition to the 
# > core, you can make sure that 'use Exporter::Easy' is effectively a 
# > no-op for Perl > 5.9.0.
# 
# Yup, done.
# 
# I've also added Exporter::Easiest which lets you do this
# 
# use Exporter::Easiest q(
# 	OK => munge frobnicate
# 	EXPORT => :tag1
# 	TAGS =>
# 		:tag1 => a b c
# 		:tag2 => :tag1 d e f
# 	FAIL => f g h
# );
# 
# No need for horrible []s and qw()s and ,s all over the place. 
# I've uploaded it 
# to CPAN but I'm not sure how long that'll take so you can get 
# it from this 
# directory too

My idea of an 'easiest' exporter interface is something like:

	use Exporter::Easiest
		':default' => qw(foo),
		':all'     => [qw(bar baz quux)], #Not needed but OK
		':tag1'    => qw(bar baz),
		':tag2'    => qw(:tag1 foo);

In other words, the logic is something like:

	sub process_args {
		my(%tags, $tag);
		
		while(@_) {
			local $_=pop;

			if(exists $tags{$_}) {
				$_=$tags{$_};
			}

			if(ref $_) {
				push @{$tags{$tag}}, @$_;
			}
			elsif(/^:/) {
				$tag=$_;
			}
			else {
				push @{$tags{$tag}}, $_;
			}
		}
		
		return %tags;
	}

(Where the calling routine would use %tags to do something useful.)

--Brent Dax <brentdax@cpan.org>
@roles=map {"Parrot $_"} qw(embedding regexen Configure)

>How do you "test" this 'God' to "prove" it is who it says it is?
"If you're God, you know exactly what it would take to convince me. Do
that."
    --Marc Fleury on alt.atheism


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