]> git.vpit.fr Git - perl/modules/Bit-MorseSignals.git/blobdiff - lib/Bit/MorseSignals/Receiver.pm
Importing Bit-MorseSignals-0.05.tar.gz
[perl/modules/Bit-MorseSignals.git] / lib / Bit / MorseSignals / Receiver.pm
index 42f6b4fcca68fefed9422077afbcaffb98c8899c..a829f36645b7166f1c46329a9f1561ef154e5ebe 100644 (file)
@@ -15,15 +15,15 @@ Bit::MorseSignals::Receiver - Base class for Bit::MorseSignals receivers.
 
 =head1 VERSION
 
-Version 0.01
+Version 0.05
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.05';
 
 =head1 SYNOPSIS
 
-    use Bit::MorseSignals;
+    use Bit::MorseSignals::Receiver;
 
     my $pants = new Bit::MorseSignals::Receiver done => sub { print "received $_[1]!\n" };
     while (...) {
@@ -46,9 +46,9 @@ sub _check_self {
 
 =head1 METHODS
 
-=head2 C<< new [ done => $cb ] >>
+=head2 C<< new < done => $cb > >>
 
-L<Bit::MorseSignal::Receiver> 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.
+L<Bit::MorseSignals::Receiver> 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.
 
 =cut
 
@@ -98,7 +98,15 @@ sub push {
     substr $self->{buf}, -$base, $base, '';
     my @demanglers = (sub { $_[0] }, \&decode_utf8, \&thaw  );
     #        BM_DATA_{PLAIN,         UTF8,          STORABLE}
-    $self->{msg} = $demanglers[$self->{type}]->($self->{buf});
+    $self->{msg} = defined $demanglers[$self->{type}]
+                    ? do {
+                       my $msg = eval {
+                        local $SIG{__DIE__} = sub { warn @_ };
+                        $demanglers[$self->{type}]->($self->{buf})
+                       };
+                       $@ ? undef : $msg;
+                      }
+                    : $self->{buf};
     $self->reset;
     $self->{done}->($self, $self->{msg}) if $self->{done};
     return;
@@ -111,6 +119,7 @@ sub push {
   if ($self->{len} >= 3) {
    my $type = 2 * vec($self->{buf}, 0, 1)
                 + vec($self->{buf}, 1, 1);
+   $type = BM_DATA_PLAIN if vec($self->{buf}, 2, 1);
    @{$self}{qw/state type buf len/} = (3, $type, '', 0);
   }
 
@@ -184,7 +193,7 @@ L<Bit::MorseSignals>, L<Bit::MorseSignals::Emitter>.
 
 =head1 AUTHOR
 
-Vincent Pit, C<< <perl at profvince.com> >>
+Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
 
 You can contact me by mail or on #perl @ FreeNode (vincent or Prof_Vince).