X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FIPC%2FMorseSignals%2FEmitter.pm;h=2b8a72a02f5d7ff4a3db0fdaa374408517e94b37;hb=9370c8d2ab07f434272dbbddb92bdd5d8d1fe3af;hp=a45735cabc97e55f619f55276f9355ecd52de47f;hpb=5fce18d9cd1111ef3703d93bef8baba2a7c8fa10;p=perl%2Fmodules%2FIPC-MorseSignals.git diff --git a/lib/IPC/MorseSignals/Emitter.pm b/lib/IPC/MorseSignals/Emitter.pm index a45735c..2b8a72a 100644 --- a/lib/IPC/MorseSignals/Emitter.pm +++ b/lib/IPC/MorseSignals/Emitter.pm @@ -16,11 +16,11 @@ IPC::MorseSignals::Emitter - Base class for IPC::MorseSignals emitters. =head1 VERSION -Version 0.11 +Version 0.15 =cut -our $VERSION = '0.11'; +our $VERSION = '0.15'; =head1 SYNOPSIS @@ -32,7 +32,7 @@ our $VERSION = '0.11'; =head1 DESCRIPTION -This module sends messages processed by a L emitter to another process as C (for bits 0) and C (for 1) signals. +This module sends messages processed by an underlying L emitter to another process as a sequence of C (for bits 0) and C (for 1) signals. =cut @@ -45,7 +45,7 @@ sub _check_self { =head2 C<< new < delay => $seconds, speed => $bauds, %bme_options > >> -Creates a new emitter object. C specifies the delay between two sends, in seconds, while C is the number of bits sent per second. The delay value has priority over the speed. Extra arguments are passed to L. +Creates a new emitter object. C specifies the delay between two sends, in seconds, while C is the number of bits sent per second. The delay value has priority over the speed. Default delay is 1 second. Extra arguments are passed to L. =cut @@ -68,7 +68,7 @@ sub new { =head2 C -Sends messages enqueued with L to the process C<$pid> (or to all the C<@$pid> if C<$pid> is an array reference). +Sends messages enqueued with L to the process C<$pid> (or to all the C<@$pid> if C<$pid> is an array reference, in which case duplicated targets are stripped off). =cut @@ -76,15 +76,17 @@ sub send { my ($self, $dest) = @_; _check_self($self); return unless defined $dest; - my @dests = grep $_ > 0, ref $dest eq 'ARRAY' ? map int, grep defined, @$dest - : int $dest; + my %count; + my @dests = grep $_ > 0 && !$count{$_}++, # Remove duplicates. + ref $dest eq 'ARRAY' ? map int, grep defined, @$dest + : int $dest; + return unless @dests; while (defined(my $bit = $self->pop)) { my @sigs = (SIGUSR1, SIGUSR2); my $d = $self->{delay} * 1_000_000; $d -= usleep $d while $d > 0; kill $sigs[$bit] => @dests; } - return unless @dests; } =head2 C<< delay < $seconds > >>