develooper Front page | perl.perl5.porters | Postings from July 2012

Re: [perl #113974] package NAMESPACE manpage comments

Thread Previous | Thread Next
Linda W
July 5, 2012 18:00
Re: [perl #113974] package NAMESPACE manpage comments
Message ID:

` David Golden via RT wrote:
> It's just file-scoped rather than block-scoped -- making it truly a
> 'global' for the file
Seems to hold across files as well:

Ishtar:bin> more
# use utf8;
# use feature 'unicode_strings';
use pck2;
use P;
package alpha;
use vars qw($aa $bb);
Pe "in file: ". __FILE__. ' package: '. __PACKAGE__;
Pe "aa=$aa, bb=$bb\n";
Ishtar:bin> more lib/
#!/usr/bin/perl -w
use 5.14.2;
#use utf8;
#use feature 'unicode_strings';
package alpha;
use P;
use vars qw($aa $bb);
Pe "in pkg %s, aa=%s, bb=%s", __PACKAGE__, eval '$aa', eval '$bb';
package beta;
use P;
Pe "---------------------\nIn pkg ". __PACKAGE__ ."\n\n";
Pe "aa=%s, bb=%s", eval '$aa', eval '$bb';
in pkg alpha, aa=one, bb=two
In pkg beta

aa=undef, bb=undef
in file: ./ package: alpha
aa=one, bb=two

> I agree that the documentation as written is confusing for someone not
> already very familiar with the jargon.

I think 'use vars' creates the vars on a trans-file-global basis...which 
explain why they would be cautioned against... HOWEVER, they should be
documented as being such...

This still leaves a 'hole', for package -specific vars that would come 
in and out
of existence only when within the scope of a package...i.e. "true 
package variables"...

I don't know how much people want that...but given all the other flavors,
it certainly seems to be the flavor that is missing.

Since 'our' is an **alias**, to PACKAGE::var, for the remainder of the
dynamic scope, it works for me to put brackets around each of my packages,
and another instance of 'ours' at the top --- though having an include 
to include identical blocks wouldn't be a bad idea... as 'use' would 
push them
all down a context (yeah, you can always push yourself up a context from
use, and define the vars... maybe a cpan-level include would suffice...
depends if // the semantics in the use'd file can be "up-leveled"

BTW... FWIW, when I went to use alpha/beta, I thought why not add some
unicode...  Badness happened.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About