use before_dispatch plugin hook to audit requests
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 21 May 2010 14:09:44 +0000 (16:09 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 21 May 2010 14:09:44 +0000 (16:09 +0200)
lib/MojoFacets.pm

index f353f33..dd80788 100644 (file)
@@ -7,6 +7,8 @@ our $VERSION = '0.0001';
 
 use base 'Mojolicious';
 
 
 use base 'Mojolicious';
 
+use Data::Dump qw(dump);
+
 # This method will run once at server start
 sub startup {
     my $self = shift;
 # This method will run once at server start
 sub startup {
     my $self = shift;
@@ -16,6 +18,19 @@ sub startup {
 
     # Default route
     $r->route('/:controller/:action/:id')->to('data#index', id => 1);
 
     # Default route
     $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;
+                               # Do whatever you want with the transaction here
+                               if ( $tx->req->url->query ) {
+                                       warn "# before_dispatch url ",dump($tx->req->url);
+                               }
+                       }
+       );
 }
 
 1;
 }
 
 1;