GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  DANCER::PLUGIN::EXTDIRECT (3)

.ds Aq ’

NAME

Dancer::Plugin::ExtDirect - ExtDirect plugin for Dancer

CONTENTS

VERSION

version 1.03

SYNOPSIS



    use Dancer::Plugin::ExtDirect;
   
    # basic example:
    extdirect {
        api         => /api,
        actions     => {
            Calculator => {
                sum => { len => 2, handler => \&sum },
            },
        },
    };
    sub sum {
        my ($a, $b) = @_;
        return $a + $b;
    }
   
    # a bit more complex example:
    any qr{ /projects/.* }x => sub {
        # chain route handlers to check permissions
        # for ExtDirect calls too
        pass;
    };
    extdirect {
        api         => /projects/*/api,  # the wildcard values are passed to handlers
        namespace   => MyApp,
        actions     => {
            Project => {
                addUser => { len => 1, handler => \&addUser },
            },
        },
    };
    sub addUser {
        my ($project_id, $user) = @_;
        ...
    }
   
    # in HTML:
    <script type="text/javascript" src="/api"></script>
    <script type="text/javascript" src="/projects/2/api"></script>
    <script type="text/javascript">
        alert("3 + 2 = " + Calculator.sum(3,2));
        MyApp.Project.addUser({ name => Harry });
    </script>



METHODS

    extdirect

This method sets up a Dancer route handler to expose some functions to your JavaScript client-side application. It accepts a hashref containing the following options.
<B>apiB> This accepts a route handler URI path, such as /api. You can also use Dancer wildcards such as /projects/*/api, so that the values caught are passed to your method handlers.
<B>namespaceB> This option is injected to the addProvider method call.
<B>provider_configB> This accepts a hashref with additional config options that will be injected to the addProvider method call.
<B>actionsB> This accepts a hashref whose keys are ExtDirect class names and their values are hashrefs with the method definitions (see the synopsis above for an example). Each method is defined by a hashref having the following keys:
len The number of arguments that the exported function accepts.
handler A coderef (or reference to a subroutine) that will handle the request. Note that this module doesn’t force you to map the exposed ExtDirect class to any particular Perl class layout. The handler subroutine will be called with the arguments coming from the client-side. If you used any wildcards in the api path, the values caught (with Dancer’s splat method) will be prepended to the arguments.
formHandler Optional. Mark this as true to handle ExtJs form (see ExtJs docs about the formHandler API).
<B>namespaceB> Optional. The JavaScript namespace under which the API will be exported.
<B>debugB> Optional. Mark this as true to send ExtDirect exceptions when the handler dies. Default is false, meaning that Dancer will just throw a 500 Internal Server Error with no details exposed.

AUTHOR

Alessandro Ranellucci <aar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Alessandro Ranellucci.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 DANCER::PLUGIN::EXTDIRECT (3) 2012-06-05

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.