in reply to Re: Removing AUTOLOAD from CGI.pm
in thread Removing AUTOLOAD from CGI.pm

> I like and tend to use CGI::Pretty. Sometimes just from the command line to get template snippets.

That is actually a sane use case, but unfortunately the way CGI::Pretty is written means i can't remove the AUTOLOAD stuff from CGI without breaking the pretty functionality of CGI::Pretty. Not just that, but it contains some very, er, "interesting" code!

It probably *could* be kept functioning, but i'm not going to spend time on it and would rather deprecate it.

Replies are listed 'Best First'.
Re^3: Removing AUTOLOAD from CGI.pm
by Your Mother (Archbishop) on Feb 23, 2015 at 08:53 UTC

    Understood. Appreciate your efforts!

      Not sure why AUTOLOAD is needed in CGI anyway, the allowed HTML-tags seem to be exported from CGI to the local namespace, but only spring into existence within the stash of %CGI:: after first use! ¹

      Speed can't be that relevant, CGI doesn't do any syntax validation, so the same generic function could be installed at import time for all html-tags, maybe with a closed over $tag_name if necessary.

      What am I missing?

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)

      PS: Je suis Charlie!

      ¹) didn't know it's possible to predeclare an AUTOLOADed sub ... (scratch)

      update

      interesting...

      DB<181> package Test; sub AUTOLOAD { $AUTOLOAD,\@_ } DB<182> bar(1,2,3) Undefined subroutine &main::bar called at (eval 196)[multi_perl5db.pl: +644] line 2. DB<183> Test::bar(1,2,3) => ("Test::bar", [1, 2, 3]) DB<184> *bar=\&Test::bar DB<185> bar(1,2,3) => ("Test::bar", [1, 2, 3])

      but

      DB<186> *foo=*Test::foo DB<187> foo(1,2,3) Undefined subroutine &Test::foo called at (eval 206)[multi_perl5db.pl: +644] line 2.

        > Not sure why AUTOLOAD is needed in CGI anyway, the allowed HTML-tags seem to be exported from CGI to the local namespace, but only spring into existence within the stash of %CGI:: after first use! Speed can't be that relevant, CGI doesn't do any syntax validation, so the same generic function could be installed at import time for all html-tags, maybe with a closed over $tag_name if necessary.

        I believe the original reason was to defer the compilation so the majority of functions, not just html functions, were wrapped in quotes and then eval'd and added to the namespace when called. Or you could pass -compile (or call ->compile) to force them to compile at import time. It was kind of a way to fix the God object problem when compiling a 4000+ line module was slow. An added side effect was the ability to call CGI with arbitrary tags not included in the module... it was future proofed! You could call CGI->wibble and get a <wibble> tag.

        Anyway it's all gone now, or soon will be.