parameters. If this is not the case, an error message noting this is produced.
This flag has no other effect on the functioning of perltidy.
+=item B<-to=n>, B<--timeout-in-seconds=n>
+
+When the standard input supplies the input stream, and the input has not been
+received within B<n> seconds, perltidy will end with a timeout message. The
+intention is to catch a situation where perltidy is accidentally invoked
+without a file to process and therefore waits for input from the system
+standard input (stdin), which never arrives. The default is B<n=10> seconds.
+This check can be turned off with B<n=0>.
+
=back
=head1 FORMATTING OPTIONS
sub stream_slurp {
- my ($filename) = @_;
+ my ( $filename, $timeout_in_seconds ) = @_;
# Read the text in $filename and
# return:
else {
if ( $filename eq '-' ) {
local $INPUT_RECORD_SEPARATOR = undef;
- my $buf = <>;
+ my $buf;
+ if ( $timeout_in_seconds && $timeout_in_seconds > 0 ) {
+ eval {
+ local $SIG{ALRM} = sub { die "alarm\n" };
+ alarm($timeout_in_seconds);
+ $buf = <>;
+ alarm(0);
+ 1;
+ }
+ or Die(
+"Timeout reading stdin using -to=$timeout_in_seconds seconds. Use -to=0 to skip timeout check.\n"
+ );
+ }
+ else {
+ $buf = <>;
+ }
$rinput_string = \$buf;
}
else {
my $rOpts = $self->[_rOpts_];
- my $rinput_string = stream_slurp($input_file);
+ my $rinput_string =
+ stream_slurp( $input_file, $rOpts->{'timeout-in-seconds'} );
return unless ( defined($rinput_string) );
# Note that we could have a zero size input string here if it
$add_option->( 'warning-output', 'w', '!' );
$add_option->( 'add-terminal-newline', 'atnl', '!' );
$add_option->( 'line-range-tidy', 'lrt', '=s' );
+ $add_option->( 'timeout-in-seconds', 'to', '=i' );
# options which are both toggle switches and values moved here
# to hide from tidyview (which does not show category 0 flags):
code-skipping
format-skipping
default-tabsize=8
+ timeout-in-seconds=10
whitespace-cycle=0
entab-leading-whitespace=0