Agent/Hook/Matcher.pm

filter: Statementstmt 94.5% 35 / 37 Branchbran 77.2% 17 / 22 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 78.0% 64 / 82 CC 15 SCAR 25.4
CC
15
Cov
82%
matches
17.3
__ANON__
1.1
BEGIN
1.0
CRAP 12.7
« Agent/Query.pm ↑ Summary Agent/CLI.pm »
1 package Claude::Agent::Hook::Matcher;
2  
3 9 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use Object::Proto ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 Object::Proto::define('Claude::Agent::Hook::Matcher',
11 'matcher:predicate',
12 'hooks:ArrayRef:default([])',
13 'timeout:Num:predicate',
14 );
15 }
16  
17 13 ▶sub matches {
Subroutine matches: called CC=15 SCAR=28.5
Pod documented
18 13 my ($self, $tool_name) = @_;
19  
20 13 ▶ return 0 unless defined $tool_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tool_name 1 12 13
21 12 ▶ return 1 unless defined $self->matcher;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->matcher 1 11 12
22  
23 11 my $pattern = $self->matcher;
24  
25 11 ▶ if ($pattern !~ /[\\^\$.|?*+()\[\]{}]/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pattern =~ /[\\^\$.|?*+()\[\]{}]/u) 6 5 11
26 6 return $tool_name eq $pattern;
27 }
28  
29 5 ▶ my $use_alarm = $^O ne 'MSWin32' && $^O ne 'cygwin';
Condition33%1/3
$^O ne 'MSWin32' && $^O ne 'cygwin'
!ll&&!rl&&r
005
MC/DC0%0/2
$^O ne 'MSWin32' && $^O ne 'cygwin'
$^O ne 'MSWin32' $^O ne 'cygwin'
Truth table33%1/3
A && B
A= $^O ne 'MSWin32'B= $^O ne 'cygwin'
ABresult
0X0
100
111
30 5 my $result = 0;
31 5 my $ok = eval {
32 5 ▶ die "Pattern too long\n" if length($pattern) > 1000;
Branch: 1 branch
BranchTrueFalseTotal
if length $pattern > 1000 0 5 5
33 5 ▶ if ($pattern =~ /\([^)]*[+*][^)]*\)[+*]/ || $pattern =~ /\([^)]*\|[^)]*\)[+*]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern =~ /\([^)]*[+*][^)]*\)[+*]/u or $pattern =~ /\([^)]*\|[^)]*\)[+*]/u) 1 4 5
Condition66%2/3
$pattern =~ /\([^)]*[+*][^)]*\)[+*]/u or $pattern =~ /\([^)]*\|[^)]*\)[+*]/u
l!l&&r!l&&!r
104
MC/DC50%1/2
$pattern =~ /\([^)]*[+*][^)]*\)[+*]/u or $pattern =~ /\([^)]*\|[^)]*\)[+*]/u
$pattern =~ /\([^)]*[+*][^)]*\)[+*]/u $pattern =~ /\([^)]*\|[^)]*\)[+*]/u
Truth table66%2/3
A or B
A= $pattern =~ /\([^)]*[+*][^)]*\)[+*]/uB= $pattern =~ /\([^)]*\|[^)]*\)[+*]/u
ABresult
1X1
011
000
34 1 die "Potentially dangerous nested quantifier pattern\n";
35 }
36 0 ▶ local $SIG{ALRM} = sub { die "Regex timeout\n" } if $use_alarm;
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
if $use_alarm 4 0 4
37 4 ▶ alarm(1) if $use_alarm;
Branch: 1 branch
BranchTrueFalseTotal
if $use_alarm 4 0 4
38 4 require Time::HiRes;
39 4 my $start_time = Time::HiRes::time();
40 4 my $compiled = qr/$pattern/;
41 4 ▶ $result = $tool_name =~ $compiled ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$tool_name =~ /$compiled/u ? : 3 1 4
42 4 ▶ if (!$use_alarm && (Time::HiRes::time() - $start_time) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $use_alarm and &Time::HiRes::time() - $start_time > 1) 0 4 4
Condition33%1/3
not $use_alarm and &Time::HiRes::time() - $start_time > 1
!ll&&!rl&&r
400
MC/DC0%0/2
not $use_alarm and &Time::HiRes::time() - $start_time > 1
not $use_alarm &Time::HiRes::time() - $start_time > 1
Truth table33%1/3
not(A) and B
A= not $use_alarmB= &Time::HiRes::time() - $start_time > 1
ABresult
0X0
100
111
43 0 die "Regex timeout\n";
44 }
45 4 1;
46 };
47 5 ▶ alarm(0) if $use_alarm;
Branch: 1 branch
BranchTrueFalseTotal
if $use_alarm 5 0 5
48 5 ▶ return $ok ? $result : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 4 1 5
49 }
50  
51 9 1;
52  
53 __END__
« Agent/Query.pm ↑ Summary Agent/CLI.pm »