Mailing List Archive

perl 5.10.1: not a glob reference at lib/Bric/Util/Burner/PHP.pm
Hi,

I just wanted a sanity check before I file a patch for this bug as it's
only on a new 5.10.1 system we are just building out.

On Bric 1.11.2, we are getting compilation errors with perl 5.10.1:

Not a GLOB reference at lib/Bric/Util/Burner/PHP.pm line 74.

which is from this snippet:

no strict 'refs';
while ( my ($k, $v) = each %{TEMPLATE_BURN_PKG . '::'} ) {
if (my $type = first { defined *{$v}{$_} }
qw(CODE HASH ARRAY IO GLOB FORMAT)
) {
# Use the reference to the variable. IOs can be used directly.
$vars{$k} = *{$v}{$type};
}

This test script:

use strict;
use warnings;
use constant test => 1;
no strict "refs";
my $k = "test";
my $v = ${'main::'}{$k};
print "key ($k) val ($v)\n";
print defined *{$v}{CODE} . "\n";

shows the issue:

key (test) val (SCALAR(0x64d960))
Not a GLOB reference at test.pl line 8.

On 5.8.8 I see:

key (test) val (*main::test)
1

as expected.

It looks like as of 5.10 we now have non globs in the stash so may need
to check for that before treating the value as a glob ref.

Thoughts?

Alex

--
Alex Krohn <alex@gossamer-threads.com>
Gossamer Threads Inc. http://www.gossamer-threads.com/
Tel: (604) 687-5804 Fax: (604) 687-5806
Re: perl 5.10.1: not a glob reference at lib/Bric/Util/Burner/PHP.pm [ In reply to ]
On Feb 4, 2010, at 11:44 AM, Alex Krohn wrote:

> This test script:
>
> use strict;
> use warnings;
> use constant test => 1;
> no strict "refs";
> my $k = "test";
> my $v = ${'main::'}{$k};
> print "key ($k) val ($v)\n";
> print defined *{$v}{CODE} . "\n";
>
> shows the issue:
>
> key (test) val (SCALAR(0x64d960))
> Not a GLOB reference at test.pl line 8.
>
> On 5.8.8 I see:
>
> key (test) val (*main::test)
> 1
>
> as expected.
>
> It looks like as of 5.10 we now have non globs in the stash so may need
> to check for that before treating the value as a glob ref.

Hrm. I guess check that *{$v}{$type} is a glob before assigning it to $vars{$k}? I can't really remember what this code is for…

Best,

David
Re: perl 5.10.1: not a glob reference at lib/Bric/Util/Burner/PHP.pm [ In reply to ]
Hi David,

> > shows the issue:
> >
> > key (test) val (SCALAR(0x64d960))
> > Not a GLOB reference at test.pl line 8.
>
> Hrm. I guess check that *{$v}{$type} is a glob before assigning it to
> $vars{$k}? I can't really remember what this code is for…

Do you know off hand how to test if something is a glob? We can test
that it's not a reference. =)

--- PHP.pm.orig 2010-02-04 11:49:59.000000000 -0800
+++ PHP.pm 2010-02-04 11:48:45.000000000 -0800
@@ -71,6 +71,7 @@
do {
no strict 'refs';
while ( my ($k, $v) = each %{TEMPLATE_BURN_PKG . '::'} ) {
+ next if (ref $v);
if (my $type = first { defined *{$v}{$_} }
qw(CODE HASH ARRAY IO GLOB FORMAT)
) {

It at least compiles now and we are doing further testing..

Cheers,

Alex

--
Alex Krohn <alex@gossamer-threads.com>
Gossamer Threads Inc. http://www.gossamer-threads.com/
Tel: (604) 687-5804 Fax: (604) 687-5806
Re: perl 5.10.1: not a glob reference at lib/Bric/Util/Burner/PHP.pm [ In reply to ]
Hi David,

> > shows the issue:
> >
> > key (test) val (SCALAR(0x64d960))
> > Not a GLOB reference at test.pl line 8.
>
> Hrm. I guess check that *{$v}{$type} is a glob before assigning it to
> $vars{$k}? I can't really remember what this code is for…

Ah better patch:

--- PHP.pm.orig 2010-02-04 11:49:59.000000000 -0800
+++ PHP.pm 2010-02-04 11:48:45.000000000 -0800
@@ -71,6 +71,7 @@
do {
no strict 'refs';
while ( my ($k, $v) = each %{TEMPLATE_BURN_PKG . '::'} ) {
+ next unless (ref(\$v) eq 'GLOB');
if (my $type = first { defined *{$v}{$_} }
qw(CODE HASH ARRAY IO GLOB FORMAT)
) {

Cheers,

Alex

--
Alex Krohn <alex@gossamer-threads.com>
Gossamer Threads Inc. http://www.gossamer-threads.com/
Tel: (604) 687-5804 Fax: (604) 687-5806
Re: perl 5.10.1: not a glob reference at lib/Bric/Util/Burner/PHP.pm [ In reply to ]
On Feb 4, 2010, at 12:52 PM, Alex Krohn wrote:

> Ah better patch:
>
> --- PHP.pm.orig 2010-02-04 11:49:59.000000000 -0800
> +++ PHP.pm 2010-02-04 11:48:45.000000000 -0800
> @@ -71,6 +71,7 @@
> do {
> no strict 'refs';
> while ( my ($k, $v) = each %{TEMPLATE_BURN_PKG . '::'} ) {
> + next unless (ref(\$v) eq 'GLOB');
> if (my $type = first { defined *{$v}{$_} }
> qw(CODE HASH ARRAY IO GLOB FORMAT)
> ) {

and does that work for 5.10.1 and 5.8.8?

Best,

David
Re: perl 5.10.1: not a glob reference at lib/Bric/Util/Burner/PHP.pm [ In reply to ]
On Feb 4, 2010, at 12:52 PM, Alex Krohn wrote:

> --- PHP.pm.orig 2010-02-04 11:49:59.000000000 -0800
> +++ PHP.pm 2010-02-04 11:48:45.000000000 -0800
> @@ -71,6 +71,7 @@
> do {
> no strict 'refs';
> while ( my ($k, $v) = each %{TEMPLATE_BURN_PKG . '::'} ) {
> + next unless (ref(\$v) eq 'GLOB');
> if (my $type = first { defined *{$v}{$_} }
> qw(CODE HASH ARRAY IO GLOB FORMAT)
> ) {

Wait, won't that then ignore any CODE HASH ARRAY IO or FORMATS? They need to be assigned to $vars{$k} = m too. Oh, and SCALARs.

David
Re: perl 5.10.1: not a glob reference at lib/Bric/Util/Burner/PHP.pm [ In reply to ]
Hi David,

> > --- PHP.pm.orig 2010-02-04 11:49:59.000000000 -0800
> > +++ PHP.pm 2010-02-04 11:48:45.000000000 -0800
> > @@ -71,6 +71,7 @@
> > do {
> > no strict 'refs';
> > while ( my ($k, $v) = each %{TEMPLATE_BURN_PKG . '::'} ) {
> > + next unless (ref(\$v) eq 'GLOB');
> > if (my $type = first { defined *{$v}{$_} }
> > qw(CODE HASH ARRAY IO GLOB FORMAT)
> > ) {
>
> Wait, won't that then ignore any CODE HASH ARRAY IO or FORMATS? They
> need to be assigned to $vars{$k} = m too. Oh, and SCALARs.

No, because the values of the symbol table are typeglobs not references. i.e.:

alex@alex ~ $ perl -MData::Dumper -le 'print Dumper(\%{"main::"})'
$VAR1 = {
'/' => *{'::/'},
'stderr' => *::stderr,
'SIG' => *::SIG,
'utf8::' => *{'::utf8::'},
<snip>

The problem is in 5.10, we now have a mix of typeglobs and references:

metrix@sitespeed ~ $ perl -MData::Dumper -le 'use constant "test" => 1; print Dumper(\%{"main::"})'
$VAR1 = {
'version::' => *{'::version::'},
'/' => *{'::/'},
'stderr' => *::stderr,
'test' => \1,
<snip>

So we want to only look at typeglobs (so we check that a reference to
the $value is in fact a glob reference). Not sure if there is a better
way.

Patch works in 5.8.8 as far as I can tell.

Cheers,

Alex

--
Alex Krohn <alex@gossamer-threads.com>
Gossamer Threads Inc. http://www.gossamer-threads.com/
Tel: (604) 687-5804 Fax: (604) 687-5806
Re: perl 5.10.1: not a glob reference at lib/Bric/Util/Burner/PHP.pm [ In reply to ]
On Feb 4, 2010, at 2:44 PM, Alex Krohn wrote:

> No, because the values of the symbol table are typeglobs not references. i.e.:
>
> alex@alex ~ $ perl -MData::Dumper -le 'print Dumper(\%{"main::"})'
> $VAR1 = {
> '/' => *{'::/'},
> 'stderr' => *::stderr,
> 'SIG' => *::SIG,
> 'utf8::' => *{'::utf8::'},
> <snip>
>
> The problem is in 5.10, we now have a mix of typeglobs and references:
>
> metrix@sitespeed ~ $ perl -MData::Dumper -le 'use constant "test" => 1; print Dumper(\%{"main::"})'
> $VAR1 = {
> 'version::' => *{'::version::'},
> '/' => *{'::/'},
> 'stderr' => *::stderr,
> 'test' => \1,
> <snip>
>
> So we want to only look at typeglobs (so we check that a reference to
> the $value is in fact a glob reference). Not sure if there is a better
> way.
>
> Patch works in 5.8.8 as far as I can tell.

Why wouldn't we want to copy over the references, too? Wouldn't your patch ignore the test constant?

Basically, in the above example, all of "version::", "/", "stderr", and "test" need to be copied to the $vars hash reference so that they're available to PHP code.

Best,

David
Re: perl 5.10.1: not a glob reference at lib/Bric/Util/Burner/PHP.pm [ In reply to ]
Hi David,

> Why wouldn't we want to copy over the references, too? Wouldn't your
> patch ignore the test constant?

D'oh, of course. I'll re-jig and test it out so that we include scalar
refs in the list of variables available in $vars. I'm not sure if there
are now other things that may be in the symbol table, so hopefully that
will work.

Cheers,

Alex

--
Alex Krohn <alex@gossamer-threads.com>
Gossamer Threads Inc. http://www.gossamer-threads.com/
Tel: (604) 687-5804 Fax: (604) 687-5806