Testing STDIN
From Perl QA
MakeMaker's test of prompt() shows how to tie STDIN.
SKIP: {
# Tying is less reliable on older perls.
skip "eof() doesn't honor ties in 5.5.3", 3 if $] < 5.006;
# close STDIN, though I don't remember why this is necessary
close STDIN;
# tie STDIN using TieIn
my $stdin = tie *STDIN, 'TieIn' or die;
# put some stuff on STDIN using TieIn->write()
$stdin->write("From STDIN");
# Run your code which reads from STDIN
is( prompt("Foo?", 'Bar!'), 'From STDIN', 'from STDIN' );
}
You can steal TieIn for yourself. http://search.cpan.org/src/MSCHWERN/ExtUtils-MakeMaker-6.36/t/lib/TieIn.pm
