| 1 | package Dancer::Exception; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 266 | our $AUTHORITY = 'cpan:SUKRIA'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | #ABSTRACT: class for throwing and catching exceptions | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 266 | $Dancer::Exception::VERSION = '1.3520'; | |||||||||||||||||||||||||||||||||||||||||
| 5 | 266 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 266 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 266 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 266 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 266 | our $Verbose = 0; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 266 | ▶ | use Dancer::Exception::Base; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 266 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 266 | our @EXPORT_OK = (qw(try catch continuation register_exception registered_exceptions raise)); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 266 | our %EXPORT_TAGS = ( all => \@EXPORT_OK ); | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 266 | ▶ | use Try::Tiny (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | sub try (&;@) { | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 1705 | ▶ | goto &Try::Tiny::try; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
try: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | sub catch (&;@) { | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 1090 | ▶ | my ( $block, @rest ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
catch: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1090 | my $continuation_code; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 1090 | ▶ | my @new_rest = grep { ref ne 'Try::Tiny::Catch' or $continuation_code = $$_, 0 } @rest; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | $continuation_code | ||||||||||||||||||||||||||||||||||||||||||
| 31 | and return ( bless( \ sub { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | ref && blessed($_) && $_->isa('Dancer::Continuation') | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=19.1
Branch: 1 branch
Condition33%2/6
ref $_ and builtin::blessed($_) and $_->isa("Dancer::Continuation")
ref $_ and builtin::blessed($_)
MC/DC0%0/3
ref $_ and builtin::blessed($_) and $_->isa("Dancer::Continuation")
ref $_
builtin::blessed($_)
$_->isa("Dancer::Continuation")
Truth table25%1/4
A and B and C
A= ref $_B= builtin::blessed($_)C= $_->isa("Dancer::Continuation")
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | ? $continuation_code->(@_) : $block->(@_); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 1090 | ▶ | }, 'Try::Tiny::Catch') , @new_rest); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | return ( bless ( \ sub { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 67 | ▶ | ref && blessed($_) && $_->isa('Dancer::Continuation') | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
Condition83%5/6
ref $_ and builtin::blessed($_) and $_->isa("Dancer::Continuation")
ref $_ and builtin::blessed($_)
MC/DC66%2/3
ref $_ and builtin::blessed($_) and $_->isa("Dancer::Continuation")
ref $_
builtin::blessed($_)
$_->isa("Dancer::Continuation")
Truth table75%3/4
A and B and C
A= ref $_B= builtin::blessed($_)C= $_->isa("Dancer::Continuation")
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | ? die($_) : $block->(@_) ; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 1089 | }, 'Try::Tiny::Catch'), @new_rest ); | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | sub continuation (&;@) { | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 1699 | ▶ | my ( $block, @rest ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
continuation: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1699 | my $catch_code; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 1699 | ▶ | my @new_rest = grep { ref ne 'Try::Tiny::Catch' or $catch_code = $$_, 0 } @rest; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | $catch_code | ||||||||||||||||||||||||||||||||||||||||||
| 48 | and return ( bless( \ sub { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 197 | ▶ | ref && blessed($_) && $_->isa('Dancer::Continuation') | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
Condition83%5/6
ref $_ and builtin::blessed($_) and $_->isa("Dancer::Continuation")
ref $_ and builtin::blessed($_)
MC/DC66%2/3
ref $_ and builtin::blessed($_) and $_->isa("Dancer::Continuation")
ref $_
builtin::blessed($_)
$_->isa("Dancer::Continuation")
Truth table75%3/4
A and B and C
A= ref $_B= builtin::blessed($_)C= $_->isa("Dancer::Continuation")
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | ? $block->(@_) : $catch_code->(@_); | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 1699 | ▶ | }, 'Try::Tiny::Catch') , @new_rest); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | return ( bless ( \ sub { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 38 | ▶ | ref && blessed($_) && $_->isa('Dancer::Continuation') | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
Condition83%5/6
ref $_ and builtin::blessed($_) and $_->isa("Dancer::Continuation")
ref $_ and builtin::blessed($_)
MC/DC66%2/3
ref $_ and builtin::blessed($_) and $_->isa("Dancer::Continuation")
ref $_
builtin::blessed($_)
$_->isa("Dancer::Continuation")
Truth table75%3/4
A and B and C
A= ref $_B= builtin::blessed($_)C= $_->isa("Dancer::Continuation")
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | ? $block->(@_) : die($_); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 615 | }, 'Try::Tiny::Catch'), @new_rest ); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | sub raise ($;@) { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 43 | ▶ | my $exception_name = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
raise: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 43 | my $exception; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 43 | ▶ | if ($exception_name =~ s/^\+//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $exception = $exception_name->new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 43 | _camelize($exception_name); | |||||||||||||||||||||||||||||||||||||||||
| 66 | 43 | $exception = "Dancer::Exception::$exception_name"->new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 41 | $exception->throw(); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | sub _camelize { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # using aliasing for ease of use | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 43 | ▶ | $_[0] =~ s/^(.)/uc($1)/e; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_camelize: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 43 | $_[0] =~ s/_(.)/'::' . uc($1)/eg; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | sub register_exception { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 5029 | ▶ | my ($exception_name, %params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_exception: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 5029 | my $exception_class = 'Dancer::Exception::' . $exception_name; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 5029 | my $path = $exception_class; $path =~ s|::|/|g; $path .= '.pm'; | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 5029 | ▶ | if (exists $INC{$path}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | local $Carp::CarpLevel = $Carp::CarpLevel++; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | 'Dancer::Exception::Base::Internal' | |||||||||||||||||||||||||||||||||||||||||
| 85 | ->new("register_exception failed: $exception_name is already defined") | ||||||||||||||||||||||||||||||||||||||||||
| 86 | ->throw; | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 5029 | my $message_pattern = $params{message_pattern}; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 5029 | my $composed_from = $params{composed_from}; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 5029 | my @composition = map { 'Dancer::Exception::' . $_ } @$composed_from; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 5029 | $INC{$path} = __FILE__; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 5029 | eval "\@${exception_class}::ISA=qw(Dancer::Exception::Base " . join (' ', @composition) . ');'; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 5029 | ▶ | if (defined $message_pattern) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 266 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 5029 | ▶ | *{"${exception_class}::_message_pattern"} = sub { $message_pattern }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | sub registered_exceptions { | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | ▶ | sort map { s|/|::|g; s/\.pm$//; $_ } grep { s|^Dancer/Exception/||; } keys %INC; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
registered_exceptions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 266 | register_exception(@$_) foreach ( | |||||||||||||||||||||||||||||||||||||||||
| 108 | [ 'Core', message_pattern => 'core - %s' ], | ||||||||||||||||||||||||||||||||||||||||||
| 109 | [ 'Core::App', message_pattern => 'core - app - %s', composed_from => [ qw(Core) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 110 | [ 'Core::Config', message_pattern => 'core - config - %s', composed_from => [ qw(Core) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 111 | [ 'Core::Deprecation', message_pattern => 'core - deprecation - %s', composed_from => [ qw(Core) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 112 | [ 'Core::Engine', message_pattern => 'core - engine - %s', composed_from => [ qw(Core) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 113 | [ 'Core::Factory', message_pattern => 'core - factory - %s', composed_from => [ qw(Core) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 114 | [ 'Core::Factory::Hook', message_pattern => 'core - hook - %s', composed_from => [ qw(Core::Factory) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 115 | [ 'Core::Hook', message_pattern => 'core - hook - %s', composed_from => [ qw(Core) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 116 | [ 'Core::Fileutils', message_pattern => 'core - file utils - %s', composed_from => [ qw(Core) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 117 | [ 'Core::Handler', message_pattern => 'core - handler - %s', composed_from => [ qw(Core) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 118 | [ 'Core::Handler::PSGI', message_pattern => 'core - handler - %s', composed_from => [ qw(Core::Handler) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 119 | [ 'Core::Plugin', message_pattern => 'core - plugin - %s', composed_from => [ qw(Core) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 120 | [ 'Core::Renderer', message_pattern => 'core - renderer - %s', composed_from => [ qw(Core) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 121 | [ 'Core::Request', message_pattern => 'core - request - %s', composed_from => [ qw(Core) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 122 | [ 'Core::Route', message_pattern => 'core - route - %s', composed_from => [ qw(Core) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 123 | [ 'Core::Serializer', message_pattern => 'core - serializer - %s', composed_from => [ qw(Core) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 124 | [ 'Core::Template', message_pattern => 'core - template - %s', composed_from => [ qw(Core) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 125 | [ 'Core::Session', message_pattern => 'core - session - %s', composed_from => [ qw(Core) ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 266 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | __END__ | ||||||||||||||||||||||||||||||||||||||||||