Skip Menu |

This queue is for tickets about the Attribute-Util CPAN distribution.

Report information
The Basics
Id: 41638
Status: resolved
Priority: 0/
Queue: Attribute-Util

People
Owner: Nobody in particular
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

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



Subject: Attribute::Memoize from a "require"d module
Date: Fri, 12 Dec 2008 08:03:21 +1100
To: bug-Attribute-Util [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
With Attribute-Util 1.03, Attribute::Handlers 0.81 and debian perl 5.10.0, the sample program and module below get an error loading bar ... Can't use string ("ANON") as a symbol ref while "strict refs" in use at /usr/share/perl5/Attribute/Memoize.pm line 13. BEGIN failed--compilation aborted at bar.pm line 9. Compilation failed in require at foo.pl line 7. Changing foo.pl from "require bar" to "use bar" makes it run ok. I suspect it may be the Attribute::Handlers problem with later loaded modules (already reported). Unless Attribute::Memoize needs some extra incantation to be able to mung new funcs at the right time.
use Attribute::Memoize; use strict; use warnings; use lib '.'; print "loading bar ...\n"; require bar; print "bar is loaded\n"; print bar::func(),"\n"; print bar::func(),"\n"; exit 0;
package bar; use strict; use warnings; use Attribute::Memoize; sub func : Memoize { print "func runs\n"; return 123; } 1;
Thanks you for your report. As a matter of fact this has been that way w/ old Attribute::Handlers as well since: perldoc Attribute::Handlers Show quoted text
> By default, attribute handlers are called at the end of the compilation > phase (in a "CHECK" block). This seems to be optimal in most cases > because most things that can be defined are defined by that point but > nothing has been executed.
in other words, it is too late to 'require'. Just 'use foo' and it works fine. Dan the Maintainer Thereof On Thu Dec 11 16:04:26 2008, user42@zip.com.au wrote: Show quoted text
> With Attribute-Util 1.03, Attribute::Handlers 0.81 and debian perl > 5.10.0, the sample program and module below get an error > > loading bar ... > Can't use string ("ANON") as a symbol ref while "strict refs" in > use at /usr/share/perl5/Attribute/Memoize.pm line 13. > BEGIN failed--compilation aborted at bar.pm line 9. > Compilation failed in require at foo.pl line 7. > > Changing foo.pl from "require bar" to "use bar" makes it run ok. > > I suspect it may be the Attribute::Handlers problem with later loaded > modules (already reported). Unless Attribute::Memoize needs some > extra > incantation to be able to mung new funcs at the right time. >
Subject: Re: [rt.cpan.org #41638] Attribute::Memoize from a "require"d module
Date: Fri, 13 Feb 2009 10:00:44 +1100
To: bug-Attribute-Util [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"DANKOGAI via RT" <bug-Attribute-Util@rt.cpan.org> writes: Show quoted text
> > it is too late to 'require'.
You could put that (ie. doesn't work with "require") as a caveat in the docs of affected modules (Attribute::Memoize and whichever other), since it's fairly subtle. Put the blame at the feet of Attribute::Handlers, since I guess it's not easily fixable, and even then would afflict users of plain 5.8.x and 5.10.0 with the supplied Attribute::Handlers. I guess the present attributes implementation is more geared to manipulating the coderef than the name/binding of the sub it's created as.
On Thu Feb 12 18:02:51 2009, user42@zip.com.au wrote: Show quoted text
> "DANKOGAI via RT" <bug-Attribute-Util@rt.cpan.org> writes:
> > > > it is too late to 'require'.
> > You could put that (ie. doesn't work with "require") as a caveat in the > docs of affected modules (Attribute::Memoize and whichever other), since > it's fairly subtle. > > Put the blame at the feet of Attribute::Handlers, since I guess it's not > easily fixable, and even then would afflict users of plain 5.8.x and > 5.10.0 with the supplied Attribute::Handlers. I guess the present > attributes implementation is more geared to manipulating the coderef > than the name/binding of the sub it's created as.
So I did in version 1.04. Closing ticket. Dan the Maintainer Thereof