Gears/X.pm

filter: Statementstmt 96.3% 52 / 54 Branchbran 87.5% 14 / 16 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 93.3% 14 / 15 Podpod 100% 5 / 5 totaltotal 94.9% 94 / 99 CC 15 SCAR 14.4
CC
15
Cov
95%
_build_trace
8.0
as_string
6.0
raise
3.0
CRAP 4.2
« Gears/Router/Pattern/SigilMatch.pm ↑ Summary Gears.pm »
1 package Gears::X;
2 8 $Gears::X::VERSION = '0.105';
3 8 ▶use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 use overload
7 11 ▶ q{""} => sub ($self, @) { $self->as_string },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
8 14 ▶ q{0+} => sub ($self, @) { $self->as_number },
Subroutine __ANON__: called CC=1 SCAR=0.0
9 8 fallback => 1;
10  
11 8 our $PRINT_TRACE = $ENV{GEARS_PRINT_TRACE};
12  
13 8 has param 'message' => (
14 isa => Str,
15 writer => -hidden,
16 );
17  
18 8 has field 'trace' => (
19 isa => ArrayRef,
20 builder => 1,
21 );
22  
23 8 my @ignored = qw(Gears Type::Coercion);
24 8 my $packages_to_skip;
25 8 _rebuild_skip();
26  
27 sub _rebuild_skip
28 8 ▶{
Subroutine _rebuild_skip: called CC=1 SCAR=0.0
29 8 my $sub_re = join '|', map { quotemeta } @ignored;
30 8 $packages_to_skip = qr/^($sub_re)::/;
31 }
32  
33 0 ▶sub add_ignored_namespace($self, $module)
Subroutine add_ignored_namespace: not called CC=1 SCAR=6.9
Pod documented
34 {
35 0 push @ignored, $module;
36 0 _rebuild_skip;
37 }
38  
39 14 ▶sub _base_class ($self)
Subroutine _base_class: called CC=1 SCAR=0.0
40 {
41 14 return __PACKAGE__;
42 }
43  
44 15 ▶sub _trace_config ($self)
Subroutine _trace_config: called CC=1 SCAR=0.0
45 {
46 15 return state $conf = {
47 max_level => 20,
48 skip_package => \$packages_to_skip,
49 skip_file => qr/\(eval \d+\)/,
50 };
51 }
52  
53 15 ▶sub _build_trace ($self)
Subroutine _build_trace: called CC=8 SCAR=20.8
54 {
55 15 my @trace;
56 15 my $trace_conf = $self->_trace_config;
57  
58 15 for my $call_level (0 .. $trace_conf->{max_level}) {
59 171 my ($package, $file, $line) = CORE::caller $call_level;
60 171 ▶ last unless defined $package;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $package 15 156 171
61 156 ▶ next if $package =~ $trace_conf->{skip_package}->$*;
Branch: 1 branch
BranchTrueFalseTotal
if $package =~ /${$trace_conf->{"skip_package"}}/u 46 110 156
62 110 ▶ next if $file =~ $trace_conf->{skip_file};
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /$trace_conf->{"skip_file"}/u 0 110 110
63 110 ▶ next if @trace > 0 && $trace[-1][0] eq $file && $trace[-1][1] == $line;
Branch: 1 branch
BranchTrueFalseTotal
if @trace > 0 and $trace[-1][0] eq $file and $trace[-1][1] == $line 26 84 110
Condition100%6/6
@trace > 0 and $trace[-1][0] eq $file and $trace[-1][1] == $line
!ll&&!rl&&r
82226
@trace > 0 and $trace[-1][0] eq $file
!ll&&!rl&&r
156728
MC/DC100%3/3
@trace > 0 and $trace[-1][0] eq $file and $trace[-1][1] == $line
@trace > 0 $trace[-1][0] eq $file $trace[-1][1] == $line
Truth table100%4/4
A and B and C
A= @trace > 0B= $trace[-1][0] eq $fileC= $trace[-1][1] == $line
ABCresult
0XX0
10X0
1100
1111
64  
65 84 push @trace, [$file, $line];
66 }
67  
68 15 return \@trace;
69 }
70  
71 12 ▶sub caller ($self)
Subroutine caller: called CC=1 SCAR=0.0
Pod documented
72 {
73 12 return $self->trace->[0];
74 }
75  
76 11 ▶sub raise ($self, $error = undef)
Subroutine raise: called CC=3 SCAR=11.0
Pod documented
77 11 {
78 11 ▶ if (defined $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) 10 1 11
79 10 $self = $self->new(message => $error);
80 }
81  
82 11 die $self;
83 }
84  
85 13 ▶sub _build_message ($self)
Subroutine _build_message: called CC=1 SCAR=0.0
86 {
87 13 return $self->message;
88 }
89  
90 14 ▶sub as_string ($self, $trace = $PRINT_TRACE)
Subroutine as_string: called CC=6 SCAR=17.9
Pod documented
91 {
92 14 my $raised = $self->_build_message;
93  
94 14 ▶ if ($trace) {
Branch: 2 branches
BranchTrueFalseTotal
if ($trace) { } 2 12 14
elsif (defined(my $caller = $self->caller)) { } 12 0 12
95 2 $raised .= "\nStack trace:\n";
96 2 foreach my $trace ($self->trace->@*) {
97 12 $raised .= " $trace->[0], line $trace->[1]\n";
98 }
99 }
100 elsif (defined(my $caller = $self->caller)) {
101 12 $raised .= " (raised at $caller->[0], line $caller->[1])";
102 }
103  
104 14 my $class = ref $self;
105 14 my $base = $self->_base_class;
106 14 ▶ if ($class eq $base) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq $base) { } 8 6 14
107 8 $class = '';
108 }
109 else {
110 6 $class =~ s/^${base}::(.+)$/[$1] /;
111 }
112  
113 14 return "An error occurred: $class$raised";
114 }
115  
116 14 ▶sub as_number ($self)
Subroutine as_number: called CC=1 SCAR=0.0
Pod documented
117 {
118 14 return refaddr $self;
119 }
120  
121 __END__
« Gears/Router/Pattern/SigilMatch.pm ↑ Summary Gears.pm »