in reply to Re^2: Extend a module
in thread Extend a module

The only difference being that you must then add "Net::FTP::" to all your (non lexical) variables in the subroutine as well, otherwise they get compiled in the "main::" package and that can get rather confusing.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^4: Extend a module
by Anonymous Monk on Jul 07, 2009 at 11:59 UTC
    Which is why i write
    sub Net::FTP::my_new_FTP_method { package Net::FTP; } # this is main, package is lexical
      Indeed, another way of doing it. However, a package declaration cannot be "lexical". It can be enclosed in a block (as you did) and then it extends to the end of the block, but it cannot be "lexical" as you can have lexical ("my") variables.

      Personally, I like to have the packages switched in a more explicit manner without having to check beginning and ending of blocks, but that is my personal style.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James