in reply to Re: Possible to change package of code reference?
in thread Possible to change package of code reference?

An SSCCE would entail explaining a kind of dumb thing I'm doing in the first place. Perhaps I'll save that for another post. I was able to accomplish what I needed to by noodling out Lanx's suggestion. Cool job on the Live Demo, btw.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

  • Comment on Re^2: Possible to change package of code reference?

Replies are listed 'Best First'.
Re^3: Possible to change package of code reference?
by haukex (Archbishop) on Oct 22, 2018 at 08:48 UTC
    I was able to accomplish what I needed to by noodling out Lanx's suggestion.

    Ok, but note LanX's warning, which I agree with - B::Deparse is more of a debugging tool, and does not guarantee to be able to round-trip Perl code, so your solution will be quite brittle. Using a regex to replace the package name will blow up on something as simple as:

    package Spin::Command::spin; our $foo = "Bar"; sub func { print "Foo:$foo"; }

    Because the deparse of func is:

    { package Spin::Command::spin; print "Foo:$foo"; }

    If, as you seem to be saying here, you really just want to replace run and don't need other replacements, then my suggestion, even though it's still kind of a hack, is much more robust (relative to it being a hack, at least).