Faking standard input for an XS function

79 views Asked by At

I'm trying to test a function that reads from standard input by redirecting the standard input to read from a file, more or less as advised here

Here's the script:

use strict;
use warnings;

use Term::EditLine qw(CC_EOF);

use v5.14;

my $el = Term::EditLine->new('progname');
$el->set_prompt ('# ');

$el->add_fun ('bye','desc',sub { say "\nbye"; return CC_EOF; });
$el->parse('bind','-e');
$el->parse('bind','exit','bye');

*STDIN = *DATA;

while (defined($_ = $el->gets())) {
  say $_;
}

__DATA__;
goo
gar
exit

It's using Term::Editline which you would have to install first. In this case, instead of reading from the (faked) standard input, it drops me into the prompt. The input is designed so that the last one of them, exit, would signal exiting (as indicated in the command above). However, it simply does not take its input from the redirected handle. It might be the case that gets is actually a function defined in an XS, but it might be something completely different. Any help will be appreciated.

0

There are 0 answers