From 2b956f2bbe125929adbf718fb6b0d721fde1df52 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 8 Jul 2011 14:23:17 +0200 Subject: [PATCH] refactor save_action to save only params --- lib/MojoFacets.pm | 36 +++++++++++++++--------------- templates/actions/view.html.ep | 7 +++--- templates/data/items/table.html.ep | 4 ++-- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/lib/MojoFacets.pm b/lib/MojoFacets.pm index 1f34ea8..9146e2f 100644 --- a/lib/MojoFacets.pm +++ b/lib/MojoFacets.pm @@ -12,28 +12,29 @@ use Storable; use Time::HiRes qw(time); -sub save_tx { - my ($self,$tx) = @_; +sub save_action { + my ($self) = @_; # 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 $path = $self->req->url->path; + if ( $path =~ m{/data/} ) { + if ( my $params = $self->req->params ) { my $time = time(); if ( my $time_travel = $params->param('time') ) { - warn "# time-travel to $time_travel from ", $tx->remote_address; + warn "# time-travel to $time_travel\n"; $time = $time_travel; } - my $path = '/tmp/actions/'; - mkdir $path unless -e $path; - $path .= sprintf '%.4f.%s', $time, join('.', @$parts); + my $actions_path = '/tmp/actions/'; + mkdir $actions_path unless -e $actions_path; + $path =~ s{/}{.}g; + $actions_path .= sprintf '%.4f%s', $time, $path; - store $params, $path; - warn "$path ", -s $path, " bytes\n"; + my $array = $params->params; + if ( @$array ) { + store $array, $actions_path; + warn "SAVE $actions_path ", -s $actions_path, " bytes params = ", dump($array), $/; + } } } } @@ -51,10 +52,9 @@ sub startup { # $self->plugin( 'request_timer' ); $self->plugins->add_hook( - before_dispatch => sub { - my ($self, $c) = @_; - my $tx = $c->tx; - save_tx( $self, $tx ); + after_dispatch => sub { + my ($self) = @_; + save_action( $self ); } ); diff --git a/templates/actions/view.html.ep b/templates/actions/view.html.ep index d70d3cc..98e4324 100644 --- a/templates/actions/view.html.ep +++ b/templates/actions/view.html.ep @@ -11,11 +11,10 @@ % if ( my $master = $ENV{'MASTER'} ) { % } -% my $params = $change->{params};