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