I believe that the documentation for the loop() function is incorrect in Net::SIP::Dispatcher::Eventloop is incorrect. The POD shows:
loop ( [ TIMEOUT, \@STOPVAR ] )
This indicates that STOPVAR should be an array reference, but I believe it should be an array of scalar references. As an example:
use Net::SIP;
my $done; ## We want to stop if this is true.
my @stopvars = ( \$done ); ## @stopvars is an array of references to the conditions to evaluate.
my $global_iteration_counter = 1;
## Callback to be run by event loop:
sub callback {
print "Iteration number $global_iteration_counter \n";
$global_iteration_counter++;
if ( $global_iteration_counter > 3 ) {
$done = 1;
}
}
## Create the event loop, and add a timer to run the callback every 3 seconds:
my $loop = Net::SIP::Dispatcher::Eventloop->new;
$loop->add_timer( 0, \&callback, 3 );
$loop->loop( undef, \@stopvars ); ### ISSUE: A reference to @stopvars.
## This line should only get executed after the eventlop ends:
print "Eventloop has completed\n";
Running this gives:
$ perl ./eventloop_test.pl
Iteration number 1
Not a SCALAR reference at /home/ben/sipp/IdentityTests/codenpprx03_pl/local/lib/perl5/Net/SIP/Dispatcher/Eventloop.pm line 190.
If the second argument to $loop->loop() is changed from an arrayref to an array:
$loop->loop( undef, @stopvars ); ## Now an array, NOT an arrayref
then it executes properly.
$ perl ./eventloop_test.pl
Iteration number 1
Iteration number 2
Iteration number 3
Eventloop has completed
I believe that the documentation for the
loop()
function is incorrect inNet::SIP::Dispatcher::Eventloop
is incorrect. The POD shows:This indicates that
STOPVAR
should be an array reference, but I believe it should be an array of scalar references. As an example:Running this gives:
If the second argument to
$loop->loop()
is changed from an arrayref to an array:then it executes properly.