]> git.vpit.fr Git - perl/modules/Bit-MorseSignals.git/blobdiff - lib/Bit/MorseSignals/Receiver.pm
Make Perl version numbers more readable
[perl/modules/Bit-MorseSignals.git] / lib / Bit / MorseSignals / Receiver.pm
index a829f36645b7166f1c46329a9f1561ef154e5ebe..0eb8751ff293a7afa74ccbbe61cf3364e3d7ac2a 100644 (file)
@@ -3,11 +3,11 @@ package Bit::MorseSignals::Receiver;
 use strict;
 use warnings;
 
-use Carp qw/croak/;
-use Encode qw/decode_utf8/;
-use Storable qw/thaw/;
+use Carp     qw<croak>;
+use Encode   qw<decode_utf8>;
+use Storable qw<thaw>;
 
-use Bit::MorseSignals qw/:consts/;
+use Bit::MorseSignals qw<:consts>;
 
 =head1 NAME
 
@@ -15,17 +15,19 @@ Bit::MorseSignals::Receiver - Base class for Bit::MorseSignals receivers.
 
 =head1 VERSION
 
-Version 0.05
+Version 0.08
 
 =cut
 
-our $VERSION = '0.05';
+our $VERSION = '0.08';
 
 =head1 SYNOPSIS
 
     use Bit::MorseSignals::Receiver;
 
-    my $pants = new Bit::MorseSignals::Receiver done => sub { print "received $_[1]!\n" };
+    my $pants = Bit::MorseSignals::Receiver->new(
+     done => sub { print "received $_[1]!\n" },
+    );
     while (...) {
      my $bit = comes_from_somewhere_lets_say_signals();
      $pants->push($bit);
@@ -33,7 +35,8 @@ our $VERSION = '0.05';
 
 =head1 DESCRIPTION
 
-Base class for L<Bit::MorseSignals> receivers. Please refer to this module for more general information about the protocol.
+Base class for L<Bit::MorseSignals> receivers.
+Please refer to this module for more general information about the protocol.
 
 Given a sequence of bits coming from the L<Bit::MorseSignals> protocol, the receiver object detects when a packet has been completed and then reconstructs the original message depending of the datatype specified in the header.
 
@@ -46,15 +49,18 @@ sub _check_self {
 
 =head1 METHODS
 
-=head2 C<< new < done => $cb > >>
+=head2 C<new>
 
-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.
+    my $bmr = Bit::MorseSignals::Receiver->new(done => $cb);
+
+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
 
 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 = {
@@ -66,9 +72,12 @@ sub new {
  return $self;
 }
 
-=head2 C<push $bit>
+=head2 C<push>
+
+    $bmr->push($bit);
 
-Tells the receiver that you have received the bit C<$bit>. Returns true while the message isn't completed, and C<undef> as soon as it is.
+Tells the receiver that you have received the bit C<$bit>.
+Returns true while the message isn't completed, and C<undef> as soon as it is.
 
 =cut
 
@@ -100,11 +109,8 @@ sub push {
     #        BM_DATA_{PLAIN,         UTF8,          STORABLE}
     $self->{msg} = defined $demanglers[$self->{type}]
                     ? do {
-                       my $msg = eval {
-                        local $SIG{__DIE__} = sub { warn @_ };
-                        $demanglers[$self->{type}]->($self->{buf})
-                       };
-                       $@ ? undef : $msg;
+                       local $SIG{__DIE__} = sub { warn @_ };
+                       $demanglers[$self->{type}]->($self->{buf})
                       }
                     : $self->{buf};
     $self->reset;
@@ -117,10 +123,10 @@ 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);
+   @{$self}{qw<state type buf len>} = (3, $type, '', 0);
   }
 
  } elsif ($self->{state} == 1) { # end of signature
@@ -132,7 +138,7 @@ sub push {
 
  } else { # first bit
 
-  @{$self}{qw/state sig sig_bit sig_len buf len/}
+  @{$self}{qw<state sig sig_bit sig_len buf len>}
            = (1,    '', $bit,   1,      '', 0  );
   vec($self->{sig}, 0, 1) = $bit;
 
@@ -151,7 +157,7 @@ sub reset {
  my ($self) = @_;
  _check_self($self);
  $self->{state} = 0;
- @{$self}{qw/sig sig_bit sig_len type buf len/} = ();
+ @{$self}{qw<sig sig_bit sig_len type buf len>} = ();
  return $self;
 }
 
@@ -185,7 +191,7 @@ An object module shouldn't export any function, and so does this one.
 
 =head1 DEPENDENCIES
 
-L<Carp> (standard since perl 5), L<Encode> (since perl 5.007003), L<Storable> (idem).
+L<Carp> (standard since perl 5), L<Encode> (since perl 5.7.3), L<Storable> (idem).
 
 =head1 SEE ALSO
 
@@ -195,11 +201,12 @@ L<Bit::MorseSignals>, L<Bit::MorseSignals::Emitter>.
 
 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).
+You can contact me by mail or on C<irc.perl.org> (vincent).
 
 =head1 BUGS
 
-Please report any bugs or feature requests to C<bug-bit-morsesignals-receiver at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Bit-MorseSignals>.  I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
+Please report any bugs or feature requests to C<bug-bit-morsesignals-receiver at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Bit-MorseSignals>.
+I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
 
 =head1 SUPPORT
 
@@ -207,6 +214,8 @@ You can find documentation for this module with the perldoc command.
 
     perldoc Bit::MorseSignals::Receiver
 
+Tests code coverage report is available at L<http://www.profvince.com/perl/cover/Bit-MorseSignals>.
+
 =head1 COPYRIGHT & LICENSE
 
 Copyright 2008 Vincent Pit, all rights reserved.