Skip to content

Commit

Permalink
refactor save_action to save only params
Browse files Browse the repository at this point in the history
  • Loading branch information
dpavlin committed Jul 8, 2011
1 parent 9f5f80a commit 2b956f2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
36 changes: 18 additions & 18 deletions lib/MojoFacets.pm
Expand Up @@ -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), $/;
}
}
}
}
Expand All @@ -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 );
}
);

Expand Down
7 changes: 3 additions & 4 deletions templates/actions/view.html.ep
Expand Up @@ -11,11 +11,10 @@
% if ( my $master = $ENV{'MASTER'} ) {
<input class=replication type=checkbox name="_master" value="<%= $master %>" title="replicate to <%= $master %>">
% }
% my $params = $change->{params};
<ul>
% while ( @$params ) {
% my $n = shift @$params;
% my $v = shift @$params;
% while ( @$change ) {
% my $n = shift @$change;
% my $v = shift @$change;
<li><label class=checkbox_to_text>
<%= $n %>
<span class=value title="double click to edit">
Expand Down
4 changes: 2 additions & 2 deletions templates/data/items/table.html.ep
Expand Up @@ -13,9 +13,9 @@
<span title="unique">&#9997;</span>
% }
% if ( session('order') ne $n ) {
<a href="<%= url_for( action => 'order' )->query( order => $n, sort => 'a' ) %>"><%= $n %></a>
<a href="<%= url_for( action => 'items' )->query( order => $n, sort => 'a' ) %>"><%= $n %></a>
% } else {
<a href="<%= url_for( action => 'order' )->query( order => $n, sort => session('sort') eq 'a' ? 'd' : 'a' ) %>"><%= $n %></a>
<a href="<%= url_for( action => 'items' )->query( order => $n, sort => session('sort') eq 'a' ? 'd' : 'a' ) %>"><%= $n %></a>
<%== session('sort') eq 'a' ? '&uarr;' : '&darr;' %>
% }
<div class="col_opts">
Expand Down

0 comments on commit 2b956f2

Please sign in to comment.