in reply to •Re^3: Auto-generated constructors not finding correct SUPER?
in thread Auto-generated constructors not finding correct SUPER?

merlyn

I am confused by your answer, when I try this:

{ eval "package $pkg;"; no strict 'refs'; *{$pkg . '::new'} = sub { (shift)->SUPER::new(%{$fields}) }; }
I get the same error as before. And when I try this:
{ no strict 'refs'; *{$pkg . '::new'} = sub { eval "package $pkg;"; (shift)->SUPER::new(%{$fields}) }; }
I get the same error as well. It would seem to me that SUPER is determined at compile time, is that true?

Does the whole subroutine need to be eval-ed?

-stvn

Replies are listed 'Best First'.
•Re^5: Auto-generated constructors not finding correct SUPER?
by merlyn (Sage) on Jan 10, 2005 at 17:39 UTC
      merlyn,

      Thanks for the quick response. I tried this:

      eval "package $pkg; sub new { (shift)->SUPER::new( \%\$fields ); }"
      and got this:
      Variable "$fields" will not stay shared at (eval 32) line 1.
      Although the the 300+ tests passed, and if $fields was somehow lost, they would not have passed. Is this warning something I should worry about? Any idea as to what context $fields is not staying shared within?

      -stvn

      dragonchild figured it out, this code works.

      eval "package $pkg; *new = sub { (shift)->SUPER::new( \%\$fields ); }"
      It avoids the warnings, and all the tests pass. Thanks for the help.

      -stvn