From: Gurusamy Sarathy [mailto:[EMAIL PROTECTED]]
> On Sun, 25 Mar 2001 09:43:18 EST, Mark-Jason Dominus wrote:
> >> Without having a look at the code, I can't remember why that
> decision was
> >> made. I'll have a look at the code this evening.
> >
> >Did you find anything out?
I've only had a chance to look at it today.
> >To me it looks like an obviously bad design. Upgrading a module can
> >change the behavior of the main program. This was exactly the problem
> >that I thought 'use warnings' was originally written to solve.
>
> FWIW, I think it is bad design in how and where the warning is emitted
> (something that predates lexical warnings), not bad design of lexical
> warnings per se.
>
> IIRC, this particular warning is emitted in a nether region that is
> neither compile time nor run time. After compilation is finished
> and run time proper is about to begin, a function iterates through
> the stashes to emit this one particular warning. This point cannot
> be considered to be in any well-defined lexical scope. Even if we
> were to pretend that it was, that point would be only *one* particular
> lexical scope, which means to say the warning completely ignores the
> lexical scope in which the variable occurs in.
>
> The quick fix is probably to set GvMULTI() on any global symbols
> introduced within the scope of a C<no warnings 'once'>, or when
> C<use warnings> in that scope isn't enabled, or when $^W isn't set.
That's what I'm in the middle of creating a patch for. The rule I'm using is
as follows
A variable will be checked for the "use once" warnings if:
1. It is in the scope of a use warnings 'once'
2. It isn't in the scope of the warnings pragma at all AND $^W is set.
Otherwise it won't be checked at all.
Part 1 is what is in perl >= 5.6.0, Part 2 is what I'm fixing.
The enclosed patch partially fixes this issue. What I didn't get to work was
the case where the "used once" warning is enabled in any file other than the
main file. For example, if this is the main prograam
#file1:
use module ;
and this is module.pm
package module ;
use warnings ;
$fred =1
1 ;
Running
perl file1
does NOT produce the expected "used once" warnings for $fred. Anyone got any
ideas why this is the case?
Paul
once.patch