]> git.vpit.fr Git - perl/modules/Bit-MorseSignals.git/blobdiff - lib/Bit/MorseSignals/Emitter.pm
Make Perl version numbers more readable
[perl/modules/Bit-MorseSignals.git] / lib / Bit / MorseSignals / Emitter.pm
index 44fec2401627773a9c817e1af2e4dd6e6087c5aa..944096aa7cf25fbf36ae7374277301b8ef59e36a 100644 (file)
@@ -3,11 +3,11 @@ package Bit::MorseSignals::Emitter;
 use strict;
 use warnings;
 
-use Carp qw/croak/;
-use Encode qw/encode_utf8 is_utf8/;
-use Storable qw/freeze/;
+use Carp     qw<croak>;
+use Encode   qw<encode_utf8 is_utf8>;
+use Storable qw<freeze>;
 
-use Bit::MorseSignals qw/:consts/;
+use Bit::MorseSignals qw<:consts>;
 
 =head1 NAME
 
@@ -15,17 +15,17 @@ Bit::MorseSignals::Emitter - Base class for Bit::MorseSignals emitters.
 
 =head1 VERSION
 
-Version 0.01
+Version 0.08
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.08';
 
 =head1 SYNOPSIS
 
-    use Bit::MorseSignals;
+    use Bit::MorseSignals::Emitter;
 
-    my $deuce = new Bit::MorseSignals::Emitter;
+    my $deuce = Bit::MorseSignals::Emitter->new;
     $deuce->post("hlagh") for 1 .. 3;
     while (defined(my $bit = $deuce->pop)) {
      sends_by_some_mean_lets_say_signals($bit);
@@ -33,9 +33,11 @@ our $VERSION = '0.01';
 
 =head1 DESCRIPTION
 
-Base class for L<Bit::MorseSignals> emitters. Please refer to this module for more general information about the protocol.
+Base class for L<Bit::MorseSignals> emitters.
+Please refer to this module for more general information about the protocol.
 
-The emitter object enqueues messages and prepares them one by one into L<Bit::MorseSignals> packets. It gives then back the bits of the packet in the order they should be sent.
+The emitter object enqueues messages and prepares them one by one into L<Bit::MorseSignals> packets.
+It gives then back the bits of the packet in the order they should be sent.
 
 =cut
 
@@ -64,13 +66,16 @@ sub _count_bits {
 
 =head2 C<new>
 
-L<Bit::MorseSignal::Emitter> object constructor. Currently does not take any optional argument.
+    my $bme = Bit::MorseSignals::Emitter->new;
+
+L<Bit::MorseSignals::Emitter> object constructor.
+Currently does not take any optional argument.
 
 =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 = {
@@ -81,9 +86,12 @@ sub new {
  return $self;
 }
 
-=head2 C<< post $msg, [ type => $type ] >>
+=head2 C<post>
+
+    $bme->post($msg, type => $type);
 
-Adds C<$msg> to the message queue and, if no other message is currently processed, dequeue the oldest item and prepare it. The type is automatically chosen, but you may want to try to force it with the C<type> option : C<$type> is then one of the C<BM_DATA_*> constants listed in L<Bit::MorseSignals/CONSTANTS>
+Adds C<$msg> to the message queue and, if no other message is currently processed, dequeue the oldest item and prepare it.
+The type is automatically chosen, but you may want to try to force it with the C<type> option : C<$type> is then one of the C<BM_DATA_*> constants listed in L<Bit::MorseSignals/CONSTANTS>
 
 =cut
 
@@ -102,7 +110,7 @@ sub post {
   #      BM_DATA_{PLAIN,         UTF8,          STORABLE}
   $type = BM_DATA_AUTO unless defined $type and exists $manglers[$type];
   if (ref $msg) {
-   return if { map { $_ => 1 } qw/CODE GLOB/ }->{ref $msg};
+   return if { map { $_ => 1 } qw<CODE GLOB> }->{ref $msg};
    $type = BM_DATA_STORABLE;
   } elsif ($type == BM_DATA_AUTO) {
    $type = is_utf8($msg) ? BM_DATA_UTF8 : BM_DATA_PLAIN;
@@ -128,8 +136,8 @@ sub post {
  $self->{state} = 2;
 
  my $head = '';
- vec($head, 0, 1) = ($type & 2) >> 1;
- vec($head, 1, 1) = ($type & 1);
+ vec($head, 0, 1) = ($type & 1);
+ vec($head, 1, 1) = ($type & 2) >> 1;
  vec($head, 2, 1) = 0;
  my $hlen = 3;
 
@@ -158,7 +166,10 @@ sub post {
 
 =head2 C<pop>
 
-If a message is being processed, pops the next bit in the packet. When the message is over, the next in the queue is immediatly prepared and the first bit of the new packet is given back. If the queue is empty, C<undef> is returned. You may want to use this method with the idiom :
+If a message is being processed, pops the next bit in the packet.
+When the message is over, the next in the queue is immediatly prepared and the first bit of the new packet is given back.
+If the queue is empty, C<undef> is returned.
+You may want to use this method with the idiom :
 
     while (defined(my $bit = $deuce->pop)) {
      ...
@@ -176,6 +187,30 @@ sub pop {
  return $bit;
 }
 
+=head2 C<len>
+
+The length of the currently posted message.
+
+=cut
+
+sub len {
+ my ($self) = @_;
+ _check_self($self);
+ return $self->{len};
+}
+
+=head2 C<pos>
+
+The number of bits that have already been sent for the current message.
+
+=cut
+
+sub pos {
+ my ($self) = @_;
+ _check_self($self);
+ return $self->{pos};
+}
+
 =head2 C<reset>
 
 Cancels the current transfer, but does not empty the queue.
@@ -186,7 +221,7 @@ sub reset {
  my ($self) = @_;
  _check_self($self);
  $self->{state} = @{$self->{queue}} > 0;
- @{$self}{qw/buf len pos/} = ();
+ @{$self}{qw<buf len pos>} = ();
  return $self;
 }
 
@@ -233,7 +268,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
 
@@ -241,13 +276,14 @@ L<Bit::MorseSignals>, L<Bit::MorseSignals::Receiver>.
 
 =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).
+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-emitter 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-emitter 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
 
@@ -255,6 +291,8 @@ You can find documentation for this module with the perldoc command.
 
     perldoc Bit::MorseSignals::Emitter
 
+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.