upgrade jquery 1.7.2 and jquery-ui 1.8.21
[MojoFacets.git] / lib / MojoFacets.pm
index dd80788..c2ef3d4 100644 (file)
@@ -8,6 +8,36 @@ our $VERSION = '0.0001';
 use base 'Mojolicious';
 
 use Data::Dump qw(dump);
+use Storable;
+use Time::HiRes qw(time);
+
+
+sub save_action {
+       my ($self) = @_;
+#      warn "## before_dispatch req ",dump($tx->req->url, $tx->req->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\n";
+                               $time = $time_travel;
+                       }
+
+                       my $actions_path = '/tmp/actions/';
+                       mkdir $actions_path unless -e $actions_path;
+                       $path =~ s{/}{.}g;
+                       $actions_path .= sprintf '%.4f%s', $time, $path;
+
+                       my $array = $params->params;
+                       if ( @$array ) {
+                               store $array, $actions_path;
+                               warn "SAVE $actions_path ", -s $actions_path, " bytes params = ", dump($array), $/;
+                       }
+               }
+       }
+}
 
 # This method will run once at server start
 sub startup {
@@ -17,20 +47,25 @@ 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;
-                               # Do whatever you want with the transaction here
-                               if ( $tx->req->url->query ) {
-                                       warn "# before_dispatch url ",dump($tx->req->url);
-                               }
+       $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 );
+       }
 }
 
+
+
 1;