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

another way to do it is to just add the package name to the method declaration:
use Net::FTP; sub Net::FTP::my_new_FTP_method { ... }; # your script here $ftp = Net::FTP->new("some.host.name", Debug => 0) or die "Cannot connect to some.host.name: $@"; $ftp->my_new_FTP_method;

Replies are listed 'Best First'.
Re^3: Extend a module
by CountZero (Bishop) on Jul 07, 2009 at 11:55 UTC
    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

      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