Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

This is the XML-RPC client.

#!/usr/bin/perl use strict; use warnings; use Frontier::Client; my $number; { print "Enter a number\n"; $number = <STDIN>; chomp($number); redo unless $number =~ /^\d+$/; } my $server_url = 'http://localhost/square/index.cgi/RPC2'; my $server = Frontier::Client->new(url => $server_url); my $result = $server->call('sample.square', $number); my $square = $result->{'square'}; my $difference = $result->{'difference'}; print "The square of $number is $square.\n";

This is the CGI::Application subclass which implements the functionality of the server.

package Square; use base 'CGI::Application'; sub setup { my ($self) = @_; $ENV{'PATH'} = ''; my @pi = split(m{/}, $self->query->path_info()); $self->start_mode(($pi[1] eq 'RPC2') ? 'RPC2' : 'view'); $self->run_modes( 'view' => 'view', 'RPC2' => 'rpc2', ); } sub view { my ($self) = @_; my $number = $self->query->param('number'); my $template = $self->load_tmpl('view'); $template->param(NUMBER => $number, SQUARE => square($number)->{square}, ); return $template->output; } sub rpc2 { my ($self) = @_; require Frontier::RPC2; my $rpc = Frontier::RPC2->new(); my $response = $rpc->serve($self->query->param('POSTDATA'), { 'sample.square' => \&square, }, ); $self->header_props( -type => 'text/xml', charset => 'UTF-8', ); return $response; } sub square { my ($x) = @_; return {square => ($x ** 2)}; } 1;

Here is the driver script that uses the above module:

#!/usr/bin/perl -T use warnings; use strict; use lib '.'; use Square; my $square = Square->new(); $square->run();

Here is the HTML::Template used in the view run mode.

<html> <head> <title>Square Two Numbers</title> </head> <body> <h1>Square Two Numbers</h1> <form action="http://localhost/square/index.cgi/view" method="POST +"> Enter a number: <input type="text" name="number"> <input type="submit"> </form> <!-- TMPL_IF NAME="number" --> <p>The square of <!-- TMPL_VAR NAME="number" --> is <!-- TMPL_V +AR NAME="square" -->.</p> <!-- /TMPL_IF --> </body> </html>

In reply to XML-RPC in a CGI::Application by jaldhar

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (1)
    As of 2021-02-26 04:41 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found