I've done SOAP and many many custom XML interchanges. They are all either fairly cumbersome or they just feel heavy. Ninety-five percent of the time now I just use JSON. It is easy to add to any Catalyst, CGI::Appliation, CGI::Ex::App, or whatever type application.
sub json_run_step {
my $self = shift;
my $form = $self->form;
my $type = $form->{'type'};
my $data;
my $ok = eval {
die "Invalid type \"$type\"\n" if $type !~ /^[a-z]\w+$/;
die "Invalid method \"$type\"\n" if ! $self->can($type);
$data = $self->$type($form);
};
if (! $ok) {
$data = {
error => "$@" || "An error occurred",
};
}
$self->cgix->print_content_type('application/x-javascript');
print JSON::to_json($data)."\n";
return 1;
}
With JSON, my exposed methods are easily available to other perl scripts, or more importantly, they are available to my javascript applications (AJAX isn't quite the word here as the "Asychronous" and "And XML" don't apply in many of my scripts - so all you are left with is the the J".
I know that this sort of solution doesn't include parameter checking, but normally my methods include any of the bounds checking that I may need.
my @a=qw(random brilliant braindead); print $a[rand(@a)];
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|