[Israel.pm] Testing problem
Jason Elbaum
Jason.Elbaum at motorola.com
Mon Jan 5 06:53:51 PST 2004
Thomas Maier wrote:
> Thanks, it's very nice, but IMO I can make it shorter by
> passing straight forward some faked 'command' instead of new
> subroutine
>
> sub method
> {
> my ($self, $fake_command, @param) = @_;
> $pid = open $fh,"-|","$fake_command @param";
> $x = do something with $fh;
> return $x;
> }
>
> But since it's only for testing purpose, I would like to avoid from
> passing additional parameters to this method. Any idea ?
Obviously, you can make $command a file-scope variable, or member data
of $self, if you prefer, and change its setting in your test method
(perhaps using local).
Or you can write a fake open method, which will behave differently
whether or not you're in test mode.
But ultimately you need a way to run method without calling the command,
and that means being able to configure method externally. Whether you do
that by an argument or a variable etc. is up to you. Example:
sub test {
....
local $self->{COMMAND} = "test_command";
$self->method(@param);
}
Regards,
Jason Elbaum
More information about the Perl
mailing list