| 1 | package Claude::Agent::Message; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use 5.020; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Claude::Agent::Types; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Claude::Agent::Message::Base; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Claude::Agent::Message::User; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use Claude::Agent::Message::Assistant; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use Claude::Agent::Message::System; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use Claude::Agent::Message::HookEvent; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use Claude::Agent::Message::Result; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use Claude::Agent::Message::StreamEvent; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use Claude::Agent::Message::RateLimitEvent; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use Claude::Agent::Message::ToolProgress; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | 11 | my %CLASS_FOR = ( | |||||||||||||||||||||||||||||||||||||
| 19 | user => 'Claude::Agent::Message::User', | ||||||||||||||||||||||||||||||||||||||
| 20 | assistant => 'Claude::Agent::Message::Assistant', | ||||||||||||||||||||||||||||||||||||||
| 21 | system => 'Claude::Agent::Message::System', | ||||||||||||||||||||||||||||||||||||||
| 22 | result => 'Claude::Agent::Message::Result', | ||||||||||||||||||||||||||||||||||||||
| 23 | stream_event => 'Claude::Agent::Message::StreamEvent', | ||||||||||||||||||||||||||||||||||||||
| 24 | rate_limit_event => 'Claude::Agent::Message::RateLimitEvent', | ||||||||||||||||||||||||||||||||||||||
| 25 | tool_progress => 'Claude::Agent::Message::ToolProgress', | ||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | 11 | my %HOOK_SUBTYPE = map { $_ => 1 } qw(hook_started hook_progress hook_response); | |||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | 398 | ▶ | sub _camel_to_snake { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_camel_to_snake: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||
| 31 | 398 | my ($str) = @_; | |||||||||||||||||||||||||||||||||||||
| 32 | 398 | ▶ | return $str unless defined $str; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 33 | 398 | $str =~ s/([A-Z]+)([A-Z][a-z])/${1}_$2/g; | |||||||||||||||||||||||||||||||||||||
| 34 | 398 | $str =~ s/([a-z\d])([A-Z])/${1}_$2/g; | |||||||||||||||||||||||||||||||||||||
| 35 | 398 | return lc($str); | |||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||
| 38 | 83 | ▶ | sub _normalize_data { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_data: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 39 | 83 | my ($data) = @_; | |||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | 83 | my %normalized; | |||||||||||||||||||||||||||||||||||||
| 42 | 83 | for my $key (keys %$data) { | |||||||||||||||||||||||||||||||||||||
| 43 | 398 | $normalized{ _camel_to_snake($key) } = $data->{$key}; | |||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||
| 46 | 83 | return \%normalized; | |||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | 83 | ▶ | sub from_json { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
from_json: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 50 | 83 | my ($class, $data) = @_; | |||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||
| 52 | 83 | my $normalized = _normalize_data($data); | |||||||||||||||||||||||||||||||||||||
| 53 | 83 | ▶ | my $type = $normalized->{type} // ''; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$normalized->{"type"} // ""
MC/DC0%0/1
$normalized->{"type"} // ""
$normalized->{"type"}
Truth table50%1/2
A
A= $normalized->{"type"}
| |||||||||||||||||||||||||||||||||||||||
| 54 | 83 | ▶ | my $target = $CLASS_FOR{$type} // 'Claude::Agent::Message::Base'; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$CLASS_FOR{$type} // "Claude::Agent::Message::Base"
MC/DC100%1/1
$CLASS_FOR{$type} // "Claude::Agent::Message::Base"
$CLASS_FOR{$type}
Truth table100%2/2
A
A= $CLASS_FOR{$type}
| |||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||
| 56 | 83 | ▶ | if ($type eq 'system' && $HOOK_SUBTYPE{ $normalized->{subtype} // '' }) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$type eq "system" and $HOOK_SUBTYPE{$normalized->{"subtype"} // ""}
$normalized->{"subtype"} // ""
MC/DC100%2/2
$type eq "system" and $HOOK_SUBTYPE{$normalized->{"subtype"} // ""}
$type eq "system"
$HOOK_SUBTYPE{$normalized->{"subtype"} // ""}
MC/DC0%0/1
$normalized->{"subtype"} // ""
$normalized->{"subtype"}
Truth table100%3/3
A and B
A= $type eq "system"B= $HOOK_SUBTYPE{$normalized->{"subtype"} // ""}
Truth table50%1/2
A
A= $normalized->{"subtype"}
| |||||||||||||||||||||||||||||||||||||||
| 57 | 2 | $target = 'Claude::Agent::Message::HookEvent'; | |||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||
| 60 | 83 | return $target->new( | |||||||||||||||||||||||||||||||||||||
| 61 | Claude::Agent::Types::known_args($target, $normalized), | ||||||||||||||||||||||||||||||||||||||
| 62 | raw => $data, | ||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||
| 66 | 11 | 1; | |||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||||||||||||||||||||