lib/Dancer/Exception.pm

filter: Statementstmt 96.3% 79 / 82 Branchbran 77.7% 14 / 18 Conditioncond 63.3% 19 / 30 MC/DCmcdc 37.5% 6 / 16 Subroutinesub 100% 20 / 20 Podpod 100% 6 / 6 totaltotal 83.7% 144 / 172 CC 20 SCAR 11.2
CC
20
Cov
86%
__ANON__
6.7
__ANON__
4.0
__ANON__
4.0
CRAP 3.1
« blib/lib/Dancer/Logger/Abstract.pm ↑ Summary lib/Dancer/Serializer/JSON.pm »
1 package Dancer::Exception;
2 275 our $AUTHORITY = 'cpan:SUKRIA';
3 #ABSTRACT: class for throwing and catching exceptions
4 275 $Dancer::Exception::VERSION = '1.3522';
5 275 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 275 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 275 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 275 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 275 our $Verbose = 0;
11  
12 275 ▶use Dancer::Exception::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 275 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 275 our @EXPORT_OK = (qw(try catch continuation register_exception registered_exceptions raise));
17 275 our %EXPORT_TAGS = ( all => \@EXPORT_OK );
18  
19 275 ▶use Try::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1705 ▶sub try (&;@) {
Subroutine try: called CC=1 SCAR=0.0
Pod documented
22 1705 goto &Try::Tiny::try;
23 }
24  
25 1090 ▶sub catch (&;@) {
Subroutine catch: called CC=3 SCAR=11.6
Pod documented
26 1090 my ( $block, @rest ) = @_;
27  
28 1090 my $continuation_code;
29 1090 ▶ my @new_rest = grep { ref ne 'Try::Tiny::Catch' or $continuation_code = $$_, 0 } @rest;
Condition33%1/3
ref $_ ne 'Try::Tiny::Catch' || ($continuation_code = $$_, 0)
l!l&&r!l&&!r
001
MC/DC0%0/2
ref $_ ne 'Try::Tiny::Catch' || ($continuation_code = $$_, 0)
ref $_ ne 'Try::Tiny::Catch' ($continuation_code = $$_, 0)
Truth table33%1/3
A || B
A= ref $_ ne 'Try::Tiny::Catch'B= ($continuation_code = $$_, 0)
ABresult
1X1
011
000
30 $continuation_code
31 1 ▶ and return ( bless( \ sub {
Subroutine __ANON__: called CC=4 SCAR=19.1
32 1 ▶ ref && blessed($_) && $_->isa('Dancer::Continuation')
Branch: 1 branch
BranchTrueFalseTotal
ref $_ && builtin::blessed($_) && $_->isa('Dancer::Continuation') ? : 1 0 1
Condition33%2/6
ref $_ and builtin::blessed($_) and $_->isa("Dancer::Continuation")
!ll&&!rl&&r
001
ref $_ and builtin::blessed($_)
!ll&&!rl&&r
001
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")
ABCresult
0XX0
10X0
1100
1111
33 ? $continuation_code->(@_) : $block->(@_);
34 1090 ▶ }, 'Try::Tiny::Catch') , @new_rest);
Branch: 1 branch
BranchTrueFalseTotal
$continuation_code and return bless(sub { ref $_ && builtin::blessed($_) && $_->isa("Dancer::Continuation") ? &$continuation_code(@_) : &$block(@_); } , "Try::Tiny::Catch"), @new_rest 1 1089 1090
35  
36 67 ▶ return ( bless ( \ sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
37 67 ▶ ref && blessed($_) && $_->isa('Dancer::Continuation')
Branch: 1 branch
BranchTrueFalseTotal
ref $_ && builtin::blessed($_) && $_->isa('Dancer::Continuation') ? : 1 66 67
Condition83%5/6
ref $_ and builtin::blessed($_) and $_->isa("Dancer::Continuation")
!ll&&!rl&&r
50161
ref $_ and builtin::blessed($_)
!ll&&!rl&&r
50017
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")
ABCresult
0XX0
10X0
1100
1111
38 ? die($_) : $block->(@_) ;
39 1089 }, 'Try::Tiny::Catch'), @new_rest );
40 }
41  
42 1699 ▶sub continuation (&;@) {
Subroutine continuation: called CC=3 SCAR=11.1
Pod documented
43 1699 my ( $block, @rest ) = @_;
44  
45 1699 my $catch_code;
46 1699 ▶ my @new_rest = grep { ref ne 'Try::Tiny::Catch' or $catch_code = $$_, 0 } @rest;
Condition33%1/3
ref $_ ne 'Try::Tiny::Catch' || ($catch_code = $$_, 0)
l!l&&r!l&&!r
001084
MC/DC0%0/2
ref $_ ne 'Try::Tiny::Catch' || ($catch_code = $$_, 0)
ref $_ ne 'Try::Tiny::Catch' ($catch_code = $$_, 0)
Truth table33%1/3
A || B
A= ref $_ ne 'Try::Tiny::Catch'B= ($catch_code = $$_, 0)
ABresult
1X1
011
000
47 $catch_code
48 197 ▶ and return ( bless( \ sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
49 197 ▶ ref && blessed($_) && $_->isa('Dancer::Continuation')
Branch: 1 branch
BranchTrueFalseTotal
ref $_ && builtin::blessed($_) && $_->isa('Dancer::Continuation') ? : 134 63 197
Condition83%5/6
ref $_ and builtin::blessed($_) and $_->isa("Dancer::Continuation")
!ll&&!rl&&r
4716134
ref $_ and builtin::blessed($_)
!ll&&!rl&&r
470150
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")
ABCresult
0XX0
10X0
1100
1111
50 ? $block->(@_) : $catch_code->(@_);
51 1699 ▶ }, 'Try::Tiny::Catch') , @new_rest);
Branch: 1 branch
BranchTrueFalseTotal
$catch_code and return bless(sub { ref $_ && builtin::blessed($_) && $_->isa("Dancer::Continuation") ? &$block(@_) : &$catch_code(@_); } , "Try::Tiny::Catch"), @new_rest 1084 615 1699
52  
53 38 ▶ return ( bless ( \ sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
54 38 ▶ ref && blessed($_) && $_->isa('Dancer::Continuation')
Branch: 1 branch
BranchTrueFalseTotal
ref $_ && builtin::blessed($_) && $_->isa('Dancer::Continuation') ? : 10 28 38
Condition83%5/6
ref $_ and builtin::blessed($_) and $_->isa("Dancer::Continuation")
!ll&&!rl&&r
22610
ref $_ and builtin::blessed($_)
!ll&&!rl&&r
22016
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")
ABCresult
0XX0
10X0
1100
1111
55 ? $block->(@_) : die($_);
56 615 }, 'Try::Tiny::Catch'), @new_rest );
57 }
58  
59 43 ▶sub raise ($;@) {
Subroutine raise: called CC=2 SCAR=7.1
Pod documented
60 43 my $exception_name = shift;
61 43 my $exception;
62 43 ▶ if ($exception_name =~ s/^\+//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exception_name =~ s/^\+//) { } 0 43 43
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 43 ▶sub _camelize {
Subroutine _camelize: called CC=1 SCAR=0.0
72 # using aliasing for ease of use
73 43 $_[0] =~ s/^(.)/uc($1)/e;
74 43 $_[0] =~ s/_(.)/'::' . uc($1)/eg;
75 }
76  
77 5200 ▶sub register_exception {
Subroutine register_exception: called CC=3 SCAR=11.1
Pod documented
78 5200 my ($exception_name, %params) = @_;
79 5200 my $exception_class = 'Dancer::Exception::' . $exception_name;
80 5200 my $path = $exception_class; $path =~ s|::|/|g; $path .= '.pm';
81  
82 5200 ▶ if (exists $INC{$path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $INC{$path}) 0 5200 5200
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 5200 my $message_pattern = $params{message_pattern};
90 5200 my $composed_from = $params{composed_from};
91 5200 my @composition = map { 'Dancer::Exception::' . $_ } @$composed_from;
92  
93 5200 $INC{$path} = __FILE__;
94 5200 eval "\@${exception_class}::ISA=qw(Dancer::Exception::Base " . join (' ', @composition) . ');';
95  
96 5200 ▶ if (defined $message_pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $message_pattern) 5200 0 5200
97 275 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
98 5200 ▶ *{"${exception_class}::_message_pattern"} = sub { $message_pattern };
Subroutine __ANON__: called CC=1 SCAR=0.0
99 }
100  
101 }
102  
103 2 ▶sub registered_exceptions {
Subroutine registered_exceptions: called CC=1 SCAR=0.0
Pod documented
104 2 sort map { s|/|::|g; s/\.pm$//; $_ } grep { s|^Dancer/Exception/||; } keys %INC;
105 }
106  
107 275 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 275 1;
129  
130 __END__
« blib/lib/Dancer/Logger/Abstract.pm ↑ Summary lib/Dancer/Serializer/JSON.pm »