$port = new Device::SerialPort("/dev$opt_p");
####
write_chunk ("modem control stuff");
####
sub write_chunk {
(my $count) = $port->write($_[0]);
}
####
if ($TESTING) {
use Test::MockObject;
$port = Test::MockObject->new();
$port->mock ('write',
sub {my $arg=shift;print "wrote $arg to the serial port\n"}
);
}
else {
$port = new Device::SerialPort("/dev/$opt_p");
}
####
wrote ATZ\r to the serial port
####
wrote Test::MockObject=HASH(0x885d760) to the serial port
####
* "mock(*name*, *coderef*)"
Adds a coderef to the object. This allows code to call the named
method on the object. For example, this code:
my $mock = Test::MockObject->new();
$mock->mock( 'fluorinate',
sub { 'impurifying precious bodily fluids' } );
print $mock->fluorinate;
will print a helpful warning message.