fix database name in view
[angular-mojolicious.git] / mmonit / collector.pl
1 #!/usr/bin/env perl
2 use Mojolicious::Lite;
3
4 # Documentation browser under "/perldoc"
5 #plugin 'PODRenderer';
6
7 use Mojo::JSON;
8 use Mojo::UserAgent;
9 use Data::Dump qw(dump);
10 use XML::Simple;
11 use Time::HiRes;
12
13 my $json = Mojo::JSON->new;
14 my $client = Mojo::UserAgent->new;
15
16 post '/collector' => sub {
17         my $self = shift;
18         my $data = XMLin( $self->req->body );
19         warn dump( $data );
20
21         # post will create new dockument, put will insert known key
22         my $key = sprintf "%10.5f", Time::HiRes::time;
23         my $res = $client->put( "http://localhost:5984/mmonit/$key" => { 'Content-Type' => 'application/json' } => $json->encode( $data ) )->res->json;
24
25         warn "# res = ",dump($res);
26
27         $self->render('index');
28 };
29
30 app->start;
31 __DATA__
32
33 @@ index.html.ep
34 % layout 'default';
35 % title 'Welcome';
36 Welcome to Mojolicious!
37
38 @@ layouts/default.html.ep
39 <!doctype html><html>
40   <head><title><%= title %></title></head>
41   <body><%= content %></body>
42 </html>