X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FBit%2FMorseSignals%2FReceiver.pm;h=52f444bf4c07c719bf4f8759c8119a29da7744ac;hb=d4cad38280f090c2057f4df1d6ef1fce88ccbcc6;hp=6c130045402f3afc26b82b55bff192f6f6f1604b;hpb=9a209b336e8b6850c08050f7ca84f86f0546bf57;p=perl%2Fmodules%2FBit-MorseSignals.git diff --git a/lib/Bit/MorseSignals/Receiver.pm b/lib/Bit/MorseSignals/Receiver.pm index 6c13004..52f444b 100644 --- a/lib/Bit/MorseSignals/Receiver.pm +++ b/lib/Bit/MorseSignals/Receiver.pm @@ -15,11 +15,11 @@ Bit::MorseSignals::Receiver - Base class for Bit::MorseSignals receivers. =head1 VERSION -Version 0.03 +Version 0.06 =cut -our $VERSION = '0.03'; +our $VERSION = '0.06'; =head1 SYNOPSIS @@ -46,7 +46,7 @@ sub _check_self { =head1 METHODS -=head2 C<< new [ done => $cb ] >> +=head2 C<< new < done => $cb > >> L object constructor. With the C<'done'> option, you can specify a callback that will be triggered every time a message is completed, and in which C<$_[0]> will be the receiver object and C<$_[1]> the message received. @@ -54,7 +54,7 @@ L object constructor. With the C<'done'> option, yo sub new { my $class = shift; - $class = ref $class || $class || return; + return unless $class = ref $class || $class; croak 'Optional arguments must be passed as key => value pairs' if @_ % 2; my %opts = @_; my $self = { @@ -99,7 +99,10 @@ sub push { my @demanglers = (sub { $_[0] }, \&decode_utf8, \&thaw ); # BM_DATA_{PLAIN, UTF8, STORABLE} $self->{msg} = defined $demanglers[$self->{type}] - ? $demanglers[$self->{type}]->($self->{buf}) + ? do { + local $SIG{__DIE__} = sub { warn @_ }; + $demanglers[$self->{type}]->($self->{buf}) + } : $self->{buf}; $self->reset; $self->{done}->($self, $self->{msg}) if $self->{done}; @@ -111,8 +114,8 @@ sub push { vec($self->{buf}, $self->{len}++, 1) = $bit; if ($self->{len} >= 3) { - my $type = 2 * vec($self->{buf}, 0, 1) - + vec($self->{buf}, 1, 1); + my $type = 2 * vec($self->{buf}, 1, 1) + + vec($self->{buf}, 0, 1); $type = BM_DATA_PLAIN if vec($self->{buf}, 2, 1); @{$self}{qw/state type buf len/} = (3, $type, '', 0); } @@ -201,6 +204,8 @@ You can find documentation for this module with the perldoc command. perldoc Bit::MorseSignals::Receiver +Tests code coverage report is available at L. + =head1 COPYRIGHT & LICENSE Copyright 2008 Vincent Pit, all rights reserved.