forked from plainblack/JSON-RPC-Dispatcher
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use strict; | ||
use lib 'lib'; | ||
use Foo; | ||
|
||
Foo->new->to_app; | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use LWP::UserAgent; | ||
use Test::More tests=>1; | ||
|
||
my $ua = LWP::UserAgent->new; | ||
|
||
#unless ($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"ping","id":"1"}')->is_success) { | ||
# die "You need to 'plackup -E prod eg/app.psgi' before running these tests!"; | ||
#} | ||
|
||
is($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"sum","params":[2,3,5],"id":"1"}')->content, | ||
'{"jsonrpc":"2.0","id":"1","result":10}', | ||
'sum test - using an inherited method'); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use strict; | ||
use lib 'lib'; | ||
use Bar; | ||
|
||
Bar->new->to_app; | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use LWP::UserAgent; | ||
use Test::More tests=>3; | ||
|
||
my $ua = LWP::UserAgent->new; | ||
|
||
#unless ($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"ping","id":"1"}')->is_success) { | ||
# die "You need to 'plackup -E prod eg/app.psgi' before running these tests!"; | ||
#} | ||
|
||
is($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"concat_with_spaces","params":["hello","world"],"id":"1"}')->content, | ||
'{"jsonrpc":"2.0","id":"1","result":"hello world"}', | ||
'concat with spaces test'); | ||
|
||
is($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"rpc_method_names","id":"1"}')->content, | ||
'{"jsonrpc":"2.0","id":"1","result":["sum","concat_with_spaces","rpc_method_names"]}', | ||
'method names test'); | ||
|
||
is($ua->post('http://localhost:5000/', Content=>'{"jsonrpc":"2.0","method":"sum","params":[2,3,5],"id":"1"}')->content, | ||
'{"jsonrpc":"2.0","id":"1","result":10}', | ||
'sum test - using an inherited method'); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package Bar; | ||
|
||
use Moose; | ||
extends 'Foo'; | ||
|
||
sub concat_with_spaces { | ||
my ($self, @params) = @_; | ||
return join " ", @params; | ||
} | ||
|
||
sub rpc_method_names { | ||
my ($self) = @_; | ||
return [$self->_rpc_method_names]; | ||
} | ||
|
||
|
||
__PACKAGE__->register_rpc_method_names( qw( concat_with_spaces rpc_method_names ) ); | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package Foo; | ||
|
||
use lib '../lib'; | ||
|
||
use Moose; | ||
extends 'JSON::RPC::Dispatcher::App'; | ||
|
||
sub sum { | ||
my ($self, @params) = @_; | ||
my $sum = 0; | ||
$sum += $_ for @params; | ||
return $sum; | ||
} | ||
|
||
|
||
|
||
|
||
__PACKAGE__->register_rpc_method_names( qw( sum ) ); | ||
|
||
1; |