1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#!/usr/bin/perl
use v5.36;
use IO::Async::Loop::Epoll;
use IO::Async::Stream;
use IO::Async::Signal;
my $loop = IO::Async::Loop::Epoll->new();
$loop->add( IO::Async::Stream->new(
read_handle => \*STDIN,
on_read => sub {
my ( $self, $buffref ) = @_;
while( $$buffref =~ s/^(.*)\r?\n// ) {
print "You said: $1\n";
}
},
) );
$loop->add( IO::Async::Signal->new(
name => 'INT',
on_receipt => sub {
print "SIGINT, will now quit\n";
$loop->loop_stop;
},
) );
$loop->loop_forever();
|