]> git.vpit.fr Git - perl/modules/IPC-MorseSignals.git/blob - lib/IPC/MorseSignals/Receiver.pm
09fceacf44e58f4485786eaa8c12e56d80588da4
[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 WARNING
24
25 Due to the POSIX signals specification (which I wasn't aware of at the time I wrote this module), this module is by nature completely unreliable and will never work properly.
26 It is therefore B<deprecated>.
27 Please don't use it (if you were actually crazy enough to use it).
28
29 =head1 SYNOPSIS
30
31     use IPC::MorseSignals::Receiver;
32
33     local %SIG;
34     my $pants = IPC::MorseSignals::Receiver->new(\%SIG, done => sub {
35      print STDERR "GOT $_[1]\n";
36     });
37
38 =head1 DESCRIPTION
39
40 This module installs C<< $SIG{qw<USR1 USR2>} >> handlers and forwards the bits received to an underlying L<Bit::MorseSignals> receiver.
41
42 =head1 METHODS
43
44 =head2 C<new>
45
46     my $imr = IPC::MorseSignals::Receiver->new(%bmr_options);
47
48 Creates a new receiver object.
49 Its arguments are passed to L<Bit::MorseSignals::Receiver/new>, in particular the C<done> callback.
50
51 =cut
52
53 sub new {
54  my $class = shift;
55  my $sig   = shift;
56  $class = ref $class || $class || return;
57  croak 'The first argument must be a hash reference to the %SIG hash'
58   unless $sig and ref $sig eq 'HASH';
59  my $self = bless $class->SUPER::new(@_), $class;
60  @{$sig}{qw<USR1 USR2>} = (sub { $self->push(0) }, sub { $self->push(1) });
61  return $self;
62 }
63
64 =pod
65
66 IPC::MorseSignals::Receiver objects also inherit methods from L<Bit::MorseSignals::Receiver>.
67
68 =head1 EXPORT
69
70 An object module shouldn't export any function, and so does this one.
71
72 =head1 DEPENDENCIES
73
74 L<Bit::MorseSignals::Receiver>.
75
76 L<Carp> (standard since perl 5) is also required.
77
78 =head1 SEE ALSO
79
80 L<IPC::MorseSignals>, L<IPC::MorseSignals::Emitter>.
81
82 L<Bit::MorseSignals>, L<Bit::MorseSignals::Emitter>, L<Bit::MorseSignals::Receiver>.
83
84 L<perlipc> for information about signals in perl.
85
86 For truly useful IPC, search for shared memory, pipes and semaphores.
87
88 =head1 AUTHOR
89
90 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
91
92 You can contact me by mail or on C<irc.perl.org> (vincent).
93
94 =head1 BUGS
95
96 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>.
97 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
98
99 =head1 SUPPORT
100
101 You can find documentation for this module with the perldoc command.
102
103     perldoc IPC::MorseSignals::Receiver
104
105 =head1 COPYRIGHT & LICENSE
106
107 Copyright 2007,2008,2013,2017 Vincent Pit, all rights reserved.
108
109 This program is free software; you can redistribute it and/or modify it
110 under the same terms as Perl itself.
111
112 =cut
113
114 1; # End of IPC::MorseSignals::Receiver