blib/lib/Langertha/Knarr/Image.pm

filter: Statementstmt 98.2% 109 / 111 Branchbran 75.7% 50 / 66 Conditioncond 55.2% 53 / 96 MC/DCmcdc 16.3% 8 / 49 Subroutinesub 100% 20 / 20 Podpod 100% 6 / 6 totaltotal 70.6% 246 / 348 CC 70 SCAR 23.3
CC
70
Cov
78%
_from_anthropic_block
20.2
_ollama_message
18.3
_from_openai_part
13.0
CRAP 10.3
« blib/lib/Langertha/Knarr/Stream.pm ↑ Summary blib/lib/Langertha/Knarr/PSGI/FakeReq.pm »
1 package Langertha::Knarr::Image;
2 # ABSTRACT: Translate a client's image parts into Langertha::Content::Image objects
3 15 our $VERSION = '1.103';
4 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use MIME::Base64 qw( decode_base64 );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 15 my @ALL_FORMATS = qw( openai anthropic gemini ollama responses lmstudio );
11  
12 15 my $translates;
13  
14 79 ▶sub translates {
Subroutine translates: called CC=6 SCAR=19.9
Pod documented
15 79 ▶ return $translates if defined $translates;
Branch: 1 branch
BranchTrueFalseTotal
if defined $translates 75 4 79
16 4 ▶ $translates = eval {
Condition50%1/2
eval { do { require Langertha::Content::Image; my $class = 'Langertha::Content::Image'; $class->can('to_ollama') && $class->can('to_responses') && $class->can('to_lmstudio') ? 1 : 0 } } || 0
l!l
40
MC/DC0%0/1
eval { do { require Langertha::Content::Image; my $class = 'Langertha::Content::Image'; $class->can('to_ollama') && $class->can('to_responses') && $class->can('to_lmstudio') ? 1 : 0 } } || 0
eval { do { require Langertha::Content::Image; my $class = 'Langertha::Content::Image'; $class->can('to_ollama') && $class->can('to_responses') && $class->can('to_lmstudio') ? 1 : 0 } }
Truth table50%1/2
A
A= eval { do { require Langertha::Content::Image; my $class = 'Langertha::Content::Image'; $class->can('to_ollama') && $class->can('to_responses') && $class->can('to_lmstudio') ? 1 : 0 } }
Aresult
11
00
17 4 require Langertha::Content::Image;
18 4 my $class = 'Langertha::Content::Image';
19 4 ▶ ( $class->can('to_ollama') && $class->can('to_responses') && $class->can('to_lmstudio') ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$class->can('to_ollama') && $class->can('to_responses') && $class->can('to_lmstudio') ? : 4 0 4
Condition33%2/6
$class->can("to_ollama") and $class->can("to_responses") and $class->can("to_lmstudio")
!ll&&!rl&&r
004
$class->can("to_ollama") and $class->can("to_responses")
!ll&&!rl&&r
004
MC/DC0%0/3
$class->can("to_ollama") and $class->can("to_responses") and $class->can("to_lmstudio")
$class->can("to_ollama") $class->can("to_responses") $class->can("to_lmstudio")
Truth table25%1/4
A and B and C
A= $class->can("to_ollama")B= $class->can("to_responses")C= $class->can("to_lmstudio")
ABCresult
0XX0
10X0
1100
1111
20 } || 0;
21 4 return $translates;
22 }
23  
24  
25 3 ▶sub content_formats {
Subroutine content_formats: called CC=2 SCAR=7.2
Pod documented
26 3 my (@face_formats) = @_;
27 3 ▶ return translates() ? [@ALL_FORMATS] : [@face_formats];
Branch: 1 branch
BranchTrueFalseTotal
translates() ? : 3 0 3
28 }
29  
30  
31 13 ▶sub openai_messages { _map_messages( $_[0], \&_openai_message ) }
Subroutine openai_messages: called CC=1 SCAR=0.0
Pod documented
32 34 ▶sub anthropic_messages { _map_messages( $_[0], \&_anthropic_message ) }
Subroutine anthropic_messages: called CC=1 SCAR=0.0
Pod documented
33 28 ▶sub ollama_messages { _map_messages( $_[0], \&_ollama_message ) }
Subroutine ollama_messages: called CC=1 SCAR=0.0
Pod documented
34  
35  
36 75 ▶sub _map_messages {
Subroutine _map_messages: called CC=4 SCAR=15.6
37 75 my ( $messages, $code ) = @_;
38 75 ▶ return $messages unless translates() && ref $messages eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless translates() and ref $messages eq "ARRAY" 0 75 75
Condition33%1/3
translates() and ref $messages eq "ARRAY"
!ll&&!rl&&r
0075
MC/DC0%0/2
translates() and ref $messages eq "ARRAY"
translates() ref $messages eq "ARRAY"
Truth table33%1/3
A and B
A= translates()B= ref $messages eq "ARRAY"
ABresult
0X0
100
111
39 75 ▶ return [ map { ref $_ eq 'HASH' ? $code->($_) : $_ } @$messages ];
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 76 0 76
40 }
41  
42 13 ▶sub _openai_message {
Subroutine _openai_message: called CC=4 SCAR=13.9
43 13 my ($msg) = @_;
44 13 ▶ return $msg unless ref $msg->{content} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $msg->{"content"} eq "ARRAY" 4 9 13
45 9 my $found = 0;
46 my @parts = map {
47 18 my $img = _from_openai_part($_);
48 18 ▶ $img ? do { $found = 1; $img } : $_;
Branch: 1 branch
BranchTrueFalseTotal
$img ? : 9 9 18
49 9 } @{ $msg->{content} };
50 9 ▶ return $found ? { %$msg, content => _plain_text(\@parts) } : $msg;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 9 0 9
51 }
52  
53 18 ▶sub _from_openai_part {
Subroutine _from_openai_part: called CC=10 SCAR=25.6
54 18 my ($part) = @_;
55 18 ▶ return undef unless ref $part eq 'HASH' && ( $part->{type} // '' ) eq 'image_url';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $part eq "HASH" and ($part->{"type"} // "") eq "image_url" 9 9 18
Condition60%3/5
ref $part eq "HASH" and ($part->{"type"} // "") eq "image_url"
!ll&&!rl&&r
099
$part->{"type"} // ""
l!l
180
MC/DC0%0/2
ref $part eq "HASH" and ($part->{"type"} // "") eq "image_url"
ref $part eq "HASH" $part->{"type"}
Truth table33%1/3
A and B
A= ref $part eq "HASH"B= $part->{"type"}
ABresult
0X0
100
111
56 9 ▶ my $url = ref $part->{image_url} eq 'HASH' ? $part->{image_url}{url} : $part->{image_url};
Branch: 1 branch
BranchTrueFalseTotal
ref $part->{'image_url'} eq 'HASH' ? : 9 0 9
57 9 ▶ return undef unless defined $url && !ref $url && length $url;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url and not ref $url and length $url 0 9 9
Condition33%2/6
defined $url and not ref $url and length $url
!ll&&!rl&&r
009
defined $url and not ref $url
!ll&&!rl&&r
009
MC/DC0%0/3
defined $url and not ref $url and length $url
defined $url not ref $url length $url
Truth table25%1/4
A and not(B) and C
A= defined $urlB= not ref $urlC= length $url
ABCresult
0XX0
10X0
1100
1111
58 9 ▶ if ( $url =~ /\Adata:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ /\Adata:/) 5 4 9
59 5 ▶ my ( $media_type, $b64 ) = _parse_data_url($url) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
() = _parse_data_url($url) or return undef 5 0 5
60 5 return Langertha::Content::Image->from_base64( $b64, media_type => $media_type );
61 }
62 # Not fetched here: core fetches only for engines that need inline data.
63 4 return Langertha::Content::Image->from_url($url);
64 }
65  
66 35 ▶sub _anthropic_message {
Subroutine _anthropic_message: called CC=4 SCAR=13.9
67 35 my ($msg) = @_;
68 35 ▶ return $msg unless ref $msg->{content} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $msg->{"content"} eq "ARRAY" 26 9 35
69 9 my $found = 0;
70 my @parts = map {
71 18 my $img = _from_anthropic_block($_);
72 18 ▶ $img ? do { $found = 1; $img } : $_;
Branch: 1 branch
BranchTrueFalseTotal
$img ? : 9 9 18
73 9 } @{ $msg->{content} };
74 9 ▶ return $found ? { %$msg, content => _plain_text(\@parts) } : $msg;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 9 0 9
75 }
76  
77 18 ▶sub _from_anthropic_block {
Subroutine _from_anthropic_block: called CC=13 SCAR=30.1
78 18 my ($block) = @_;
79 return undef unless ref $block eq 'HASH' && ( $block->{type} // '' ) eq 'image'
80 18 ▶ && ref $block->{source} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $block eq "HASH" and ($block->{"type"} // "") eq "image" and ref $block->{"source"} eq "HASH" 9 9 18
Condition62%5/8
ref $block eq "HASH" and ($block->{"type"} // "") eq "image" and ref $block->{"source"} eq "HASH"
!ll&&!rl&&r
909
ref $block eq "HASH" and ($block->{"type"} // "") eq "image"
!ll&&!rl&&r
099
$block->{"type"} // ""
l!l
180
MC/DC0%0/3
ref $block eq "HASH" and ($block->{"type"} // "") eq "image" and ref $block->{"source"} eq "HASH"
ref $block eq "HASH" $block->{"type"} ref $block->{"source"} eq "HASH"
Truth table25%1/4
A and B and C
A= ref $block eq "HASH"B= $block->{"type"}C= ref $block->{"source"} eq "HASH"
ABCresult
0XX0
10X0
1100
1111
81 9 my $src = $block->{source};
82 9 ▶ my $type = $src->{type} // '';
Condition50%1/2
$src->{"type"} // ""
l!l
90
MC/DC0%0/1
$src->{"type"} // ""
$src->{"type"}
Truth table50%1/2
A
A= $src->{"type"}
Aresult
11
00
83 9 ▶ if ( $type eq 'base64' && defined $src->{data} && length $src->{data} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "base64" and defined $src->{"data"} and length $src->{"data"}) 6 3 9
Condition66%4/6
$type eq "base64" and defined $src->{"data"} and length $src->{"data"}
!ll&&!rl&&r
306
$type eq "base64" and defined $src->{"data"}
!ll&&!rl&&r
306
MC/DC33%1/3
$type eq "base64" and defined $src->{"data"} and length $src->{"data"}
$type eq "base64" defined $src->{"data"} length $src->{"data"}
Truth table50%2/4
A and B and C
A= $type eq "base64"B= defined $src->{"data"}C= length $src->{"data"}
ABCresult
0XX0
10X0
1100
1111
84 return Langertha::Content::Image->from_base64( $src->{data},
85 6 ▶ media_type => $src->{media_type} // _sniff_base64( $src->{data} ) );
Condition33%1/3
$src->{"media_type"} // _sniff_base64($src->{"data"})
l!l&&r!l&&!r
600
MC/DC0%0/2
$src->{"media_type"} // _sniff_base64($src->{"data"})
$src->{"media_type"} _sniff_base64($src->{"data"})
Truth table33%1/3
A // B
A= $src->{"media_type"}B= _sniff_base64($src->{"data"})
ABresult
1X1
011
000
86 }
87 3 ▶ if ( $type eq 'url' && defined $src->{url} && length $src->{url} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "url" and defined $src->{"url"} and length $src->{"url"}) 3 0 3
Condition33%2/6
$type eq "url" and defined $src->{"url"} and length $src->{"url"}
!ll&&!rl&&r
003
$type eq "url" and defined $src->{"url"}
!ll&&!rl&&r
003
MC/DC0%0/3
$type eq "url" and defined $src->{"url"} and length $src->{"url"}
$type eq "url" defined $src->{"url"} length $src->{"url"}
Truth table25%1/4
A and B and C
A= $type eq "url"B= defined $src->{"url"}C= length $src->{"url"}
ABCresult
0XX0
10X0
1100
1111
88 3 return Langertha::Content::Image->from_url( $src->{url} );
89 }
90 0 return undef;
91 }
92  
93 28 ▶sub _ollama_message {
Subroutine _ollama_message: called CC=15 SCAR=29.1
94 28 my ($msg) = @_;
95 28 ▶ return $msg unless ref $msg->{images} eq 'ARRAY' && @{ $msg->{images} };
Branch: 1 branch
BranchTrueFalseTotal
unless ref $msg->{"images"} eq "ARRAY" and @{$msg->{"images"};} 14 14 28
Condition66%2/3
ref $msg->{"images"} eq "ARRAY" and @{$msg->{"images"};}
!ll&&!rl&&r
14014
MC/DC50%1/2
ref $msg->{"images"} eq "ARRAY" and @{$msg->{"images"};}
ref $msg->{"images"} eq "ARRAY" @{$msg->{"images"};}
Truth table66%2/3
A and B
A= ref $msg->{"images"} eq "ARRAY"B= @{$msg->{"images"};}
ABresult
0X0
100
111
96 14 my @images;
97 14 for my $raw ( @{ $msg->{images} } ) {
98 14 ▶ return $msg unless defined $raw && !ref $raw && length $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw and not ref $raw and length $raw 0 14 14
Condition33%2/6
defined $raw and not ref $raw and length $raw
!ll&&!rl&&r
0014
defined $raw and not ref $raw
!ll&&!rl&&r
0014
MC/DC0%0/3
defined $raw and not ref $raw and length $raw
defined $raw not ref $raw length $raw
Truth table25%1/4
A and not(B) and C
A= defined $rawB= not ref $rawC= length $raw
ABCresult
0XX0
10X0
1100
1111
99 14 ▶ my ( $media_type, $b64 ) = $raw =~ /\Adata:/ ? _parse_data_url($raw) : ();
Branch: 1 branch
BranchTrueFalseTotal
$raw =~ /\Adata:/ ? : 1 13 14
100 14 ▶ return $msg if $raw =~ /\Adata:/ && !defined $b64;
Branch: 1 branch
BranchTrueFalseTotal
if $raw =~ /\Adata:/ and not defined $b64 0 14 14
Condition66%2/3
$raw =~ /\Adata:/ and not defined $b64
!ll&&!rl&&r
1310
MC/DC0%0/2
$raw =~ /\Adata:/ and not defined $b64
$raw =~ /\Adata:/ not defined $b64
Truth table66%2/3
A and not(B)
A= $raw =~ /\Adata:/B= not defined $b64
ABresult
0X0
100
111
101 14 ▶ $b64 //= $raw;
Condition66%2/3
$b64 //= $raw
l!l&&r!l&&!r
1130
MC/DC0%0/2
$b64 //= $raw
$b64 $raw
Truth table66%2/3
A //= B
A= $b64B= $raw
ABresult
1X1
011
000
102 14 ▶ push @images, Langertha::Content::Image->from_base64( $b64,
Condition66%2/3
$media_type // _sniff_base64($b64)
l!l&&r!l&&!r
1130
MC/DC0%0/2
$media_type // _sniff_base64($b64)
$media_type _sniff_base64($b64)
Truth table66%2/3
A // B
A= $media_typeB= _sniff_base64($b64)
ABresult
1X1
011
000
103 media_type => $media_type // _sniff_base64($b64) );
104 }
105 14 my $content = $msg->{content};
106 14 ▶ my @parts = ref $content eq 'ARRAY' ? @$content
Branch: 2 branches
BranchTrueFalseTotal
ref $content eq 'ARRAY' ? : 0 14 14
defined $content && length $content ? : 10 4 14
Condition66%2/3
defined $content and length $content
!ll&&!rl&&r
0410
MC/DC50%1/2
defined $content and length $content
defined $content length $content
Truth table66%2/3
A and B
A= defined $contentB= length $content
ABresult
0X0
100
111
107 : defined $content && length $content ? ($content)
108 : ();
109 14 my %out = %$msg;
110 14 delete $out{images};
111 14 return { %out, content => _plain_text( [ @parts, @images ] ) };
112 }
113  
114 # A bare { type => 'text', text => ... } part as a plain string: the one
115 # text form core renders in every content format.
116 32 ▶sub _plain_text {
Subroutine _plain_text: called CC=7 SCAR=20.1
117 32 my ($parts) = @_;
118 return [ map {
119 32 ( ref $_ eq 'HASH' && keys %$_ == 2 && ( $_->{type} // '' ) eq 'text'
120 60 ▶ && defined $_->{text} && !ref $_->{text} ) ? $_->{text} : $_
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' && keys %$_ == 2 && ($_->{'type'} // '') eq 'text' && defined $_->{'text'} && !ref($_->{'text'}) ? : 17 43 60
Condition71%10/14
ref $_ eq "HASH" and keys %$_ == 2 and ($_->{"type"} // "") eq "text" and defined $_->{"text"} and not ref $_->{"text"}
!ll&&!rl&&r
43017
ref $_ eq "HASH" and keys %$_ == 2 and ($_->{"type"} // "") eq "text" and defined $_->{"text"}
!ll&&!rl&&r
43017
ref $_ eq "HASH" and keys %$_ == 2 and ($_->{"type"} // "") eq "text"
!ll&&!rl&&r
43017
ref $_ eq "HASH" and keys %$_ == 2
!ll&&!rl&&r
42117
$_->{"type"} // ""
l!l
170
MC/DC40%2/5
ref $_ eq "HASH" and keys %$_ == 2 and ($_->{"type"} // "") eq "text" and defined $_->{"text"} and not ref $_->{"text"}
ref $_ eq "HASH" keys %$_ == 2 $_->{"type"} defined $_->{"text"} not ref $_->{"text"}
Truth table50%3/6
A and B and C and D and not(E)
A= ref $_ eq "HASH"B= keys %$_ == 2C= $_->{"type"}D= defined $_->{"text"}E= not ref $_->{"text"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
121 } @$parts ];
122 }
123  
124 # data:<media type>[;param...];base64,<payload>
125 6 ▶sub _parse_data_url {
Subroutine _parse_data_url: called CC=2 SCAR=7.1
126 6 my ($url) = @_;
127 6 ▶ return unless $url =~ m{\Adata:([^;,]+)((?:;[^;,]*)*);base64,(.+)\z}s;
Branch: 1 branch
BranchTrueFalseTotal
unless $url =~ /\Adata:([^;,]+)((?:;[^;,]*)*);base64,(.+)\z/s 0 6 6
128 6 return ( $1, $3 );
129 }
130  
131 15 my @MAGIC = (
132 [ qr/\A\x89PNG/, 'image/png' ],
133 [ qr/\A\xFF\xD8\xFF/, 'image/jpeg' ],
134 [ qr/\AGIF8/, 'image/gif' ],
135 [ qr/\ARIFF.{4}WEBP/s, 'image/webp' ],
136 [ qr/\ABM/, 'image/bmp' ],
137 );
138  
139 # Media type from the payload's magic bytes; Ollama sends none. PNG when
140 # nothing matches.
141 13 ▶sub _sniff_base64 {
Subroutine _sniff_base64: called CC=3 SCAR=11.0
142 13 my ($b64) = @_;
143 13 my $head = decode_base64( substr( $b64, 0, 16 ) );
144 13 for my $m (@MAGIC) {
145 31 ▶ return $m->[1] if $head =~ $m->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $head =~ /$m->[0]/ 12 19 31
146 }
147 1 return 'image/png';
148 }
149  
150 27 ▶sub plain_messages {
Subroutine plain_messages: called CC=7 SCAR=20.0
Pod documented
151 27 my ($messages) = @_;
152 return $messages unless ref $messages eq 'ARRAY'
153 27 ▶ && grep { ref $_ eq 'HASH' && ref $_->{content} eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $messages eq "ARRAY" and grep {ref $_ eq "HASH" and ref $_->{"content"} eq "ARRAY" and grep {builtin::blessed($_);} @{$$_{"content"};};} @$messages 25 2 27
Condition100%3/3
ref $messages eq "ARRAY" and grep {ref $_ eq "HASH" and ref $_->{"content"} eq "ARRAY" and grep {builtin::blessed($_);} @{$$_{"content"};};} @$messages
!ll&&!rl&&r
9162
MC/DC100%2/2
ref $messages eq "ARRAY" and grep {ref $_ eq "HASH" and ref $_->{"content"} eq "ARRAY" and grep {builtin::blessed($_);} @{$$_{"content"};};} @$messages
ref $messages eq "ARRAY" grep {ref $_ eq "HASH" and ref $_->{"content"} eq "ARRAY" and grep {builtin::blessed($_);} @{$$_{"content"};};} @$messages
Truth table100%3/3
A and B
A= ref $messages eq "ARRAY"B= grep {ref $_ eq "HASH" and ref $_->{"content"} eq "ARRAY" and grep {builtin::blessed($_);} @{$$_{"content"};};} @$messages
ABresult
0X0
100
111
154 17 ▶ && grep { blessed $_ } @{ $_->{content} } } @$messages;
Condition66%4/6
ref $_ eq 'HASH' && ref $_->{'content'} eq 'ARRAY' && grep({builtin::blessed($_);} @{$$_{'content'};})
!ll&&!rl&&r
1502
ref $_ eq "HASH" and ref $_->{"content"} eq "ARRAY"
!ll&&!rl&&r
0152
MC/DC33%1/3
ref $_ eq 'HASH' && ref $_->{'content'} eq 'ARRAY' && grep({builtin::blessed($_);} @{$$_{'content'};})
ref $_ eq "HASH" ref $_->{"content"} eq "ARRAY" grep({builtin::blessed($_);} @{$$_{'content'};})
Truth table50%2/4
A and B && C
A= ref $_ eq "HASH"B= ref $_->{"content"} eq "ARRAY"C= grep({builtin::blessed($_);} @{$$_{'content'};})
ABCresult
0XX0
10X0
1100
1111
155 return [ map {
156 2 ( ref $_ eq 'HASH' && ref $_->{content} eq 'ARRAY' )
157 2 ▶ ? { %$_, content => [ map { _plain_part($_) } @{ $_->{content} } ] }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' && ref $_->{'content'} eq 'ARRAY' ? : 2 0 2
Condition33%1/3
ref $_ eq "HASH" and ref $_->{"content"} eq "ARRAY"
!ll&&!rl&&r
002
MC/DC0%0/2
ref $_ eq "HASH" and ref $_->{"content"} eq "ARRAY"
ref $_ eq "HASH" ref $_->{"content"} eq "ARRAY"
Truth table33%1/3
A and B
A= ref $_ eq "HASH"B= ref $_->{"content"} eq "ARRAY"
ABresult
0X0
100
111
158 : $_
159 } @$messages ];
160 }
161  
162  
163 6 ▶sub _plain_part {
Subroutine _plain_part: called CC=5 SCAR=16.6
164 6 my ($part) = @_;
165 6 ▶ return $part unless blessed $part;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($part) 2 4 6
166 4 ▶ if ( $part->isa('Langertha::Content::Image') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part->isa("Langertha::Content::Image")) 4 0 4
167 4 ▶ my $url = $part->has_base64
Branch: 1 branch
BranchTrueFalseTotal
$part->has_base64 ? : 2 2 4
Condition50%1/2
$part->media_type // "application/octet-stream"
l!l
20
MC/DC0%0/1
$part->media_type // "application/octet-stream"
$part->media_type
Truth table50%1/2
A
A= $part->media_type
Aresult
11
00
168 ? sprintf( 'data:%s;base64,%s', $part->media_type // 'application/octet-stream', $part->base64 )
169 : $part->url;
170 4 return { type => 'image_url', image_url => { url => $url } };
171 }
172 0 return "$part";
173 }
174  
175  
176 15 1;
177  
178 __END__
« blib/lib/Langertha/Knarr/Stream.pm ↑ Summary blib/lib/Langertha/Knarr/PSGI/FakeReq.pm »