in reply to Extend a module

OR if you want to stay within the same namespace and not write a specific module for it:
use Net::FTP; package Net::FTP; sub my_new_FTP_method { ... }; package main; # 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;

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^2: Extend a module
by salva (Canon) on Jul 07, 2009 at 06:53 UTC
    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;
      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