Functions stop working after a Perl "use Shell" statement

Last edited on

Symptom

If you put this Perl statement in your test scripts it will cause problems.

use Shell;

Any calls to Squish functions such as waitForObject() that follow this statement will cause script errors such as:

Can't exec waitForObject: No such file or directory

Explanation

By default the Perl Shell module turns calls to unknown Perl functions into executions of shell commands. This is done by the use of Perl's AUTOLOAD feature. Unfortunately, Squish also uses Perl's AUTOLOAD feature, and so there is a conflict.

Workaround

The Shell module can be passed a specific list of commands to export. When such a list is given, the Shell module does not use (or need to use) the AUTOLOAD feature, and so there is no longer any conflict with Squish. Here is an example that shows how to select the ls and mkdir commands in a way that won't cause any problems:

use Shell qw(ls mkdir);

sub main {
  # ...
  mkdir("/tmp/output");
}