From e78d1bd4c3de9574ac9777f1f3dd22598e90d68b Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sat, 22 May 2010 14:02:07 +0200 Subject: [PATCH] store requests in /tmp/changes using Storable --- lib/MojoFacets.pm | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/MojoFacets.pm b/lib/MojoFacets.pm index dd80788..5e91832 100644 --- a/lib/MojoFacets.pm +++ b/lib/MojoFacets.pm @@ -8,6 +8,27 @@ 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' ) { + + my $path = '/tmp/changes/'; + mkdir $path unless -e $path; + $path .= sprintf '%.4f.%s', time(), join('.', @$parts); + store $tx->req->params, $path; + # $self->log->info( "$path ", -s $path, " bytes\n" ); + warn "$path ", -s $path, " bytes\n"; + + } +} + # This method will run once at server start sub startup { @@ -25,12 +46,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; -- 2.20.1