![]() |
![]()
| ![]() |
![]()
NAMEDancer::Plugin::ExtDirect - ExtDirect plugin for Dancer VERSIONversion 1.03 SYNOPSISuse 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> METHODSextdirectThis 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.
AUTHORAlessandro Ranellucci <aar@cpan.org> COPYRIGHT AND LICENSEThis 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.
|