]> git.vpit.fr Git - perl/modules/IPC-MorseSignals.git/blob - lib/IPC/MorseSignals/Receiver.pm
1d8472f5acd31f74299d85a61b83d8f137e67a15
[perl/modules/IPC-MorseSignals.git] / lib / IPC / MorseSignals / Receiver.pm
1 package IPC::MorseSignals::Receiver;
2
3 use strict;
4 use warnings;
5
6 use Carp qw/croak/;
7
8 use Bit::MorseSignals::Receiver;
9 use base qw/Bit::MorseSignals::Receiver/;
10
11 =head1 NAME
12
13 IPC::MorseSignals::Receiver - Base class for IPC::MorseSignals receivers.
14
15 =head1 VERSION
16
17 Version 0.16
18
19 =cut
20
21 our $VERSION = '0.16';
22
23 =head1 SYNOPSIS
24
25     use IPC::MorseSignals::Receiver;
26
27     local %SIG;
28     my $pants = IPC::MorseSignals::Receiver->new(\%SIG, done => sub {
29      print STDERR "GOT $_[1]\n";
30     });
31
32 =head1 DESCRIPTION
33
34 This module installs C<$SIG{qw/USR1 USR2/}> handlers and forwards the bits received to an underlying L<Bit::MorseSignals> receiver.
35
36 =head1 METHODS
37
38 =head2 C<new>
39
40     my $imr = IPC::MorseSignals::Receiver->new(%bmr_options);
41
42 Creates a new receiver object. Its arguments are passed to L<Bit::MorseSignals::Receiver/new>, in particular the C<done> callback.
43
44 =cut
45
46 sub new {
47  my $class = shift;
48  my $sig   = shift;
49  $class = ref $class || $class || return;
50  croak 'The first argument must be a hash reference to the %SIG hash'
51   unless $sig and ref $sig eq 'HASH';
52  my $self = bless $class->SUPER::new(@_), $class;
53  @{$sig}{qw/USR1 USR2/} = (sub { $self->push(0) }, sub { $self->push(1) });
54  return $self;
55 }
56
57 =pod
58
59 IPC::MorseSignals::Receiver objects also inherit methods from L<Bit::MorseSignals::Receiver>.
60
61 =head1 EXPORT
62
63 An object module shouldn't export any function, and so does this one.
64
65 =head1 DEPENDENCIES
66
67 L<Bit::MorseSignals::Receiver>.
68
69 L<Carp> (standard since perl 5) is also required.
70
71 =head1 SEE ALSO
72
73 L<IPC::MorseSignals>, L<IPC::MorseSignals::Emitter>.
74
75 L<Bit::MorseSignals>, L<Bit::MorseSignals::Emitter>, L<Bit::MorseSignals::Receiver>.
76
77 L<perlipc> for information about signals in perl.
78
79 For truly useful IPC, search for shared memory, pipes and semaphores.
80
81 =head1 AUTHOR
82
83 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
84
85 You can contact me by mail or on C<irc.perl.org> (vincent).
86
87 =head1 BUGS
88
89 Please report any bugs or feature requests to C<bug-ipc-morsesignals-receiver at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IPC-MorseSignals>.  I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
90
91 =head1 SUPPORT
92
93 You can find documentation for this module with the perldoc command.
94
95     perldoc IPC::MorseSignals::Receiver
96
97 =head1 COPYRIGHT & LICENSE
98
99 Copyright 2007,2008,2013 Vincent Pit, all rights reserved.
100
101 This program is free software; you can redistribute it and/or modify it
102 under the same terms as Perl itself.
103
104 =cut
105
106 1; # End of IPC::MorseSignals::Receiver