X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2FMojoFacets.pm;h=c80e7489416b26566a8478c085c623f394b5b691;hb=b0d2178ef6767587f99341bbdc245eb65bd31b63;hp=dd8078823c02f824d4bfc565eeffd27028367d24;hpb=d4b6362ce5d4504c8e002e7c6861e714d0d68cf4;p=MojoFacets.git diff --git a/lib/MojoFacets.pm b/lib/MojoFacets.pm index dd80788..c80e748 100644 --- a/lib/MojoFacets.pm +++ b/lib/MojoFacets.pm @@ -8,6 +8,28 @@ our $VERSION = '0.0001'; use base 'Mojolicious'; use Data::Dump qw(dump); +use Storable; +use Time::HiRes qw(time); + + +sub save_tx { + my ($self,$tx) = @_; +# warn "## before_dispatch req ",dump($tx->req->url, $tx->req->params); + my $parts = $tx->req->url->path->parts; + warn "# parts ",dump( $parts ); + if ( $parts->[0] eq 'data' ) { + if ( my $params = $tx->req->params ) { + + my $path = '/tmp/changes/'; + mkdir $path unless -e $path; + $path .= sprintf '%.4f.%s', time(), join('.', @$parts); + + store $params, $path; + warn "$path ", -s $path, " bytes\n"; + } + } +} + # This method will run once at server start sub startup { @@ -25,12 +47,11 @@ sub startup { before_dispatch => sub { my ($self, $c) = @_; my $tx = $c->tx; - # Do whatever you want with the transaction here - if ( $tx->req->url->query ) { - warn "# before_dispatch url ",dump($tx->req->url); - } + save_tx( $self, $tx ); } ); } + + 1;