Dancer2

 view release on metacpan or  search on metacpan

lib/Dancer2/Core/Error.pm  view on Meta::CPAN

package Dancer2::Core::Error;
# ABSTRACT: Class representing fatal errors
$Dancer2::Core::Error::VERSION = '2.1.0';
use Moo;
use Carp;
use Dancer2::Core::Types;
use Dancer2::Core::MIME;
use Dancer2::Core::HTTP;
use Data::Dumper;
use Path::Tiny ();
use Sub::Quote;
use Module::Runtime qw/ require_module use_module /;
use Ref::Util qw< is_hashref >;
use Clone qw(clone);

has app => (
    is        => 'ro',
    isa       => InstanceOf['Dancer2::Core::App'],
    predicate => 'has_app',
);

has show_stacktrace => (
    is      => 'ro',
    isa     => Bool,
    default => sub {
        my $self = shift;

        $self->has_app
            and return $self->app->setting('show_stacktrace');
    },
);

has charset => (
    is      => 'ro',
    isa     => Str,
    default => sub {'UTF-8'},
);

has type => (
    is      => 'ro',
    isa     => Str,
    default => sub {'Runtime Error'},
);

has title => (
    is      => 'ro',
    isa     => Str,
    lazy    => 1,
    builder => '_build_title',
);

has censor => (
    is => 'ro',
    isa => CodeRef,
    lazy => 1, 
    default => sub {
        my $self = shift;

        if( my $custom = $self->has_app && $self->app->setting('error_censor') ) {

            if( is_hashref $custom ) {
                die "only one key can be set for the 'error_censor' setting\n" 
                    if 1 != keys %$custom;

                my( $class, $args ) = %$custom;

                my $censor = use_module($class)->new(%$args);

                return sub {
                    $censor->censor(@_);
                }
            }



( run in 1.752 second using v1.01-cache-2.11-cpan-39bf76dae61 )