reformat changes as table and show relative time
[MojoFacets.git] / lib / MojoFacets.pm
1 package MojoFacets;
2
3 use strict;
4 use warnings;
5
6 our $VERSION = '0.0001';
7
8 use base 'Mojolicious';
9
10 use Data::Dump qw(dump);
11 use Storable;
12 use Time::HiRes qw(time);
13
14
15 sub save_tx {
16         my ($self,$tx) = @_;
17 #       warn "## before_dispatch req ",dump($tx->req->url, $tx->req->params);
18         my $parts = $tx->req->url->path->parts;
19         warn "# parts ",dump( $parts );
20         if ( $parts->[0] eq 'data' ) {
21                 if ( my $params = $tx->req->params ) {
22
23                         my $path = '/tmp/changes/';
24                         mkdir $path unless -e $path;
25                         $path .= sprintf '%.4f.%s', time(), join('.', @$parts);
26
27                         store $params, $path;
28                         warn "$path ", -s $path, " bytes\n";
29                 }
30         }
31 }
32
33
34 # This method will run once at server start
35 sub startup {
36     my $self = shift;
37
38     # Routes
39     my $r = $self->routes;
40
41     # Default route
42     $r->route('/:controller/:action/:id')->to('data#index', id => 1);
43
44 #       $self->plugin( 'request_timer' );
45
46         $self->plugins->add_hook(
47                         before_dispatch => sub {
48                                 my ($self, $c) = @_;
49                                 my $tx = $c->tx;
50                                 save_tx( $self, $tx );
51                         }
52         );
53 }
54
55
56
57 1;