Re: my $var at file scope and __DATA__ sections under mod_perl

2002-01-14 Thread Perrin Harkins

 Each time, the warn is for 'blah' because the value 'test'
 is never retained in $var. Is this intended behaviour?

No, that should create a closure that keeps the value of $var.  Are you sure
these requests are all going to the same instance?

 Weird, it's like the MIME::Types::DATA handle just
 mysteriously ran out of data halfway through reading
 from it. Does anybody have any idea what's going on here.

No, but it doesn't obviously point to problems with closures and lexical
scoping in my opinion.  It looks more like you have a problem with that
filehandle.

- Perrin




my $var at file scope and __DATA__ sections under mod_perl

2002-01-13 Thread Rob Mueller (fastmail)



I've had a little bit of a look, but can't 
find anything in the mod_perl guide about this. Basically it seems to me that 
'my' variables at the package level don't retain their value under 
mod_perl.

For instance, consider the following 
mod_perl handler.

package My::Module;
my $var;

sub handler {
 warn($var || 
'blah');
 $var = 
'test';
}

Each time, the warn is for 'blah' because 
the value 'test' is never retained in $var. Is this intended behaviour? 
Personally I don't actually do this myself, but the module MIME::Types does, and 
it's causing it to break badly.

Actually, it's a bit deeper than that. 
MIME::Types does this:

my %list;sub new(@) { (bless {}, 
shift)-init( {@_} ) }

sub init($){ my ($self, 
$args) = @_; 
unless(keys %list) { local 
$_; 
while(MIME::Types::DATA)
 
{ s/\#.*//;
 next 
if m/^$/;
...

What I'm finding is that it ends up running 
the loop everytime because (keys %list) == 0 always. Now in theory this should 
work, it would just be a performance annoyance. But it doesn't, if I change the 
code to

 { local 
$_; 
while(MIME::Types::DATA)
 
{ s/\#.*//;
  
 warn($_);
 next 
if m/^$/;
...

I end up seeing in my logs...

[Mon Jan 14 13:47:01 2002] null: type: 
application/index.response[Mon Jan 14 13:47:01 2002] null: type: 
application/index.vnd[Mon Jan 14 13:47:01 2002] null: type: 
application/iotp[Mon Jan 14 13:47:01 2002] null: type: 
application/ipp[Mon Jan 14 13:47:01 2002] null: type: applicati at 
/usr/local/lib/perl5/site_perl/5.6.1/MIME/Types.pm line 75, DATA line 
30.

Weird, it's like the 
MIME::Types::DATA handle just mysteriously ran out of data halfway 
through reading from it. Does anybody have any idea what's going on here. What's 
the best idea for fixing a module like this, change all:

my $var;

to

usr vars qw($var);

and submit a patch?

Rob