Wally Hartshorn has asked for the wisdom of the Perl Monks concerning the following question:
Can a function in a module read the __DATA__ of the calling program?
I have a module which contains a function that reads a filehandle, $fh.
I'd like to write a test which tests that function. To do that, I need to provide it some sample data. I figured I would just drop a few lines into the __DATA__ section of the testing program, then point $fh at the *DATA handle and test away.
Unfortunately, it doesn't seem to work.
Here's what I'm trying (more or less):
In test.pl:
$fh = *DATA; my $results = $app->process(); is ( $results->{item1}, "result1", "process item1" ); __DATA__ item1,data1 item2,data2 item3,data3
In Module.pm:
use vars qw($fh); sub process { my ($self) = @_; my $reslts = {}; while (<$fh>) { [do stuff] $results->{$key} = $result; } return $results; }
What basic bit of idiocy am I committing this time? :-)
Wally Hartshorn
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem Reading __DATA__ in a Module
by blokhead (Monsignor) on Apr 13, 2004 at 00:52 UTC | |
|
Re: Problem Reading __DATA__ in a Module
by stvn (Monsignor) on Apr 13, 2004 at 20:04 UTC |