in reply to Re: Re: Re: Lexical::Alias & subroutines
in thread Lexical::Alias & subroutines

I don't think the $SWAP global is the right implementation. It's too global :-)

What about having

alias $original => $alias;
and
Alias $alias => $original;
or something like this. Or at least the SWAPing should be on package level. IHMO of course.

Thanks, Jenda
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
   -- Rick Osborne

Edit by castaway: Closed small tag in signature

Replies are listed 'Best First'.
Re^5: Lexical::Alias & subroutines
by Aristotle (Chancellor) on May 21, 2003 at 11:59 UTC
    That's what local is for, no?

    Makeshifts last the longest.

      Definitely no. If I did

      sub foo { local $SWAP = 1; alias $alias => $original; ... Module::bar(some,params); ... }
      and someone else in the Module writes
      sub bar { alias $original => $alias; ... }
      And suddenly his/her code starts trying to do something else than it should. Just because it was called from my foo() instead of directly. The local() could only "help" if I used it like this:
      sub foo { {local $SWAP = 1;alias $alias => $original;} ... }
      But that's to long. I'd need the $SWAP to be lexical to my whole file, not local to the current call/block stack.

      I think the nicest solution is alias $original => $alias; and Alias $alias => $original;.

      Or maybe I should just learn it's the other way around versus what I'd expect :-)

      Jenda
      Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
         -- Rick Osborne

      Edit by castaway: Closed small tag in signature

        You're safe if you make sure to always localize $SWAP and make sure it's what you want it to be. Admittedly that adds needless red tape. I am really opposed to making such distinctions by letter case though - there's just no criterion for why it's the capitalized version that does it that way around, and not the lowercase.

        As far as the ordering is concerned, I believe you should just learn it, yes. :) It follows the convention of most every other comparable function: link, symlink, rename etc all take the source as first and the target as second argument.

        Makeshifts last the longest.