http://www.perlmonks.org?node_id=1016876


in reply to how to use angle operator with timeout?

Try Prompt::Timeout or IO::Prompter.

The basic technique just involves the alarm function...

use 5.010; use strict; use warnings; use Try::Tiny; my $line; try { local $SIG{ALRM} = sub { die "ALARM\n" }; alarm 10; say "Please enter some text, but quick!"; $line = <>; chomp $line; alarm 0; } catch { my $e = shift; $e =~ /^ALARM/ ? warn("timeout\n") : die($e); }; say "Got: '$line'";
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name