Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Readonly CPAN distribution.

Report information
The Basics
Id: 36653
Status: resolved
Priority: 0/
Queue: Readonly

People
Owner: sanko [...] cpan.org
Requestors: alex [...] alexfrancis.org.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.03
Fixed in: (no value)



Subject: Readonly scalar as class name sometimes undefined
Hi - I've found when I use a Readonly scalar to hold a class name and invoke a class method on that scalar, the second and subsequent invocations complain e.g. "Can't call method "new" without a package or object reference". A contrived example of the type of thing I'm trying to do is like this: Readonly my $CLASS => 'DirHandle'; my $handle = $CLASS->new('.'); (This is to avoid repeatedly typing long package names when executing class methods; kind of like using a local alias for a fully qualified package name). Attached is a small script, readonly-bug.pl, that illustrates the problem. I noticed earlier bugs which I suspect have the same root cause: * (mainly) http://rt.cpan.org/Public/Bug/Display.html?id=15326 * http://rt.cpan.org/Public/Bug/Display.html?id=24216 Based on bug 15326 I tried a version with a direct tied scalar with no Readonly.pm - attached as readonly-bug-2.pl - which exhibits the same behaviour. I then tried the direct tied hash version on a perl 5.5 which succeeded. So I guess this isn't exactly a bug in Readonly.pm! However I felt it worthwhile logging as a bug in case others come across the same scenario and it helps them. There is a workaround - force the stringification of the value, like: Readonly my $CLASS => 'DirHandle'; my $handle = "$CLASS"->new('.'); And as noted by the author, this is all down to perl bug 37731: http://rt.perl.org/rt3/Public/Bug/Display.html?id=37731 Also attached * readonly-bug-basic.pl - minimal script to reproduce the bug * readonly-bug-basic-2.pl - minimal script reproducing the bug with a direct tied hash not Readonly.pm My environment: Readonly-1.03 perl version 5.8.8 on AMD 64 linux (ubuntu) (perl -V attached as perl_V) uname -a: Linux ws 2.6.22-14-generic #1 SMP Tue Feb 12 07:42:25 UTC 2008 i686 GNU/Linux
Subject: readonly-bug-2.pl
#!perl use strict; use warnings; use DirHandle; package TieTest; sub TIESCALAR {return bless {} } sub FETCH {return 'DirHandle' } package main; tie my $CLASS, 'TieTest'; foo1(); foo2(); foo3(); sub foo1 { eval { my $handle = $CLASS->new(q{.}); }; if ($@) { warn "Failed 1 - CLASS is '$CLASS': $@"; } } sub foo2 { eval { my $handle = $CLASS->new(q{.}); }; if ($@) { warn "Failed 2 - CLASS is '$CLASS': $@"; } } sub foo3 { eval { my $handle = "$CLASS"->new(q{.}); }; if ($@) { warn "Failed 3 - CLASS is '$CLASS': $@"; } }
Subject: readonly-bug-basic-2.pl
#!perl use strict; package TieTest; sub TIESCALAR {return bless {} } sub FETCH {return 'DirHandle' } package main; use DirHandle; tie my $CLASS, 'TieTest'; my $handle = $CLASS->new(q{.}); $handle = $CLASS->new(q{.});
Subject: readonly-bug.pl
#!perl use strict; use warnings; use DirHandle; use Readonly; Readonly my $CLASS => 'DirHandle'; foo1(); foo2(); foo3(); sub foo1 { eval { my $handle = $CLASS->new(q{.}); }; if ($@) { warn "Failed 1 - CLASS is '$CLASS': $@"; } } sub foo2 { eval { my $handle = $CLASS->new(q{.}); }; if ($@) { warn "Failed 2 - CLASS is '$CLASS': $@"; } } sub foo3 { eval { my $handle = "$CLASS"->new(q{.}); }; if ($@) { warn "Failed 3 - CLASS is '$CLASS': $@"; } }
Subject: readonly-bug-basic.pl
#!perl use strict; use DirHandle; use Readonly; Readonly my $CLASS => 'DirHandle'; my $handle = $CLASS->new(q{.}); $handle = $CLASS->new(q{.});
Subject: perl_V
Download perl_V
application/octet-stream 2.9k

Message body not shown because it is not plain text.

On Wed Jun 11 13:14:01 2008, ALEXF wrote: Show quoted text
> Hi - I've found when I use a Readonly scalar to hold a class name and > invoke a class method on that scalar, the second and subsequent > invocations complain e.g. "Can't call method "new" without a package or > object reference". > > A contrived example of the type of thing I'm trying to do is like this: > > Readonly my $CLASS => 'DirHandle'; > my $handle = $CLASS->new('.'); > > (This is to avoid repeatedly typing long package names when executing > class methods; kind of like using a local alias for a fully qualified > package name). > > Attached is a small script, readonly-bug.pl, that illustrates the problem. > > I noticed earlier bugs which I suspect have the same root cause: > > * (mainly) http://rt.cpan.org/Public/Bug/Display.html?id=15326 > * http://rt.cpan.org/Public/Bug/Display.html?id=24216 > > Based on bug 15326 I tried a version with a direct tied scalar with no > Readonly.pm - attached as readonly-bug-2.pl - which exhibits the same > behaviour. > > I then tried the direct tied hash version on a perl 5.5 which succeeded. > > So I guess this isn't exactly a bug in Readonly.pm! However I felt it > worthwhile logging as a bug in case others come across the same scenario > and it helps them. > > There is a workaround - force the stringification of the value, like: > > Readonly my $CLASS => 'DirHandle'; > my $handle = "$CLASS"->new('.'); > > And as noted by the author, this is all down to perl bug 37731: > http://rt.perl.org/rt3/Public/Bug/Display.html?id=37731 > > Also attached > > * readonly-bug-basic.pl - minimal script to reproduce the bug > * readonly-bug-basic-2.pl - minimal script reproducing the bug with a > direct tied hash not Readonly.pm > > My environment: > > Readonly-1.03 > > perl version 5.8.8 on AMD 64 linux (ubuntu) (perl -V attached as perl_V) > > uname -a: Linux ws 2.6.22-14-generic #1 SMP Tue Feb 12 07:42:25 UTC 2008 > i686 GNU/Linux
Thanks for all the work put into this! perl still has a few magic variable related gremlins but this was has been fixed upstream so I'm marking it as resolved. -- Sanko Robinson sanko@cpan.org