Skip Menu |

This queue is for tickets about the IO-Prompt CPAN distribution.

Report information
The Basics
Id: 127720
Status: open
Priority: 0/
Queue: IO-Prompt

People
Owner: Nobody in particular
Requestors: gilles [...] lamiral.info
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: When @ARGV is localized, prompt does not prompt a prompt.
Date: Sun, 18 Nov 2018 16:52:22 +0100
To: bug-IO-Prompt [...] rt.cpan.org
From: Gilles LAMIRAL <gilles [...] lamiral.info>
Hi Damian, Here is a little script showing an issue when @ARGV is localized: IO::Prompt::prompt() does not prompt a prompt. I searched in the source where it could be fixed. Not found, too complex for me! (I felt like an elephant in a Chinese store) #!/usr/bin/perl use strict; use warnings; use IO::Prompt; # The defect is when used with a pipe, like the following on the command line example, # prompt() does not print the prompt string 'Say something: ' # however the variable @ARGV is locally empty. # The output is then only: # # $ echo bla bla bla | ./bug_io_prompt_local_ARGV param1 param2 # ARGV are param1 param2 # You said: bla bla bla # I tried also # prompt( \*STDOUT, 'Say something: '); # The behavior is ok without the pipe: # ./bug_io_prompt_local_ARGV param1 param2 print "$IO::Prompt::VERSION\n" ; print "ARGV are @ARGV\n" ; my $input = get_stdin(); print "You said: $input\n" ; sub get_stdin { local(@ARGV) ; my $input = prompt('Say something: '); return $input ; } -- Au revoir, Gilles Lamiral. France, Baulon (35580) mob 06 19 22 03 54 tel 09 51 84 42 42
Subject: Re: [rt.cpan.org #127720] When @ARGV is localized, prompt does not prompt a prompt.
Date: Mon, 19 Nov 2018 02:15:50 +0000
To: bug-IO-Prompt [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Hi Gilles, The problem is not the localization of @ARGV (which has no effect on the *ARGV filehandle, which is what prompt() reads from). The problem is that, when input is piped, *ARGV is not connected to a tty, so IO::Prompt doesn't bother prompt for input that could not be typed in anyway. The solution is to use the -tty flag to override the (non-)reading of *ARGV. Like so: sub get_stdin { my $input = prompt(-tty, 'Say something: '); return $input ; } Hope this helps, Damian PS: IO::Prompt is no longer under active maintenance. You may want to take a look at the IO::Prompter module instead. Though, of course, that would not have behaved any differently in this particular example.
Subject: Re: [rt.cpan.org #127720] When @ARGV is localized, prompt does not prompt a prompt.
Date: Mon, 19 Nov 2018 08:33:28 +0100
To: bug-IO-Prompt [...] rt.cpan.org
From: Gilles LAMIRAL <gilles [...] lamiral.info>
Hi Damian, You misunderstood the issue. I don't want the -tty behaviour. In that case of a pipe, I don't want prompt to read from the terminal tty, I want it to read from the pipe, classical Unix STDIN, and it does so. But in that case, a pipe, it does not output the prompt on STDOUT. So if the whole process is logged to file or read on the terminal you see prompt() getting the right value without "asking" any questions. I hope IO::Prompter does not behave like so. -- Au revoir, Gilles Lamiral. France, Baulon (35580) mob 06 19 22 03 54 tel 09 51 84 42 42
Subject: Re: [rt.cpan.org #127720] When @ARGV is localized, prompt does not prompt a prompt.
Date: Mon, 19 Nov 2018 08:12:51 +0000
To: bug-IO-Prompt [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Show quoted text
> But in that case, a pipe, it does not output the prompt on STDOUT. > So if the whole process is logged to file or read on the terminal > you see prompt() getting the right value without "asking" any questions.
You are correct: here is no way to do that using IO::Prompt. Show quoted text
> I hope IO::Prompter does not behave like so.
I'm afraid it does. The whole point is that both modules are designed to allow you to put a prompted app inside a pipeline and NOT have the unnecessary prompts appear in the output. Neither module provides a mechanism to do what you want. Given what you want, why not just write your own: sub prompt { my ($prompt_str) = @_; print $prompt_str; my $input = readline(*ARGV); if (!-t *ARGV) { print $input; } chomp $input; return $input; } This would do precisely what you need, (assuming I now understand you correctly. ;-) Damian
Subject: Re: [rt.cpan.org #127720] When @ARGV is localized, prompt does not prompt a prompt.
Date: Mon, 19 Nov 2018 19:24:32 +0100
To: bug-IO-Prompt [...] rt.cpan.org
From: Gilles LAMIRAL <gilles [...] lamiral.info>
Hi Damian, My goal is just to replace a perlcritic level 4 my $input = <STDIN> ; Use "<>" or "<ARGV>" or a prompting module instead of "<STDIN>" 1 violations of InputOutput::ProhibitExplicitStdin That way, using <STDIN>, I do have what I want, like a shell reading STDIN, no matter the arguments: echo input | { echo -n "prompt: " ; read stdin ; echo "got $stdin" ; } It could be an option in IO::Prompter, if someone else needs it one day. For now I'm ok with ## no critic InputOutput::ProhibitExplicitStdin -- Au revoir, Gilles Lamiral. France, Baulon (35580) mob 06 19 22 03 54 tel 09 51 84 42 42
Subject: Re: [rt.cpan.org #127720] When @ARGV is localized, prompt does not prompt a prompt.
Date: Tue, 20 Nov 2018 02:08:47 +0000
To: bug-IO-Prompt [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Show quoted text
> It could be an option in IO::Prompter, if someone else needs it one day.
I'll note it as a possible extension. Thanks, Gilles. Damian