Subject: | AUTOLOAD is confusing |
The way AUTOLOAD is used, you can't tell if a piece of information will be available at run-time without inspecting the contents of the object's blessed hash. The AUTOLOAD implementation returns undef if a method name is not recognized or a piece of information was not retrieved during parsing, but the caller won't know which is which. Additionally, there is no can() implementation.
There are some options for fixing this:
- Change AUTOLOAD to accept only a list of possible method names (v, major, minor, osvers, etc.), and throw an error otherwise. Implement can() separately as shown here (http://www.perlmonks.org/?node_id=8227).
- Get rid of AUTOLOAD and use Class::Tiny or another system to generate the getters.
- Get rid of AUTOLOAD and generate the getters manually.(http://stackoverflow.com/a/17207602/474819); added bonus of not adding any new dependencies.
- Get rid of AUTOLOAD and just write normal methods. This is long-winded, but clear.