Changeset 14291 for lang/perl/POE-Component-Server-JSONRPC
- Timestamp:
- 06/20/08 16:31:36 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/POE-Component-Server-JSONRPC/trunk/ex.pl
r14244 r14291 5 5 6 6 use List::Util (); 7 use Devel::PartialDump; 7 8 8 9 POE::Session->create( … … 10 11 _start => sub { 11 12 POE::Component::Server::JSONRPC->new( 12 handler => { 13 'echo' => 'echo', 14 'sum' => 'sum', 15 'echo_in' => 'echo_in', 16 }, 13 handler => "rpc", 17 14 tcp => { 18 15 Port => 3000, … … 21 18 ); 22 19 }, 23 echo_in => \&echo_in,24 echo => \&echo,25 sum => \&sum,26 do_callback => sub { eval { $_[ARG0]->() } }27 20 }, 21 package_states => [ 22 __PACKAGE__, { map { $_ => $_ } qw( 23 rpc 24 do_callback 25 echo_in 26 echo 27 sum 28 die 29 )}, 30 ], 28 31 ); 32 33 sub do_callback { 34 if ( my $cb = $_[ARG0] ) { 35 $cb->(); 36 } 37 } 38 39 sub rpc { 40 my ($kernel, $cb, $call) = @_[KERNEL, ARG0, ARG1]; 41 42 my $method = $call->method; 43 44 if ( __PACKAGE__->can($method) ) { 45 # call as a state, so that delays can be set. 46 # ordinarily we could just do eval { $cb->( $self->$method ) } 47 unless ( eval { $kernel->call( $_[SESSION], $method, @_[ARG0 .. $#_] ); 1 } ) { 48 $cb->( $call->return_error($@) ); 49 } 50 } else { 51 $cb->( $call->return_error( message => sprintf 'No such method "%s"', $method ) ); 52 } 53 } 54 55 sub die { 56 my ($cb, $call) = @_[ARG0, ARG1]; 57 die { message => Devel::PartialDump::dump($call->params_list) }; 58 } 29 59 30 60 sub echo_in {
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)