Hi All, i was looking for something that's similar to "auto" in the sense that it also runs in all the parent controllers of the dispatched action, but is run right before "end" (that dispatches to the view).
The actual problem that led to this was that I had to log the processing time of the request *excluding* the processing time of the view component. Since I had some Catalyst::Controller::REST based controllers (that inherit their own "end" actions from C:P::REST) I could not put the logging in the root "end" action as it did not run for the C:P::REST based controllers. Overriding the "end" in each REST controller to call the logging is error-prone (even with a role, as one can easily forget to apply the role when writing the next REST controller). And since I wanted to exclude the processing time of the view, Catalyst::Plugin::RunAfterRequest alone did not solve my problem either - it runs after the view, thus it's perfect for the actual logging but is too late to measure the time elapsed since the beginning of the request. I did not find anything like that, so I wrote this module: https://github.com/mendel/Catalyst-Plugin-SpecialAction-Trail/blob/master/lib/Catalyst/Plugin/SpecialAction/Trail.pm Now the code looks like this: package MyApp; ... use Catalyst qw/ ... RunAfterRequest SpecialAction::Trail /; ... package MyApp::Controller::Root; ... __PACKAGE__->config(namespace => ''); ... sub trail : Private { my ($self, $c) = @_; # $c->stash->{req_start_time} is set to gettimeofday() # at the beginning of request processing my $time_elapsed = tv_interval($c->stash->{req_start_time}); $c->run_after_request(sub { <actual logging> }); } sub end : Private : ActionClass('RenderView') { ... } Comments welcome. norbi _______________________________________________ List: [email protected] Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[email protected]/ Dev site: http://dev.catalyst.perl.org/
