On Fri, Jul 15, 2005 at 03:59:13PM -0500, David Nicol wrote:
> How does the attached patch grab you?

Piecing it together, these are the leading paragraphs:

Unlike C<my>, which both allocates storage for a variable and assigns       
a simple name to that storage for use within the current scope, C<our>    
associates a simple name with a package variable in the current package, 
for use within the current scope.  In other words, C<our> has the same  
scoping rules as C<my>, but does not necessarily create a            
variable.  If more than one value is listed, the list must be placed
in parentheses.                                                              
                                                                                
When C<use strict vars> is in effect, C<our> lets you use                       
declared global variables without qualifying them with package names,           
within the lexical scope of the C<our> declaration.  In this                    
way C<our> differs from C<use vars>, which is package scoped.                   
                                                                                
The package in which a variable declared with C<our> lives is 
determined at the point of the declaration, not at the point of use. 
This means the following behavior holds:         


I think it talks about the exceptional cases too early.  It needs to start
with what our() does and why you want to use it.  

I also think the "prints 20, without looking up $bar in the symbol table"
comment is obtuse.  "prints 20, as it refers to $Foo::bar" is more straight
forward.

Attached is a patch which mixes your wording with that introduced in patch 
25148.  Here is is for easy review.

C<our> associates a simple name with a package variable in the current 
package for use within the current scope.  When C<use strict vars> is in 
effect, C<our> lets you use declared global variables without qualifying 
them with package names, within the lexical scope of the C<our> declaration. 
In this way C<our> differs from C<use vars>, which is package scoped. 
 
Unlike C<my>, which both allocates storage for a variable and assigns 
a simple name to that storage for use within the current scope, C<our> 
associates a simple name with a package variable in the current package, 
for use within the current scope.  In other words, C<our> has the same 
scoping rules as C<my>, but does not necessarily create a 
variable. 
 
If more than one value is listed, the list must be placed 
in parentheses. 
 
    our $foo;  
    our($bar, $baz); 
 
An C<our> declaration declares a global variable that will be visible 
across its entire lexical scope, even across package boundaries.  The 
package in which the variable is entered is determined at the point 
of the declaration, not at the point of use.  This means the following 
behavior holds: 
 
    package Foo; 
    our $bar;           # declares $Foo::bar for rest of lexical scope 
    $bar = 20; 
 
    package Bar; 
    print $bar;         # prints 20, as it refers to $Foo::bar 
 
Multiple C<our> declarations with the same name in the same lexical 
scope are allowed if they are in different packages.  If they happen 
to be in the same package, Perl will emit warnings if you have asked 
for them, just like multiple C<my> declarations.  Unlike a second 
C<my> declaration, which will assign the name to a fresh variable, a 
second C<our> declaration in the same package, in the same scope, is 
merely redundant. 
 
    use warnings; 
    package Foo; 
    our $bar;           # declares $Foo::bar for rest of lexical scope 
    $bar = 20; 
 
    package Bar; 
    our $bar = 30;      # declares $Bar::bar for rest of lexical scope 
    print $bar;         # prints 30 
 
    our $bar;           # emits warning but has no other effect 
    print $bar;         # still prints 30 


-- 
Michael G Schwern     [EMAIL PROTECTED]     http://www.pobox.com/~schwern
Reality is that which, when you stop believing in it, doesn't go away.
        -- Phillip K. Dick
--- pod/perlfunc.pod    2005/07/15 21:28:12     1.1
+++ pod/perlfunc.pod    2005/07/15 21:33:06
@@ -3243,19 +3243,22 @@
 =item our TYPE EXPR : ATTRS
 
 C<our> associates a simple name with a package variable in the current
-package for the remander of the lexical scope.  The listed variables
-are declared to be valid globals within the enclosing block, file, or
-C<eval>.  That is, it has the same scoping rules as a "my"
-declaration, but does not create a local variable.  When C<use strict
-'vars'> is in effect, the C<our> declaration lets you use the declared
-global variable without qualifying it with a package name.  (But only
-within the lexical scope of the C<our> declaration.  In this it
-differs from "use vars", which is package scoped.)
+package for use within the current scope.  When C<use strict vars> is in
+effect, C<our> lets you use declared global variables without qualifying
+them with package names, within the lexical scope of the C<our> declaration.
+In this way C<our> differs from C<use vars>, which is package scoped.
+
+Unlike C<my>, which both allocates storage for a variable and assigns
+a simple name to that storage for use within the current scope, C<our>
+associates a simple name with a package variable in the current package,
+for use within the current scope.  In other words, C<our> has the same
+scoping rules as C<my>, but does not necessarily create a
+variable.
 
-If more than one value is listed, the list must be placed in
-parentheses.
+If more than one value is listed, the list must be placed
+in parentheses.
 
-    our $foo;
+    our $foo; 
     our($bar, $baz);
 
 An C<our> declaration declares a global variable that will be visible
@@ -3269,11 +3272,15 @@
     $bar = 20;
 
     package Bar;
-    print $bar;                # prints 20 as it refers to $Foo::bar
+    print $bar;                # prints 20, as it refers to $Foo::bar
 
-Multiple C<our> declarations in the same lexical scope are allowed
-if they are in different packages.  If they happen to be in the same
-package, Perl will emit warnings if you have asked for them.
+Multiple C<our> declarations with the same name in the same lexical
+scope are allowed if they are in different packages.  If they happen
+to be in the same package, Perl will emit warnings if you have asked
+for them, just like multiple C<my> declarations.  Unlike a second
+C<my> declaration, which will assign the name to a fresh variable, a
+second C<our> declaration in the same package, in the same scope, is
+merely redundant.
 
     use warnings;
     package Foo;
@@ -3284,7 +3291,8 @@
     our $bar = 30;     # declares $Bar::bar for rest of lexical scope
     print $bar;                # prints 30
 
-    our $bar;          # emits warning
+    our $bar;          # emits warning but has no other effect
+    print $bar;         # still prints 30
 
 An C<our> declaration may also have a list of attributes associated
 with it.

Reply via email to