Re: Circular dependencies when using the perl syntax checker
by ikegami (Patriarch) on Jul 28, 2008 at 15:52 UTC
|
Don't execute modules. The error you show will go away if you do
perl -c -we"use modA"
or
perl -MmodA -cwe1
Treating the module as a script doesn't set %INC, so modA.pm gets compiled and executed twice, once as a script and once as a module (the first time it's used).
| [reply] [d/l] [select] |
|
| [reply] |
Re: Circular dependencies when using the perl syntax checker
by moritz (Cardinal) on Jul 28, 2008 at 14:35 UTC
|
I tried to reproduce your error:
$ echo 'package A; sub foo { }; 1' > A.pm
$ echo 'package B; use A; 1;' > B.pm
$ perl -w -I. -MA -wle 'use B'
# no warnings here
I use A twice, once via the command line, and once indirectly by using B. The -w switch actives warnings globally, and still no warnings about redefinitions.
Maybe you could show us some code that demonstrates your problem? | [reply] [d/l] [select] |
|
I was thinking of something more like:
echo 'package modA; use modB; sub foo { }; 1' > modA.pm
echo 'package modB; use modA; 1;' > modB.pm
perl -c -w modA.pm
Subroutine foo redefined at modA.pm line 1.
modA.pm syntax OK
| [reply] |
|
C:\>echo package B;sub VERSION{333};1; >B.pm
C:\>more B.pm
package B;sub VERSION{333};1;
C:\>perl -MB -le"print for %INC;die B->VERSION"
XSLoader.pm
C:/Perl/lib/XSLoader.pm
C:/Perl/site/lib/sitecustomize.pl
C:/Perl/site/lib/sitecustomize.pl
Exporter.pm
C:/Perl/lib/Exporter.pm
strict.pm
C:/Perl/lib/strict.pm
B.pm
C:/Perl/lib/B.pm
1.09 at -e line 1.
| [reply] [d/l] [select] |
Re: Circular dependencies when using the perl syntax checker
by alexm (Chaplain) on Jul 28, 2008 at 15:41 UTC
|
| [reply] [d/l] |
Re: Circular dependencies when using the perl syntax checker
by jettero (Monsignor) on Jul 28, 2008 at 14:44 UTC
|
If you post some of the code, or equiv that produces the error(s), we'll come up with much better guesses. Possibly even a good explanation of what's happening (and why).
| [reply] |
Re: Circular dependencies when using the perl syntax checker
by tsee (Curate) on Dec 01, 2008 at 15:08 UTC
|
This is a bit of a late post, but I've just stumbled on this thread because I had the same problem. Other posts explained the cause of it, so I won't go into that. I'd just like to point out a workaround which seems to work for me: Say, we have module Foo which resides in its own file Foo.pm. You can put the following code right below the package statement.
BEGIN { $INC{"Foo.pm"} ||= __FILE__ }
Essentially, this forces an entry in %INC when the file is compiled. Use with care.
Cheers, Steffen
| [reply] [d/l] |
|
I had this specific problem with Class::MethodMaker as well. Perhaps because I had my files inside of subdirs (e.g. My::Module in My/Module.pm), Steffen's fix didn't work. I had to take another step, and make sure I had the filename just so:
BEGIN { use strict; use File::Spec; $INC{"My/Module.pm"} ||= File::Spe
+c->rel2abs(__FILE__); }
(OK, the "use strict" is just a bit of belt-and-suspenders ;) | [reply] [d/l] |
Re: Circular dependencies when using the perl syntax checker
by Anonymous Monk on Jul 28, 2008 at 14:37 UTC
|
1. Don't do that (write better test code)
2. Supress warnings (no warnings ... )
| [reply] |
|
2. Supress warnings (no warnings ... )
As John Macenroe once famously said @ Wimbledon 'You cannot be serious' ... this should only be done by those who know what they're doing and with great care - don't look gift horses etc. etc. To ignore a problem doesn't fix it.
useing strict & warnings are provided for a purpose!!
Wonders why aren't they aren't both used by default - being disabled as required ???
At last, a user level that overstates my experience :-))
| [reply] [d/l] [select] |
|
| [reply] [d/l] [select] |
|