Agent/Message/Assistant.pm

filter: Statementstmt 97.9% 48 / 49 Branchbran 80.0% 8 / 10 Conditioncond 69.4% 25 / 36 MC/DCmcdc 26.6% 4 / 15 Subroutinesub 100% 14 / 14 Podpod 100% 6 / 6 totaltotal 80.7% 105 / 130 CC 19 SCAR 19.0
CC
19
Cov
85%
text
13.5
tool_uses
6.3
content_blocks
4.0
CRAP 6.7
« Agent/MCP/SDKBridge.pm ↑ Summary Agent/MCP/HeaderUtils.pm »
1 package Claude::Agent::Message::Assistant;
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 Object::Proto ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Claude::Agent::Content;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use Claude::Agent::Message::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 11 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 Object::Proto::define('Claude::Agent::Message::Assistant',
14 extends => 'Claude::Agent::Message::Base',
15 'message:HashRef:required',
16 'model:predicate',
17 'error:predicate',
18 '_content_blocks_cache',
19 );
20 }
21  
22 14 ▶sub content_blocks {
Subroutine content_blocks: called CC=4 SCAR=13.9
Pod documented
23 14 my ($self) = @_;
24  
25 14 ▶ return [@{$self->_content_blocks_cache}] if $self->_content_blocks_cache;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_content_blocks_cache 7 7 14
26  
27 7 my $raw = $self->message->{content};
28 7 ▶ $raw = [] unless ref($raw) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $raw eq "ARRAY" 3 4 7
29  
30 my @blocks = map {
31 7 ▶ ref($_) eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 7 0 7
32 ? Claude::Agent::Content->from_json($_)
33 : $_
34 } @$raw;
35  
36 7 $self->_content_blocks_cache(\@blocks);
37 7 return [@blocks];
38 }
39  
40 4 ▶sub text {
Subroutine text: called CC=11 SCAR=26.0
Pod documented
41 4 my ($self) = @_;
42 4 my @texts;
43 4 for my $block (@{$self->content_blocks}) {
44 6 ▶ if (blessed($block) && $block->can('type') && $block->type eq 'text' && $block->can('text')) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($block) and $block->can('type') and $block->type eq 'text' and $block->can('text')) { } 3 3 6
elsif (defined $block and ref $block eq 'HASH' and defined $block->{'type'} and $block->{'type'} eq 'text' and defined $block->{'text'}) { } 0 6 6
Condition77%7/9
builtin::blessed($block) and $block->can("type") and $block->type eq "text" and $block->can("text")
!ll&&!rl&&r
303
builtin::blessed($block) and $block->can("type") and $block->type eq "text"
!ll&&!rl&&r
123
builtin::blessed($block) and $block->can("type")
!ll&&!rl&&r
105
MC/DC50%2/4
builtin::blessed($block) and $block->can("type") and $block->type eq "text" and $block->can("text")
builtin::blessed($block) $block->can("type") $block->type eq "text" $block->can("text")
Truth table60%3/5
A and B and C and D
A= builtin::blessed($block)B= $block->can("type")C= $block->type eq "text"D= $block->can("text")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
45 3 push @texts, $block->text;
46 }
47 ▶ elsif (defined $block && ref($block) eq 'HASH' && defined $block->{type} && $block->{type} eq 'text' && defined $block->{text}) {
Condition58%7/12
defined $block and ref $block eq "HASH" and defined $block->{"type"} and $block->{"type"} eq "text" and defined $block->{"text"}
!ll&&!rl&&r
300
defined $block and ref $block eq "HASH" and defined $block->{"type"} and $block->{"type"} eq "text"
!ll&&!rl&&r
210
defined $block and ref $block eq "HASH" and defined $block->{"type"}
!ll&&!rl&&r
201
defined $block and ref $block eq "HASH"
!ll&&!rl&&r
021
MC/DC0%0/5
defined $block and ref $block eq "HASH" and defined $block->{"type"} and $block->{"type"} eq "text" and defined $block->{"text"}
defined $block ref $block eq "HASH" defined $block->{"type"} $block->{"type"} eq "text" defined $block->{"text"}
Truth table33%2/6
A and B and C and D and E
A= defined $blockB= ref $block eq "HASH"C= defined $block->{"type"}D= $block->{"type"} eq "text"E= defined $block->{"text"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
48 0 push @texts, $block->{text};
49 }
50 }
51 4 return join("\n", @texts);
52 }
53  
54 3 ▶sub tool_uses {
Subroutine tool_uses: called CC=6 SCAR=18.5
Pod documented
55 3 my ($self) = @_;
56 return [
57 grep {
58 (blessed($_) && $_->can('type') && $_->type eq 'tool_use')
59 5 ▶ || (ref($_) eq 'HASH' && defined $_->{type} && $_->{type} eq 'tool_use')
Condition73%11/15
builtin::blessed($_) && $_->can('type') && $_->type eq 'tool_use' || ref $_ eq 'HASH' && defined $_->{'type'} && $_->{'type'} eq 'tool_use'
l!l&&r!l&&!r
203
builtin::blessed($_) and $_->can("type") and $_->type eq "tool_use"
!ll&&!rl&&r
122
builtin::blessed($_) and $_->can("type")
!ll&&!rl&&r
104
ref $_ eq "HASH" and defined $_->{"type"} and $_->{"type"} eq "tool_use"
!ll&&!rl&&r
210
ref $_ eq "HASH" and defined $_->{"type"}
!ll&&!rl&&r
201
MC/DC33%2/6
builtin::blessed($_) && $_->can('type') && $_->type eq 'tool_use' || ref $_ eq 'HASH' && defined $_->{'type'} && $_->{'type'} eq 'tool_use'
builtin::blessed($_) $_->can("type") $_->type eq "tool_use" ref $_ eq "HASH" defined $_->{"type"} $_->{"type"} eq "tool_use"
Truth table23%3/13
A and B and C || D and E and F
A= builtin::blessed($_)B= $_->can("type")C= $_->type eq "tool_use"D= ref $_ eq "HASH"E= defined $_->{"type"}F= $_->{"type"} eq "tool_use"
ABCDEFresult
111XXX1
0XX1111
10X1111
1101111
0XX0XX0
0XX10X0
0XX1100
10X0XX0
10X10X0
10X1100
1100XX0
11010X0
1101100
60 3 } @{$self->content_blocks}
61 ];
62 }
63  
64 1 ▶sub usage {
Subroutine usage: called CC=1 SCAR=0.0
Pod documented
65 1 my ($self) = @_;
66 1 return $self->message->{usage};
67 }
68  
69 1 ▶sub stop_reason {
Subroutine stop_reason: called CC=1 SCAR=0.0
Pod documented
70 1 my ($self) = @_;
71 1 return $self->message->{stop_reason};
72 }
73  
74 1 ▶sub message_id {
Subroutine message_id: called CC=1 SCAR=0.0
Pod documented
75 1 my ($self) = @_;
76 1 return $self->message->{id};
77 }
78  
79 11 1;
80  
81 __END__
« Agent/MCP/SDKBridge.pm ↑ Summary Agent/MCP/HeaderUtils.pm »