#!/usr/bin/env perl
get
"/"
=>
sub
{
my
$self
=
shift
;
$self
->render(
text
=>
"<h1>It works!</h1>\n<p>This is the PickLE web server.</p>\n"
);
};
post
"/export/:ftype"
=>
sub
{
my
$self
=
shift
;
my
$format
=
$self
->param(
'ftype'
);
my
$document
= PickLE::Document->from_string(
$self
->req->body);
if
(not
defined
$document
) {
return
$self
->reply->exception(
"There were errors while trying to parse the document.\n"
);
}
if
(
$format
eq
'pickle'
) {
return
$self
->render_text(
$document
->as_string,
format
=>
'txt'
);
}
elsif
(
$format
eq
'json'
) {
return
$self
->render(
json
=> PickLE::Exporter::JSON->as_hash(
$document
));
}
elsif
(
$format
eq
'html'
) {
return
$self
->render(
text
=> PickLE::Exporter::HTML->as_string(
$document
));
}
return
$self
->reply->exception(
"Unknown type of file to be exported.\n"
);
};
app->start();