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
Dancer::Plugin::ExtDirect(3) User Contributed Perl Documentation Dancer::Plugin::ExtDirect(3)

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

version 1.03

    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>

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.
api
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.
namespace
This option is injected to the addProvider method call.
provider_config
This accepts a hashref with additional config options that will be injected to the addProvider method call.
actions
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).
namespace
Optional. The JavaScript namespace under which the API will be exported.
debug
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.

Alessandro Ranellucci <aar@cpan.org>

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.

2012-06-05 perl v5.32.1

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

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