blib/lib/Error/TypeTiny.pm

filter: Statementstmt 98.3% 60 / 61 Branchbran 77.7% 14 / 18 Conditioncond 58.8% 10 / 17 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 100% 16 / 16 Podpod 100% 8 / 8 totaltotal 84.6% 110 / 130 CC 17 SCAR 16.9
CC
17
Cov
88%
throw_cb
11.2
to_string
5.9
new
2.1
CRAP 5.4
« blib/lib/Reply/Plugin/TypeTiny.pm ↑ Summary blib/lib/Error/TypeTiny/WrongNumberOfParameters.pm »
1 package Error::TypeTiny;
2  
3 290 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 290 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 290 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 290 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 290 $Error::TypeTiny::AUTHORITY = 'cpan:TOBYINK';
9 290 $Error::TypeTiny::VERSION = '2.010001';
10 }
11  
12 290 $Error::TypeTiny::VERSION =~ tr/_//d;
13  
14 290 require Type::Tiny;
15 __PACKAGE__->Type::Tiny::_install_overloads(
16 730 ▶ q[""] => sub { local $@; $_[0]->to_string },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 854 ▶ q[bool] => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 290 );
19  
20 290 require Carp;
21 290 *CarpInternal = \%Carp::CarpInternal;
22  
23 290 our %CarpInternal;
24 290 $CarpInternal{$_}++ for @Type::Tiny::InternalPackages;
25  
26 879 ▶sub new {
Subroutine new: called CC=2 SCAR=7.6
Pod documented
27 879 my $class = shift;
28 0 ▶ my %params = ( @_ == 1 ) ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 879 879
29 879 return bless \%params, $class;
30 }
31  
32 450 ▶sub throw {
Subroutine throw: called CC=1 SCAR=0.0
Pod documented
33 450 my $next = $_[0]->can( 'throw_cb' );
34 450 splice( @_, 1, 0, undef );
35 450 goto $next;
36 }
37  
38 878 ▶sub throw_cb {
Subroutine throw_cb: called CC=11 SCAR=24.1
Pod documented
39 878 my $class = shift;
40 878 my $callback = shift;
41
42 878 my ( $level, @caller, %ctxt ) = 0;
43 878 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if (do { my $caller = caller $level; defined $caller and $Error::TypeTiny::CarpInternal{$caller} }) 1626 878 2504
44 do {
45 2504 my $caller = caller $level;
46 2504 ▶ defined $caller and $CarpInternal{$caller};
Condition66%2/3
defined $caller && $Error::TypeTiny::CarpInternal{$caller}
!ll&&!rl&&r
08781626
MC/DC50%1/2
defined $caller && $Error::TypeTiny::CarpInternal{$caller}
defined $caller $Error::TypeTiny::CarpInternal{$caller}
Truth table66%2/3
A && B
A= defined $callerB= $Error::TypeTiny::CarpInternal{$caller}
ABresult
0X0
100
111
47 }
48 )
49 {
50 1626 $level++;
51 }
52 878 ▶ if ( ( ( caller( $level - 1 ) )[1] || "" ) =~
Branch: 1 branch
BranchTrueFalseTotal
if (((caller $level - 1)[1] || "") =~ /^(?:parameter validation for|exportable function) '(.+?)'$/) 652 226 878
Condition100%2/2
(caller $level - 1)[1] || ''
l!l
8726
MC/DC100%1/1
(caller $level - 1)[1] || ''
(caller $level - 1)[1]
Truth table100%2/2
A
A= (caller $level - 1)[1]
Aresult
11
00
53 /^(?:parameter validation for|exportable function) '(.+?)'$/ )
54 {
55 652 my ( $pkg, $func ) = ( $1 =~ m{^(.+)::(\w+)$} );
56 652 ▶ $level++ if caller( $level ) eq ( $pkg || "" );
Branch: 1 branch
BranchTrueFalseTotal
if caller $level eq ($pkg || "") 570 82 652
Condition50%1/2
$pkg || ''
l!l
6520
MC/DC0%0/1
$pkg || ''
$pkg
Truth table50%1/2
A
A= $pkg
Aresult
11
00
57 }
58
59 {
60 290 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
61 # Moo's Method::Generate::Constructor puts an eval in the stack trace,
62 # that is useless for debugging, so show the stack frame one above.
63 878 ▶ $level++
Branch: 1 branch
BranchTrueFalseTotal
if (caller $level)[1] =~ /^\(eval \d+\)$/ and (caller $level)[3] eq "(eval)" 0 878 878
Condition33%1/3
(caller $level)[1] =~ /^\(eval \d+\)$/ and (caller $level)[3] eq "(eval)"
!ll&&!rl&&r
87800
MC/DC0%0/2
(caller $level)[1] =~ /^\(eval \d+\)$/ and (caller $level)[3] eq "(eval)"
(caller $level)[1] =~ /^\(eval \d+\)$/ (caller $level)[3] eq "(eval)"
Truth table33%1/3
A and B
A= (caller $level)[1] =~ /^\(eval \d+\)$/B= (caller $level)[3] eq "(eval)"
ABresult
0X0
100
111
64 if (
65 ( caller( $level ) )[1] =~ /^\(eval \d+\)$/
66 and ( caller( $level ) )[3] eq '(eval)' # (caller())[3] is $subroutine
67 );
68 878 @ctxt{qw/ package file line /} = caller( $level );
69 }
70
71 878 my $stack = undef;
72 878 ▶ if ( our $StackTrace ) {
Branch: 1 branch
BranchTrueFalseTotal
if (our $StackTrace) 1 877 878
73 1 require Devel::StackTrace;
74 1 $stack = "Devel::StackTrace"->new(
75 ignore_package => [ keys %CarpInternal ],
76 );
77 }
78
79 878 our $LastError = $class->new(
80 context => \%ctxt,
81 stack_trace => $stack,
82 @_,
83 );
84
85 878 ▶ $callback ? $callback->( $LastError ) : die( $LastError );
Branch: 1 branch
BranchTrueFalseTotal
$callback ? : 4 874 878
86 } #/ sub throw
87  
88 750 ▶sub message { $_[0]{message} ||= $_[0]->_build_message }
Subroutine message: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
$_[0]{"message"} ||= $_[0]->_build_message
l!l&&r!l&&!r
693570
MC/DC0%0/2
$_[0]{"message"} ||= $_[0]->_build_message
$_[0]{"message"} $_[0]->_build_message
Truth table66%2/3
A ||= B
A= $_[0]{"message"}B= $_[0]->_build_message
ABresult
1X1
011
000
89 737 ▶sub context { $_[0]{context} }
Subroutine context: called CC=1 SCAR=0.0
Pod documented
90 3 ▶sub stack_trace { $_[0]{stack_trace} }
Subroutine stack_trace: called CC=1 SCAR=0.0
Pod documented
91  
92 392 ▶sub to_string {
Subroutine to_string: called CC=5 SCAR=17.8
Pod documented
93 392 my $e = shift;
94 392 my $c = $e->context;
95 392 my $m = $e->message;
96  
97 $m =~ /\n\z/s
98 ? $m
99 : $c ? sprintf(
100 "%s at %s line %s.\n", $m, $c->{file} || 'file?',
101 392 ▶ $c->{line} || 'NaN'
Branch: 2 branches
BranchTrueFalseTotal
$m =~ /\n\z/s ? : 0 392 392
$c ? : 392 0 392
Condition50%2/4
$c->{'file'} || 'file?'
l!l
3920
$c->{'line'} || 'NaN'
l!l
3920
MC/DC0%0/1
$c->{'file'} || 'file?'
$c->{'file'}
MC/DC0%0/1
$c->{'line'} || 'NaN'
$c->{'line'}
Truth table50%1/2
A
A= $c->{'file'}
Aresult
11
00
Truth table50%1/2
A
A= $c->{'line'}
Aresult
11
00
102 )
103 : sprintf( "%s\n", $m );
104 } #/ sub to_string
105  
106 1 ▶sub _build_message {
Subroutine _build_message: called CC=1 SCAR=0.0
107 1 return 'An exception has occurred';
108 }
109  
110 141 ▶sub croak {
Subroutine croak: called CC=1 SCAR=0.0
Pod documented
111 141 my ( $fmt, @args ) = @_;
112 141 @_ = (
113 __PACKAGE__,
114 message => sprintf( $fmt, @args ),
115 );
116 141 goto \&throw;
117 }
118  
119 290 1;
120  
121 __END__
« blib/lib/Reply/Plugin/TypeTiny.pm ↑ Summary blib/lib/Error/TypeTiny/WrongNumberOfParameters.pm »