develooper Front page | perl.perl5.porters | Postings from August 2013

Re: [perl #116020] toggle operator missing reset: proposal

Thread Previous | Thread Next
From:
Zefram
Date:
August 29, 2013 15:48
Subject:
Re: [perl #116020] toggle operator missing reset: proposal
Message ID:
20130829154828.GV31643@fysh.org
tlhackque wrote:
>>One might imagine a toggle object as a middle ground -- e.g.
>>    $toggle = Toggle::new( '...', sub {/^--a$/} , sub {/^--b$/}); #

Can be done much more neatly by a call-checker plugin and custom ops.
I'm thinking of it looking something like

	$out .= $_ if toggle /^--a$/, /^--b$/;

Named toggles just need a slight extension to put their state somewhere
visible.  As the hiddenness of a toggle's state is a nasty aspect of
the core feature, I'd be inclined to make these toggles use an explicit
variable, whose lifetime can be controlled in the usual ways:

	my $tog;
	reset_toggle $tog;
	$out .= $_ if toggle $tog, /^--a$/, /^--b$/;

>>such as
>>
>>      reset ['label']; or reset( ['label'], 2 );

If a toggle reset feature is added to the core, it should not further
overload an existing core operator, especially one that is presently
unrelated.

-zefram

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