Can I subclass DP::Authorize::Credentials from a different namespace
Hi, I want to subclass Dancer::Plugin::Authorize::Credentials but not in the DPAC namespace, but in my App namespace, essentially something that would go like this: package App:Authenticate; use base qw/Dancer::Plugin::Authorize::Credentials/; sub authorize { my ($app, $opts, $username, $passwd) = @_; ..... } 1; I have two questions: 1. Can I do this? 2. If yes, how do I set option parameters in config.yml so that they are passed as a hashref in $opts. Thank you. ----------------------------------------------------------------- dancer does for web frameworks what sqlite did to databases
Hi! First of all, Dance::Plugin::Authorize has been renamed as Dancer::Plugin::Auth::RBAC<http://search.cpan.org/perldoc?Dancer::Plugin::Auth::RBAC> . This was a crucial change in order to allow a more organic expansion of the Plugin namespace. On Mon, Dec 13, 2010 at 9:10 PM, Gurunandan Bhat <gbhat@pobox.com> wrote:
1. Can I do this?
Of course.
2. If yes, how do I set option parameters in config.yml so that they are passed as a hashref in $opts.
In order to get Dancer to send your subclass the configuration for the plugin, it has to sit on the Plugin namespace. That is, it should be called Dancer::Plugin::My::App::Authorize or something like that. Then just set the correct plugin name in the config.yml file. For example: plugins: My::App::Authorize: credentials: class: Config options: accounts: user01: password: foobar roles: - guest - user user02: password: barbaz roles: - admin If you still wish to separate the namespace, you have two options: 1. Simply read the settings yourself from the config file (setting('MyApp')->{'authorize') or something like that). 2. You can re-register your subclass with Dancer, making sure Dancer sends it its settings automatically. Check the RBAC.pm source for this. When subclassing RBAC, notice it has lexical file-scoped variables (specifically $settings). These variables won't be overridden by simply subclassing or fiddling with the symbol table, since they're sitting in the lexical pad of the file. If you find need for RBAC to refactor and abstract away that part, feel free to make any suggestions or (better yet) patches to do that. Franck is working on refactoring RBAC and he could take that into account, if you approach him with it. Good luck, happy hacking! :) Sawyer.
participants (2)
-
Gurunandan Bhat -
sawyer x