in reply to Not Catching Signals While Program is Prompting with IO::Prompt

Probably because like some many overspecified CPAN modules, IO::Prompt throws everything including the kitchen sink at solving what are essentially simple problems, without considering the knock-on affects upon the callers code.

In this case, the kitchen sink is Term::Readkey and ReadMode 'raw', $IN;.

It compounds that by taking the unilateral decision to terminate the calling process if the user type ^C:

local $SIG{INT} = sub { ReadMode 'restore', $IN; exit };

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: Not Catching Signals While Program is Prompting with IO::Prompt
by gg48gg (Sexton) on Jun 08, 2012 at 21:08 UTC
    That sucks. Thanks for the response. I didn't like it that much anyway. I think I will write my own sub to prompt.
Re^2: Not Catching Signals While Program is Prompting with IO::Prompt
by gg48gg (Sexton) on Jun 08, 2012 at 21:18 UTC
    found this bug... https://rt.cpan.org/Ticket/Display.html?id=38014

      2008. It doesn't look like anythings going to change any time soon.

      Frankly, the module is overkill for what it does. A simple loop that prompts and re-prompts until the input matches a regex is pretty trivial to write.

      sub promptTill{{ local $\; print "$_[0]: "; chomp( my $input = <STDIN> ); redo unless $input =~ $_[1]; return $input }} print promptTill( 'Yes/No', qr[^(?:y(?:e(?:s)?)?|n(?:o)?)$]i );;

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        I agree. I ended up with this:
        use Time::HiRes qw(usleep); my $PROMPT="What's the ticket number?\n"; my $TRY_AGAIN_PROMPT="excuse me?\n"; my $TICKET_NUMBER=prompt_until($PROMPT, $TRY_AGAIN_PROMPT, '^\d{7}$|^NOTICKET$', 1500); sub prompt_until { my $prompt_text=$_[0]; my $try_again_prompt=($_[1])? $_[1] : ''; my $until_regex=($_[2])? $_[2] : '.*'; my $speed=($_[3])? $_[3] : '0'; my $answer; if ($speed) { print_slow($prompt_text,$speed); } else { print "$prompt_text"; } $answer=<STDIN>; until ($answer=~m/$until_regex/) { if ($speed) { print_slow($try_again_prompt,$speed); } else { print "$try_again_prompt"; } $answer=<STDIN>; } chomp $answer; return $answer; } ###################################################################### +########## sub print_slow { my $speed=pop(@_); my $phrase=join('',@_); my @characters=split(//,$phrase); foreach my $char (@characters) { print $char; usleep($speed); } } ###################################################################### +##########
        I still don't understand the code!