]> git.vpit.fr Git - perl/modules/IPC-MorseSignals.git/blob - samples/try.pl
Update VPIT::TestHelpers to 15e8aee3
[perl/modules/IPC-MorseSignals.git] / samples / try.pl
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use POSIX qw<pause EXIT_SUCCESS EXIT_FAILURE>;
7
8 use lib qw<blib/lib>;
9
10 use IPC::MorseSignals::Emitter;
11 use IPC::MorseSignals::Receiver;
12
13 my $pid = fork;
14 if (!defined $pid) {
15  die "fork() failed : $!";
16 } elsif ($pid == 0) {
17  local %SIG;
18  my $rcv = IPC::MorseSignals::Receiver->new(\%SIG, done => sub {
19   print STDERR "I, the child, recieved this : $_[1]\n";
20   exit EXIT_SUCCESS;
21  });
22  print STDERR "I'm $$ (the child), and I'm waiting for data...\n";
23  pause while 1;
24  exit EXIT_FAILURE;
25 }
26
27 print STDERR "I'm $$ (the parent), and I'm gonna send a message to my child $pid.\n";
28
29 my $snd = IPC::MorseSignals::Emitter->new(speed => 1000);
30 $snd->post("This message was sent with IPC::MorseSignals");
31 $snd->send($pid);
32 waitpid $pid, 0;