in reply to coding a subroutine as both method and regular function

Almost always a bad idea. Now you have to write twice as many tests, since you have to test it both ways. And you can't do anything very interesting on the OO side, since you don't require it.

If you want an example, look at CGI.pm. It's not an example I would recommend copying. The code is complicated and obscure, partly because of this.

  • Comment on Re: coding a subroutine as both method and regular function

Replies are listed 'Best First'.
Re^2: coding a subroutine as both method and regular function
by leocharre (Priest) on Mar 22, 2007 at 16:18 UTC

    So, you suggest a package should not offer both procedural and oo methodology? For the general case? Or that it should be solved in another manner, by separating it into different subroutines?

      Yes, I think it's a bad idea to offer both. It just makes more work, more confusion, and more bugs.