1# Remote API initialization from a hashref (no packages) 2 3use strict; 4use warnings; 5 6use Test::More tests => 4; 7 8use RPC::ExtDirect::Test::Util; 9use RPC::ExtDirect::Config; 10use RPC::ExtDirect::API; 11 12my $test_data = eval do { local $/; <DATA>; } or die "Can't eval DATA: '$@'"; 13 14my $api_def = $test_data->{api_def}; 15my $tests = $test_data->{tests}; 16 17my $config = RPC::ExtDirect::Config->new( 18 debug_serialize => 1, 19 namespace => 'myApp.Server', 20 router_path => '/router.cgi', 21 poll_path => '/poll.cgi', 22 remoting_var => 'Ext.app.REMOTE_CALL_API', 23 polling_var => 'Ext.app.REMOTE_EVENT_API', 24 auto_connect => 'HELL YEAH!', 25); 26 27my $api = eval { 28 RPC::ExtDirect::API->new_from_hashref( 29 config => $config, 30 api_href => $api_def, 31 ) 32}; 33 34is $@, '', "new_from_hashref eval $@"; 35ref_ok $api, 'RPC::ExtDirect::API'; 36 37$api->config->debug_serialize(1); 38 39my $want = shift @$tests; 40my $have = eval { $api->get_remoting_api() }; 41 42is $@, '', "remoting_api() eval $@"; 43cmp_api $have, $want, "remoting_api() result"; 44 45__DATA__ 46#line 46 47{ 48 api_def => { 49 'Foo' => { 50 remote => 1, 51 methods => { 52 foo_foo => { len => 1 }, 53 foo_bar => { len => 2 }, 54 foo_blessed => { }, 55 foo_baz => { params => [qw/ foo bar baz /] }, 56 foo_zero => { len => 0 }, 57 }, 58 }, 59 'Bar' => { 60 remote => 1, 61 methods => { 62 bar_bar => { len => 5 }, 63 bar_foo => { len => 4 }, 64 bar_baz => { formHandler => 1 }, 65 }, 66 }, 67 'Qux' => { 68 remote => 1, 69 methods => { 70 foo_foo => { len => 1 }, 71 bar_bar => { len => 5 }, 72 bar_foo => { len => 4 }, 73 bar_baz => { formHandler => 1 }, 74 foo_bar => { len => 2 }, 75 foo_baz => { params => [qw/ foo bar baz /] }, 76 }, 77 }, 78 'PollProvider' => { 79 remote => 1, 80 methods => { 81 foo => { pollHandler => 1 }, 82 }, 83 }, 84 }, 85 86 tests => [ 87 q~ 88Ext.app.REMOTE_CALL_API = { 89 "actions": { 90 "Bar": [ 91 { "len":5, "name":"bar_bar" }, 92 { "len":4, "name":"bar_foo" }, 93 { "formHandler":true, "name":"bar_baz" } 94 ], 95 "Foo": [ 96 { "len":1, "name":"foo_foo" }, 97 { "len":2, "name":"foo_bar" }, 98 { "name":"foo_blessed", "params":[], "strict":false }, 99 { "name":"foo_baz", "params":["foo","bar","baz"] }, 100 { "len":0, "name":"foo_zero" } 101 ], 102 "Qux": [ 103 { "len":1, "name":"foo_foo" }, 104 { "len":5, "name":"bar_bar" }, 105 { "len":4, "name":"bar_foo" }, 106 { "formHandler":true, "name":"bar_baz" }, 107 { "len":2, "name":"foo_bar" }, 108 { "name":"foo_baz", "params":["foo","bar","baz"] } 109 ] 110 }, 111 "namespace":"myApp.Server", 112 "type":"remoting", 113 "url":"/router.cgi" 114}; 115Ext.direct.Manager.addProvider(Ext.app.REMOTE_CALL_API); 116Ext.app.REMOTE_EVENT_API = { 117 "type":"polling", 118 "url":"/poll.cgi" 119}; 120Ext.direct.Manager.addProvider(Ext.app.REMOTE_EVENT_API); 121 ~, 122 ], 123} 124