Possible error in Event::Watcher::configure?

[email protected] (Jeff Boes)
Newsgroups perl.loop
Organization Nexcerpt, Inc.
Message-ID <[email protected]>
Perhaps this isn't an error so much as a failure between the dox and me
...

I was trying to reset the 'data' attribute for an 'idle' event. 
Specifically, the event got created without the 'data => $anything'
attribute, and I'm trying to add it later. I get a run-time error because
'splice()' is trying to scrape off more stuff from the parameter list than
is available.


Here's my code:

----start of code----
#!/usr/bin/perl -w
use diagnostics;
use strict;
use Event;
use Carp;
my $event = Event->idle(    min	       => 60,
			    max	       => 300,
			    cb	       => sub { print 'foo' },
			    repeat     => 1,
			    reentrant  => 0,
		       );
$event->configure( data => 'foo' );
-----code ends here------

The affected code from Event occurs in Event::Watcher::configure:

----start of code------
sub configure {
    my $o = shift;
    if (! @_) {
	map { $_, $o->$_() } $o->attributes;
    } else {
	while (my ($k,$v)= splice @_, -2) { $o->$k($v)}
	1 # whatever
    }
}
------code ends here----

The error looks like:

Modification of non-creatable array value attempted, subscript -2 at
        /usr/local/lib/perl5/site_perl/5.6.1/i686-linux/Event/Watcher.pm
line 95 (#1)
    (F) You tried to make an array value spring into existence, and the
    subscript was probably negative, even counting from end of the array
    backwards.
 
Uncaught exception from user code:
        Modification of non-creatable array value attempted, subscript -2
at /usr/local/lib/perl5/site_perl/5.6.1/i686-linux/Event/Watcher.pm line
95.
        Event::Watcher::configure('Event::idle=HASH(0x8235400)') called at
testevent.pl line 16

The problem lies in the while() loop, as it can't end without trying to
reference part of the array that doesn't exist.
I have a dim memory that splice() used to silently ignore references to
negative subscripts that don't exist, and returned an empty list, but now
it does not.


-- 
Jeff Boes                                             vox 616.226.9550
Database Engineer                                     fax 616.349.9076
Nexcerpt, Inc.                                      [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.