When should I use Perl's AUTOLOAD?

前端 未结 3 1520
我在风中等你
我在风中等你 2021-01-17 17:13

In \"Perl Best Practices\" the very first line in the section on AUTOLOAD is:

Don\'t use AUTOLOAD

However all t

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-17 17:50

    An alternative strategy would be to write the script as an App::* module and have the commandline option choose which class to load to provide whatever functionality it is that's pluggable depending on the option. You would require that class just-in-time once you know which it is. It's a little more up-front work, but if you intend to maintain the script for a long time, I bet it would pay off. The past couple years have seen the creation of some extra-nice tools for creating scripts whose functionality really lives in modules, including App::Cmd, MooseX::Getopt, and the bastard offspring of both.

提交回复
热议问题