Re: [MacPerl-Toolbox] A difficulty with Mac-Events.pm
[email protected] (Ronald J Kimball) Sun, 1 Apr 2001 21:56:57 -0400
| Newsgroups | perl.macperl.toolbox |
|---|---|
| Message-ID | <[email protected]> |
On Sun, Apr 01, 2001 at 09:59:22PM +0100, Alan Fry wrote:
> A "use Mac::Events" statement appears to interfere with the workings
> of a web browsers even if the 'Mac::Events' module is not actually
> used in the script. By all the laws of the Medes and Persians (and
> Camels) it should be possible to "use" any module without penalty
> should it not, since the 'methods' of the module should merely lie
> dormant in the script unless called into action?
Err, no. First, when you use a module, that module is compiled and
executed. BEGIN, CHECK, and INIT blocks are called (depending on the Perl
version) and code outside of any subroutine is executed. Second, the
module's import() method is called.
This hypothetical module would impose penalties in several ways upon use:
package UhOh;
BEGIN {
sleep 10000000;
}
for ($i = 1; $i < 1000; $i++) {
push @x, [@x];
}
sub import {
exit;
}
__END__
These are extreme examples, of course, but it's quite possible that an
actual module could execute code upon being used that would cause problems.
Ronald