[Dancer-users] Can I subclass DP::Authorize::Credentials from a different namespace

sawyer x xsawyerx at gmail.com
Tue Dec 14 09:51:10 CET 2010


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 at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20101214/13c3a949/attachment.htm>


More information about the Dancer-users mailing list