Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed the usage of AUTOLOAD in the Dancer2::Plugin code.
The context: in the new plugin infrastructure, the plugin code can use DSL keywords, but the keywords need to be the one of the App that where this plugin is running. This can be known only very late in the execution. This association of the keywords with the right app is what I'll call the "mapping". To be able to defer the building of this mapping long enough, previous implementation was using an AUTOLOAD: when a DSL keyword was called, the AUTOLOAD code would get the App that we are currently running under, and map the call to the right keyword implementation. The issue: using AUTOLOAD is considered dangerous, kind of ugly and error prone, and it has nasty side effect (some of them already woked around in D2::Plugin itself) The proposed fix: at import time, each time an App loads Dancer2::Plugin, and late enough so that the App is fleshed out, we store the various DSL keywords implementation of this App in a mapping hash. And we inflate the plugin namespace with keywords definition that will choose the right implementation from the mapping hash at run time. There is imho very little magic, which makes this fix a preferred solution compared to AUTOLOAD.
- Loading branch information