X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=lib%2FMojoFacets.pm;h=9a5b315831fb6d195e102f13f2cf8083c25805e4;hb=add6d343a92cd01879d1d822bf78bb9a4a3ae8ff;hp=3455b952ec87eec36ea52afd7e5e11cf6f0a61a2;hpb=4a2f8d04e852084a3ac7488f4fd866e11d16dcc4;p=MojoFacets.git diff --git a/lib/MojoFacets.pm b/lib/MojoFacets.pm index 3455b95..9a5b315 100644 --- a/lib/MojoFacets.pm +++ b/lib/MojoFacets.pm @@ -7,6 +7,38 @@ 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 ) { + + warn "# params ",dump($params); + + my $time = time(); + if ( my $time_travel = $params->param('time') ) { + warn "# time-travel to $time_travel from ", $tx->remote_address; + $time = $time_travel; + } + + my $path = '/tmp/actions/'; + 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 { my $self = shift; @@ -15,7 +47,19 @@ sub startup { my $r = $self->routes; # Default route - $r->route('/:controller/:action/:id')->to('data#stats', id => 1); + $r->route('/:controller/:action/:id')->to('data#index', id => 1); + +# $self->plugin( 'request_timer' ); + + $self->plugins->add_hook( + before_dispatch => sub { + my ($self, $c) = @_; + my $tx = $c->tx; + save_tx( $self, $tx ); + } + ); } + + 1;