Exception-Reporter-Summarizer-Catalyst
    
    
  
  
  
view release on metacpan or search on metacpan
lib/Exception/Reporter/Summarizer/Catalyst.pm view on Meta::CPAN
use strict;
use warnings;
package Exception::Reporter::Summarizer::Catalyst 0.005;
use parent 'Exception::Reporter::Summarizer';
# ABSTRACT: a summarizer for Catalyst applications
#pod =head1 OVERVIEW
#pod
#pod If added as a summarizer to an L<Exception::Reporter>, this plugin will
#pod summarize Catalyst objects, adding summaries for the request, stash, errors,
#pod user, and session.
#pod
#pod =attr resolve_hostname
#pod
#pod If true, the summary will include the hostname of the remote client.  Catalyst
#pod I<always> resolves this hostname the first time it's requested and I<never>
#pod accepts it from the server.  That means it might be slow.
#pod
#pod Right now, this defaults to true.  It might default to false later.  Consider
#pod being explicit if you're concerned about this behavior.
#pod
#pod =cut
use Try::Tiny;
sub new {
  my ($class, $arg) = @_;
  $arg ||= {};
  return bless { resolve_hostname => !! $arg->{resolve_hostname} } => $class;
}
sub resolve_hostname { $_[0]->{resolve_hostname} }
sub can_summarize {
  my ($self, $entry) = @_;
  return try { $entry->[1]->isa('Catalyst') };
}
sub summarize {
  my ($self, $entry) = @_;
  my ($name, $c, $arg) = @$entry;
  my @summaries = ({
    filename => 'catalyst.txt',
    %{ 
      $self->dump(
        {
          class   => (ref $c),
          version => $c->VERSION,
        },
        { basename => 'catalyst' },
      )  
    },
    ident => 'Catalyst application ' . (ref $c),
  });
  push @summaries, $self->summarize_request($c);
  # push @summaries, $self->summarize_response($c);
  push @summaries, $self->summarize_stash($c);
  push @summaries, $self->summarize_errors($c);
  push @summaries, $self->summarize_user($c);
  push @summaries, $self->summarize_session($c);
  return @summaries;
}
sub summarize_request {
  my ($self, $c) = @_;
  my $req = $c->req;
  my $cookie_hash = $req->cookies;
  my %cookie_str = map {; $_ => $cookie_hash->{$_}->value } keys %$cookie_hash;
  my $to_dump = {
    action           => $req->action,
    address          => $req->address,
    arguments        => $req->arguments,
    body_parameters  => $req->body_parameters,
    cookies          => \%cookie_str,
    headers          => $req->headers,
    method           => $req->method,
    query_parameters => $req->query_parameters,
    uri              => "" . $req->uri,
    uploads          => $req->uploads,
    path             => $req->path,
    ($self->resolve_hostname ? (hostname => $req->hostname) : ()),
    
  
  
  
( run in 0.222 second using v1.01-cache-2.11-cpan-a1d94b6210f )