X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=lib%2FMojoFacets.pm;h=cf52becaadf29ceb2f1b2e379df8ded3d35a1bf2;hb=435913283b2941a6e1c20d6b2ac20c7f6895bddd;hp=e68fde8d9fc42897b867f993bb8a46c676cb3d9f;hpb=3b424526d012b5bd5b1212bcc996b41738b559b3;p=MojoFacets.git diff --git a/lib/MojoFacets.pm b/lib/MojoFacets.pm index e68fde8..cf52bec 100644 --- a/lib/MojoFacets.pm +++ b/lib/MojoFacets.pm @@ -12,33 +12,33 @@ 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/changes/'; - 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 $hash = $params->to_hash; + if ( $hash ) { + store $hash, $actions_path; + warn "SAVE $actions_path ", -s $actions_path, " bytes params = ", dump($hash), $/; + } } } } - # This method will run once at server start sub startup { my $self = shift; @@ -47,17 +47,23 @@ sub startup { my $r = $self->routes; # Default route - $r->route('/:controller/:action/:id')->to('data#index', id => 1); + $r->route('/:controller/:action/:id')->to('data#index', id => 0); # $self->plugin( 'request_timer' ); - $self->plugins->add_hook( - before_dispatch => sub { - my ($self, $c) = @_; - my $tx = $c->tx; - save_tx( $self, $tx ); + $self->hook( + after_dispatch => sub { + my ($self) = @_; + save_action( $self ); } ); + + eval 'use MojoFacets::Plugin::NYTProf'; + if ( $@ ) { + warn "profile disabled: ",substr($@,0,40) if $@; + } else { + MojoFacets::Plugin::NYTProf->register( $self ); + } }