Front page | perl.perl5.porters |
Postings from July 2012
[perl #113974] package NAMESPACE manpage comments
Thread Next
From:
Linda Walsh
Date:
July 3, 2012 18:37
Subject:
[perl #113974] package NAMESPACE manpage comments
Message ID:
rt-3.6.HEAD-28836-1341365855-583.113974-75-0@perl.org
# New Ticket Created by Linda Walsh
# Please include the string: [perl #113974]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=113974 >
This is a bug report for perl from perl-diddler@tlinx.org,
generated with the help of perlbug 1.39 running under perl 5.14.2.
-----------------------------------------------------------------
[Please describe your issue here]
Looking at the 2nd paragraph under package in the perlfunc manpage
of 5.14.2, I see:
A package statement affects dynamic variables only, including
those you've used "local" on, but not lexical variables, which
are created with "my", "state", or "our".
Issues:
1) package statements affect dynamically ***scoped*** variables --
not dynamic variables (state & my, usually in subroutines live
on a stack. "My" is a dynamic variable with static scoping -- since
if you recursively call the same subroutine, you don't get 1 lexical
copy of the 'my' var, you get 1 for each dynical level (vs. state only
get 1 for all levels).
2) package affects 'our', despite what it says above. AFAIK, 'our'
only refers to variables that belong to the current package.
Sample prog to demonstrate above:
----
perl -wE'use strict;
package A;
our $one="A.1";
state $two="A.2";
my $three = "A.3";
local $__PACKAGE__::four = "A.4";
printf "package=%s\n",__PACKAGE__;
package B;
our $one="B.1";
state $two="B.2";
my $three = "B.3";
local $__PACKAGE__::four = "B.4";
printf "package=%s\n",__PACKAGE__;
printf "%s\n", join ", ", ($one, $two, $three, $__PACKAGE__::four);
'
"state" variable $two masks earlier declaration in same scope at -e line 10.
"my" variable $three masks earlier declaration in same scope at -e line 11.
package=A
package=B
B.1, B.2, B.3, B.4
=========
my and state complain -- rightfully. but 'our' does not! because
it belongs to the package in scope. If what the man page said was
true and one was the same type of var as 'my' and 'state', you'd
get the same type of warning about masking.
3rd) Issue: You have to use "__PACKAGE__::four" to not get a warning
about the confusion between global var four and four -- even though
one is A::four and the other is B::four. Without the __PACKAGE__ prefixes
(maybe the one in 'B' is enough in this case), you get an error:
Global symbol "$four" requires explicit package name at -e line 6.
Execution of -e aborted due to compilation errors.
So why the requirement to put __PACKAGE__ in -- why not assume that
if you are in package B, you mean B::four unless you override with
a different prefix? Or, in other words -- the behavior that "our $one"
shows (even though the documentation claims it should be acting more
like "state or my"....
Questions --
what is correct? should 'our' complain like state+my? or is the documentation
wrong? (I.e. 'our' means it belongs to the package!)...
Shouldn't local be defaulting to that as well rather than requiring an
explicity prefix?
And please --- that needs to say dynamically scoped variables, NOT
"dynamic variables"....
linda
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=docs
severity=medium
---
This perlbug was built using Perl 5.14.2 - Wed Feb 8 15:59:25 UTC 2012
It is being executed now by Perl 5.14.2 - Wed Feb 8 15:55:36 UTC 2012.
Site configuration information for perl 5.14.2:
Configured by abuild at Wed Feb 8 15:55:36 UTC 2012.
Summary of my perl5 (revision 5 version 14 subversion 2) configuration:
Platform:
osname=linux, osvers=3.1.0-1.2-default, archname=x86_64-linux-thread-multi
uname='linux build09 3.1.0-1.2-default #1 smp thu nov 3 14:45:45 utc 2011 (187dde0) x86_64 x86_64 x86_64 gnulinux '
config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr -Dinstallusrbinperl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm -Dd_dbm_open -Duseshrplib=true -Doptimize=-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe -Accflags=-DPERL_USE_SAFE_PUTENV -Dotherlibdirs=/usr/lib/perl5/site_perl'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -fno-strict-aliasing -pipe -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -fno-strict-aliasing -pipe -fstack-protector'
ccversion='', gccversion='4.6.2', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib64 -fstack-protector'
libpth=/lib64 /usr/lib64 /usr/local/lib64
libs=-lm -ldl -lcrypt -lpthread
perllibs=-lm -ldl -lcrypt -lpthread
libc=/lib64/libc-2.14.1.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.14.1'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.14.2/x86_64-linux-thread-multi/CORE'
cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib64 -fstack-protector'
Locally applied patches:
---
@INC for perl 5.14.2:
/usr/lib/perl5/site_perl/5.14.2/x86_64-linux-thread-multi
/usr/lib/perl5/site_perl/5.14.2
/usr/lib/perl5/vendor_perl/5.14.2/x86_64-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.14.2
/usr/lib/perl5/5.14.2/x86_64-linux-thread-multi
/usr/lib/perl5/5.14.2
/usr/lib/perl5/site_perl/5.14.2/x86_64-linux-thread-multi
/usr/lib/perl5/site_perl/5.14.2
/usr/lib/perl5/site_perl
.
---
Environment for perl 5.14.2:
HOME=/home/law
LANG=en_US.UTF-8
LANGUAGE (unset)
LC_COLLATE=C
LC_CTYPE=en_US.UTF-8
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=.:/sbin:/usr/local/sbin:/home/law/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/usr/lib/qt3/bin:/usr/sbin:/etc/local/func_lib:/home/law/lib:/home/law/bin/lib
PERL5OPT=-CSA
PERL_BADLANG (unset)
SHELL=/bin/bash
Thread Next
-
[perl #113974] package NAMESPACE manpage comments
by Linda Walsh