use before_dispatch plugin hook to audit requests
[MojoFacets.git] / lib / MojoFacets.pm
1 package MojoFacets;
2
3 use strict;
4 use warnings;
5
6 our $VERSION = '0.0001';
7
8 use base 'Mojolicious';
9
10 use Data::Dump qw(dump);
11
12 # This method will run once at server start
13 sub startup {
14     my $self = shift;
15
16     # Routes
17     my $r = $self->routes;
18
19     # Default route
20     $r->route('/:controller/:action/:id')->to('data#index', id => 1);
21
22 #       $self->plugin( 'request_timer' );
23
24         $self->plugins->add_hook(
25                         before_dispatch => sub {
26                                 my ($self, $c) = @_;
27                                 my $tx = $c->tx;
28                                 # Do whatever you want with the transaction here
29                                 if ( $tx->req->url->query ) {
30                                         warn "# before_dispatch url ",dump($tx->req->url);
31                                 }
32                         }
33         );
34 }
35
36 1;