Subject: | Attempt to reload (module).pm aborted obscures real use statement error |
Date: | Fri, 1 Aug 2014 12:32:00 +0000 |
To: | "bug-Moo [...] rt.cpan.org" <bug-Moo [...] rt.cpan.org> |
From: | "Angenent, Will" <Will.Angenent [...] ntt.eu> |
Hi Moo gurus,
I found an interesting problem related to use-ing modules, extends and use. I found a case where attempting to use a missing module results in a Attempt to reload (module).pm aborted error instead of Can't locate (module) in @INC.
My environment:
Perl version: v5.10.1
Moo versions: 1.004002 and 1.005 (I didn’t try any others).
Distro: Ubuntu 10.04 with 2.6.32-38-server #83-Ubuntu SMP
I can reproduce this problem with four files, test.pl, Base.pm, Package1.pm and Package2.pm:
test.pl:
---
#!/usr/bin/perl
BEGIN { print "BEGIN for main\n" }
UNITCHECK { print "UNITCHECK for main\n" }
CHECK { print "CHECK for main\n" }
INIT { print "INIT for main\n" }
use Package1;
use Package2;
---
Base.pm:
---
package Base;
BEGIN { print "BEGIN for Base\n" }
UNITCHECK { print "UNITCHECK for Base\n" }
CHECK { print "CHECK for Base\n" }
INIT { print "INIT for Base\n" }
# Uncomment the following line to trigger the "Attempt to reload Base.pm aborted" error
# use Data::Dumper;
use Some::Missing::Module;
use Moo;
1;
---
Package1.pm:
---
package Package1;
BEGIN { print "BEGIN for Package1\n" }
UNITCHECK { print "UNITCHECK for Package1\n" }
CHECK { print "CHECK for Package1\n" }
INIT { print "INIT for Package1\n" }
use Moo;
extends qw(Base);
1;
---
Package2.pm:
---
package Package2;
BEGIN { print "BEGIN for Package2\n" }
UNITCHECK { print "UNITCHECK for Package2\n" }
CHECK { print "CHECK for Package2\n" }
INIT { print "INIT for Package2\n" }
use Moo;
use Base;
extends qw(Base);
1;
---
Note that Package2 has a use Base statement, but Package 1 doesn’t. Adding a use Base statement to Package2 makes the incorrect error message go away.
The output of the above, with the use Data::Dumper statement commented out is:
BEGIN for main
BEGIN for Package1
UNITCHECK for Package1
BEGIN for Base
Can't locate Some/Missing/Module.pm in @INC (@INC contains: [removed]) at Base.pm line 11.
BEGIN failed--compilation aborted at Base.pm line 11.
Compilation failed in require at /usr/share/perl5/Module/Runtime.pm line 317.
Compilation failed in require at ./test.pl line 8.
BEGIN failed--compilation aborted at ./test.pl line 8.
UNITCHECK for main
CHECK for Base
CHECK for Package1
CHECK for main
With it uncommented:
BEGIN for main
BEGIN for Package1
UNITCHECK for Package1
BEGIN for Base
BEGIN for Package2
Attempt to reload Base.pm aborted.
Compilation failed in require at Package2.pm line 10.
BEGIN failed--compilation aborted at Package2.pm line 10.
Compilation failed in require at ./test.pl line 9.
BEGIN failed--compilation aborted at ./test.pl line 9.
UNITCHECK for main
CHECK for Package2
CHECK for Base
CHECK for Package1
CHECK for main
Thanks,
Will
Show quoted text
________________________________
This e-mail (and any attachments) contains information which is intended solely for the attention of the person to whom it has been sent. If you are not the intended recipient, you are not authorised to copy, distribute or use it for any purpose or disclose the contents to any person. If you have received this e-mail in error, please notify us immediately at legal@ntt.eu and delete this e-mail from your systems. NTT Europe makes no warranty that this message is error or virus free. Any comments or opinions expressed are those of the originator not of NTT Europe Ltd. unless otherwise expressly stated. NTT Europe Limited is a company registered in England and Wales with company number 2307625. Registered Address: 3rd Floor, Devon House, 58-60 St. Katharine's Way, London, E1W 1LB, UK.