| 1 | package AnyEvent::XMLRPC; | ||
| 2 | |||
| 3 | 1 | ▶ | use common::sense; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | # roughly the same as, with much lower memory usage: | ||
| 5 | # | ||
| 6 | # use strict qw(vars subs); | ||
| 7 | # use feature qw(say state switch); | ||
| 8 | # no warnings; | ||
| 9 | |||
| 10 | 1 | ▶ | use utf8; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | #~ use Data::Dumper; | ||
| 12 | 0 | ▶ | use Frontier::RPC2; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 13 | |||
| 14 | use base qw(AnyEvent::HTTPD); | ||
| 15 | |||
| 16 | =encoding utf8 | ||
| 17 | |||
| 18 | =head1 NAME | ||
| 19 | |||
| 20 | AnyEvent::XMLRPC - Non-Blocking XMLRPC Server. Originally a AnyEvent implementation of Frontier. | ||
| 21 | |||
| 22 | =head1 VERSION | ||
| 23 | |||
| 24 | Version 0.05 | ||
| 25 | |||
| 26 | =cut | ||
| 27 | |||
| 28 | our $VERSION = '0.05'; | ||
| 29 | |||
| 30 | |||
| 31 | =head1 SYNOPSIS | ||
| 32 | |||
| 33 | use AnyEvent::XMLRPC; | ||
| 34 | |||
| 35 | my $serv = AnyEvent::XMLRPC->new( | ||
| 36 | methods => { | ||
| 37 | 'echo' => \&echo, | ||
| 38 | }, | ||
| 39 | ); | ||
| 40 | or | ||
| 41 | |||
| 42 | my $serv = AnyEvent::XMLRPC->new( | ||
| 43 | port => 9090, | ||
| 44 | uri => "/RPC2", | ||
| 45 | methods => { | ||
| 46 | 'echo' => \&echo, | ||
| 47 | }, | ||
| 48 | ); | ||
| 49 | |||
| 50 | and | ||
| 51 | |||
| 52 | sub echo { | ||
| 53 | @rep = qw(bala bababa); | ||
| 54 | return \@rep; | ||
| 55 | } | ||
| 56 | |||
| 57 | $serv->run; | ||
| 58 | |||
| 59 | =head1 DESCRIPTION | ||
| 60 | |||
| 61 | I<AnyEvent::XMLRPC> is a Non-Blocking XMLRPC Server. | ||
| 62 | Originally a L<AnyEvent> implementation of L<Frontier>. | ||
| 63 | I<AnyEvent::XMLRPC> is base on elmex's L<AnyEvent::HTTPD>. | ||
| 64 | |||
| 65 | =head1 FUNCTIONS | ||
| 66 | |||
| 67 | =head2 new (%options) | ||
| 68 | |||
| 69 | =cut | ||
| 70 | |||
| 71 | sub new { | ||
| 72 | my $class = shift; | ||
| 73 | my %args = @_; | ||
| 74 | |||
| 75 | $args{'port'} ||= 9090; | ||
| 76 | |||
| 77 | # extract args which are not for httpd | ||
| 78 | my $methods = delete $args{'methods'}; | ||
| 79 | my $uri = delete $args{'uri'}; | ||
| 80 | $uri ||= "/RPC2"; | ||
| 81 | |||
| 82 | # get a new clean AnyEvent::HTTPD | ||
| 83 | my $self = $class->SUPER::new(%args); | ||
| 84 | return undef unless $self; | ||
| 85 | |||
| 86 | # Now I'm AnyEvent::XMLRPC | ||
| 87 | bless $self, $class; | ||
| 88 | |||
| 89 | |||
| 90 | # register methods, use Frontier::RPC2 to encode/decode xml | ||
| 91 | ${$self}{'methods'} = $methods; | ||
| 92 | ${$self}{'decode'} = new Frontier::RPC2 'use_objects' => $args{'use_objects'}; | ||
| 93 | |||
| 94 | |||
| 95 | # register AnyEvent(::HTTPD) callbacks | ||
| 96 | $self->reg_cb ( | ||
| 97 | '/RPC2' => sub { | ||
| 98 | my ($httpd, $req) = @_; | ||
| 99 | |||
| 100 | #~ my $reply = ${$self}{'decode'}->serve( | ||
| 101 | #~ $req->content, ${$self}{'methods'} | ||
| 102 | #~ ); | ||
| 103 | |||
| 104 | $req->respond ({ content => [ | ||
| 105 | 'text/xml', | ||
| 106 | ${$self}{'decode'}->serve( | ||
| 107 | $req->content, ${$self}{'methods'} | ||
| 108 | ) | ||
| 109 | ]}); | ||
| 110 | |||
| 111 | $httpd->stop_request; | ||
| 112 | }, | ||
| 113 | '' => sub { | ||
| 114 | my ($httpd, $req) = @_; | ||
| 115 | $req->respond ({ content => ['text/html', | ||
| 116 | "I'm not something you think I am..." | ||
| 117 | ]}); | ||
| 118 | }, | ||
| 119 | ); | ||
| 120 | |||
| 121 | return $self; | ||
| 122 | } | ||
| 123 | |||
| 124 | =head1 AUTHOR | ||
| 125 | |||
| 126 | BlueT - Matthew Lien - 練喆明, C<< <BlueT at BlueT.org> >> | ||
| 127 | |||
| 128 | =head1 BUGS | ||
| 129 | |||
| 130 | Please report any bugs or feature requests to C<bug-anyevent-xmlrpc at rt.cpan.org>, or through | ||
| 131 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AnyEvent-XMLRPC>. I will be notified, and then you'll | ||
| 132 | automatically be notified of progress on your bug as I make changes. | ||
| 133 | |||
| 134 | |||
| 135 | |||
| 136 | |||
| 137 | =head1 SUPPORT | ||
| 138 | |||
| 139 | You can find documentation for this module with the perldoc command. | ||
| 140 | |||
| 141 | perldoc AnyEvent::XMLRPC | ||
| 142 | |||
| 143 | |||
| 144 | You can also look for information at: | ||
| 145 | |||
| 146 | =over 4 | ||
| 147 | |||
| 148 | =item * Git repository | ||
| 149 | |||
| 150 | L<http://github.com/BlueT/AnyEvent-XMLRPC> | ||
| 151 | |||
| 152 | =item * RT: CPAN's request tracker | ||
| 153 | |||
| 154 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-XMLRPC> | ||
| 155 | |||
| 156 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 157 | |||
| 158 | L<http://annocpan.org/dist/AnyEvent-XMLRPC> | ||
| 159 | |||
| 160 | =item * CPAN Ratings | ||
| 161 | |||
| 162 | L<http://cpanratings.perl.org/d/AnyEvent-XMLRPC> | ||
| 163 | |||
| 164 | =item * Search CPAN | ||
| 165 | |||
| 166 | L<http://search.cpan.org/dist/AnyEvent-XMLRPC> | ||
| 167 | |||
| 168 | =back | ||
| 169 | |||
| 170 | |||
| 171 | =head1 ACKNOWLEDGEMENTS | ||
| 172 | |||
| 173 | |||
| 174 | =head1 COPYRIGHT & LICENSE | ||
| 175 | |||
| 176 | Copyright 2009 BlueT - Matthew Lien - 練喆明, all rights reserved. | ||
| 177 | |||
| 178 | This program is free software; you can redistribute it and/or modify it | ||
| 179 | under the same terms as Perl itself. | ||
| 180 | |||
| 181 | |||
| 182 | =cut | ||
| 183 | |||
| 184 | 1; # End of AnyEvent::XMLRPC | ||