# In the sender process
use IPC::MorseSignals::Emitter;
- my $deuce = new IPC::MorseSignals::Emitter speed => 1024;
+ my $deuce = IPC::MorseSignals::Emitter->new(speed => 1024);
$deuce->post('HLAGH') for 1 .. 3;
$deuce->send($pid);
use IPC::MorseSignals::Receiver;
local %SIG;
- my $pants = new IPC::MorseSignals::Receiver \%SIG, done => sub {
+ my $pants = IPC::MorseSignals::Receiver->new(\%SIG, done => sub {
print STDERR "GOT $_[1]\n";
- };
+ });
=head1 DESCRIPTION
use IPC::MorseSignals::Emitter;
- my $deuce = new IPC::MorseSignals::Emitter speed => 1024;
+ my $deuce = IPC::MorseSignals::Emitter->new(speed => 1024);
$deuce->post('HLAGH') for 1 .. 3;
$deuce->send($pid);
use IPC::MorseSignals::Receiver;
local %SIG;
- my $pants = new IPC::MorseSignals::Receiver \%SIG, done => sub {
+ my $pants = IPC::MorseSignals::Receiver->new(\%SIG, done => sub {
print STDERR "GOT $_[1]\n";
- };
+ });
=head1 DESCRIPTION
die "fork() failed : $!";
} elsif ($pid == 0) {
local %SIG;
- my $rcv = new IPC::MorseSignals::Receiver \%SIG, done => sub {
+ my $rcv = IPC::MorseSignals::Receiver->new(\%SIG, done => sub {
print STDERR "I, the child, recieved this : $_[1]\n";
exit EXIT_SUCCESS;
- };
+ });
print STDERR "I'm $$ (the child), and I'm waiting for data...\n";
pause while 1;
exit EXIT_FAILURE;
print STDERR "I'm $$ (the parent), and I'm gonna send a message to my child $pid.\n";
-my $snd = new IPC::MorseSignals::Emitter speed => 1000;
+my $snd = IPC::MorseSignals::Emitter->new(speed => 1000);
$snd->post("This message was sent with IPC::MorseSignals");
$snd->send($pid);
waitpid $pid, 0;
sub neq { abs($_[0] - $_[1]) < ($_[1] / 10) };
-my $deuce = new IPC::MorseSignals::Emitter;
+my $deuce = IPC::MorseSignals::Emitter->new;
ok(defined $deuce, 'BME object is defined');
is(ref $deuce, 'IPC::MorseSignals::Emitter', 'IME object is valid');
ok($deuce->isa('Bit::MorseSignals::Emitter'), 'IME is a BME');
is($deuce->speed, 100, 'set speed is 100');
ok(neq($deuce->delay, 0.01), 'resulting speed is 0.01');
-$deuce = new IPC::MorseSignals::Emitter delay => 0.25;
+$deuce = IPC::MorseSignals::Emitter->new(delay => 0.25);
ok(neq($deuce->delay, 0.25), 'initial delay is 0.25');
is($deuce->speed, 4, 'resulting initial speed is 4');
-$deuce = new IPC::MorseSignals::Emitter speed => 40;
+$deuce = IPC::MorseSignals::Emitter->new(speed => 40);
is($deuce->speed, 40, 'initial speed is 40');
ok(neq($deuce->delay, 0.025), 'resulting initial delay is 0.025');
-$deuce = new IPC::MorseSignals::Emitter delay => 0.25, speed => 40;
+$deuce = IPC::MorseSignals::Emitter->new(delay => 0.25, speed => 40);
ok(neq($deuce->delay, 0.25), 'delay supersedes speed');
-$deuce = new IPC::MorseSignals::Emitter delay => 0;
+$deuce = IPC::MorseSignals::Emitter->new(delay => 0);
is($deuce->delay, 1, 'wrong delay results in 1');
-$deuce = new IPC::MorseSignals::Emitter speed => 0.1;
+$deuce = IPC::MorseSignals::Emitter->new(speed => 0.1);
is($deuce->delay, 1, 'wrong speed results in 1');
-$deuce = new IPC::MorseSignals::Emitter delay => 0, speed => -0.1;
+$deuce = IPC::MorseSignals::Emitter->new(delay => 0, speed => -0.1);
is($deuce->delay, 1, 'wrong delay and speed result in 1');
use IPC::MorseSignals::Receiver;
-my $pants = new IPC::MorseSignals::Receiver \%SIG;
+my $pants = IPC::MorseSignals::Receiver->new(\%SIG);
ok(defined $pants, 'IMR object is defined');
is(ref $pants, 'IPC::MorseSignals::Receiver', 'IMR object is valid');
ok($pants->isa('Bit::MorseSignals::Receiver'), 'IMR is a BMR');
my @msgs = qw/hlagh hlaghlaghlagh HLAGH HLAGHLAGHLAGH \x{0dd0}\x{00}
h\x{00}la\x{00}gh \x{00}\x{ff}\x{ff}\x{00}\x{00}\x{ff}/;
-my $deuce = new IPC::MorseSignals::Emitter speed => 1024;
-my $pants = new IPC::MorseSignals::Receiver \%SIG, done => sub {
+my $deuce = IPC::MorseSignals::Emitter->new(speed => 1024);
+my $pants = IPC::MorseSignals::Receiver->new(\%SIG, done => sub {
my $cur = shift @msgs;
is($_[1], $cur, "message correctly received");
-};
+});
$deuce->post($_) for @msgs;
$deuce->send($$);
sub cp { join '.', map ord, split //, $_[0] }
-my $deuce = new IPC::MorseSignals::Emitter speed => 1024;
-my $pants = new IPC::MorseSignals::Receiver \%SIG, done => sub {
+my $deuce = IPC::MorseSignals::Emitter->new(speed => 1024);
+my $pants = IPC::MorseSignals::Receiver->new(\%SIG, done => sub {
my $cur = shift @msgs;
ok($_[1] eq $cur, 'got ' . cp($_[1]) . ', expected ' . cp($cur))
-};
+});
$deuce->post($_) for @msgs;
$deuce->send($$);
$msgs[7]->{wut} = { dong => [ 0 .. 9 ], recurse => $msgs[7] };
my $i = 0;
-my $deuce = new IPC::MorseSignals::Emitter speed => 1024;
-my $pants = new IPC::MorseSignals::Receiver \%SIG, done => sub {
+my $deuce = IPC::MorseSignals::Emitter->new(speed => 1024);
+my $pants = IPC::MorseSignals::Receiver->new(\%SIG, done => sub {
my $cur = shift @msgs;
is_deeply($_[1], $cur, 'got object ' . $i++);
-};
+});
$deuce->post($_) for @msgs;
$deuce->send($$);
close $rdr or die "close() failed: $!";
select $wtr;
$| = 1;
- my $rcv = new IPC::MorseSignals::Receiver \%SIG, done => sub {
+ my $rcv = IPC::MorseSignals::Receiver->new(\%SIG, done => sub {
my $msg = Dumper($_[1]);
$msg =~ s/\n\r/ /g;
print $wtr "$msg\n";
- };
+ });
$SIG{__WARN__} = sub {
my $warn = join '', @_;
$warn =~ s/\n\r/ /g;
sub cleanup { slaughter }
-my $snd = new IPC::MorseSignals::Emitter;
+my $snd = IPC::MorseSignals::Emitter->new;
sub try {
my ($msg) = @_;