[Dancer-users] Conditionally defining routes (and keywords) in a plugin?

Michael Alan Dorman mdorman at ironicdesign.com
Wed Jul 18 21:52:32 CEST 2012


Hey, all,

I have been working on an overhaul of Dancer::Plugin::Facebook.

To allow it to be more generally useful, but as lightweight as possible,
I would like to make certain choices as to what to make available, or
how to do so, based on the plugin configuration.

For instance, if the application doesn't intend to act on the user's
behalf, then we should be able to use a single Facebook::Graph object,
rather than regenerating it each request, or the application may not
care for any information that requires authorization, so there's no need
to create a postback handler, etc.

So is it reasonable to consider doing something like:

    package Dancer::Plugin::Facebook;

    use Dancer;
    use Dancer::Plugin;

    register setup_fb => sub {
        if (plugin_setting->{auth}) {
            get "/auth/fb" => sub { ... }
        }
        # I think I need to do this again
        register_plugin;
        if (plugin-setting->{user}) {
            register fb => sub {
                Facebook::Graph->new ($config)
            }
        } else {
            my $fb = Facebook::Graph->new ($config)
            register fb => sub () { $fb }
        }
    }

    register_plugin;

    ...

    package MyApp;

    use Dancer
    use Dancer::Plugin::Facebook;

    setup_fb;

or is this going to work at best by accident?

Mike.


More information about the Dancer-users mailing list