in reply to Re: Defining a subroutine in another package
in thread Defining a subroutine in another package

I believe this only works in perl 5.6.0 and above though.

  • Comment on Re: Re: Defining a subroutine in another package

Replies are listed 'Best First'.
Re: Re: Re: Defining a subroutine in another package
by chromatic (Archbishop) on Jan 26, 2002 at 23:10 UTC
    It works for me on 5.004_5 and (I presume) even earlier, though you'll have to disable strict 'refs'.

    It's just a symbolic access to a typeglob, nothing special. :)

      I have had problems with it under 5.005: it did not like the sub, although it looked OK and was compiled without a hitch in 5.6.0 and above. So yes the construct works but it looks to me like what you put in the sub can be a problem.

      Here is what caused the problem:

      my( $text_method, $nav); # actually defined and initialized earlier { no strict 'refs'; my ${text_method}= sub { my $elt=shift; my $dest= $elt->$nav( @_) or return ''; return $dest->text; } }