Sorry for the delayed reply.
In the examples below, I used the following test harness:
my $module = do { open(my $fh, '<', 'Module.pm') or die("Unable to read Module.pm: $!\n"); local $/; <$fh> }; eval $module or warn $@; $module =~ s/^for;$/#for;/m; eval $module or warn $@;
The most common problem would be (safely ignored) warnings.
use strict; use warnings; package Module; sub one { } for; sub two { } 1;
First require/eval output:
[None]
Second require/eval output:
Subroutine one redefined at (eval 2) line 6.
Another problem is code running twice.
use strict; use warnings; package Module; END { print("END1\n"); } for; END { print("END2\n"); } 1;
First require/eval output:
[None]
Second require/eval output:
END2 END1 END1
Same, but different.
use strict; use warnings; package Module; BEGIN { print("BEGIN1\n"); } for; BEGIN { print("BEGIN2\n"); } 1;
First require/eval output:
BEGIN1
Second require/eval output:
BEGIN1 BEGIN2
Objects can be created and destroyed twice.
use strict; use warnings; package Module; { package Obj; sub new { print "Creating\n"; bless({}, shift) } sub DESTROY { print "Destroying\n"; } } our $o; BEGIN { $o = Obj->new(); } for; 1;
First require/eval output:
Creating
Second require/eval output:
Subroutine new redefined at (eval 2) line 8. Subroutine DESTROY redefined at (eval 2) line 9. Creating Destroying Destroying
Hopefully, nothing took the address of $o in between the two requires!
That's all I can think of. It's not quite as bad as I thought, since I thought a function could capture a variable from the first attempt, and another function could capture the same variable from the second attempt. Still, the above can still create some weird problems.
In reply to Re^3: Require a Modul that produced a error before
by ikegami
in thread Require a Modul that produced a error before
by Outaspace
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |