blib/lib/Text/ANSI/Image.pm

filter: Statementstmt 83.9% 110 / 131 Branchbran 64.8% 61 / 94 Conditioncond 55.8% 43 / 77 MC/DCmcdc 24.4% 11 / 45 Subroutinesub 80.0% 16 / 20 Podpod 71.4% 10 / 14 totaltotal 65.8% 251 / 381 CC 78 SCAR 32.7
CC
78
Cov
71%
terminal
59.9
png
59.9
cells
20.2
CRAP 26.4
↑ Summary blib/lib/App/ansipic.pm »
1 package Text::ANSI::Image;
2  
3 25 our $VERSION = "0.02";
4  
5 25 ▶use v5.16;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 25 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 25 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 25 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 25 ▶use POSIX qw(ceil floor);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # The methods which auto tries, in order: the first which the terminal
13 # supports is taken.
14 25 our @METHODS = qw(kitty);
15  
16 # The types of images which are known
17 25 our @TYPES = qw(png jpeg gif);
18  
19 # The size of a cell in pixels when the terminal does not tell it
20 25 our @CELL = (8, 17);
21  
22 # Lines of the terminal which an image leaves free
23 25 our $MARGIN = 4;
24  
25 # The commands which make an image PNG, or smaller
26 25 our $SIPS = '/usr/bin/sips';
27  
28 # new(method => NAME, ...): an object of the method NAME, which is the
29 # module Text::ANSI::Image::NAME. With "auto" (the default), of the
30 # first method in @METHODS which the terminal supports, or undef when
31 # it supports none. A method module calls it as its own new.
32 77 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod documented
33 77 my($class, %opt) = @_;
34 77 ▶ if ($class eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) 41 36 77
35 41 ▶ my $method = delete $opt{method} // 'auto';
Condition100%2/2
delete $opt{"method"} // "auto"
l!l
392
MC/DC100%1/1
delete $opt{"method"} // "auto"
delete $opt{"method"}
Truth table100%2/2
A
A= delete $opt{"method"}
Aresult
11
00
36 41 ▶ if ($method eq 'auto') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "auto") 3 38 41
37 3 for my $m (@METHODS) {
38 3 my $c = $class->method_class($m);
39 3 ▶ return $c->new(%opt) if $c->supported;
Branch: 1 branch
BranchTrueFalseTotal
if $c->supported 1 2 3
40 }
41 2 return undef;
42 }
43 38 return $class->method_class($method)->new(%opt);
44 }
45 36 my $obj = bless {
46 term => undef, # COLSxROWS:WxH, or from the tty
47 tty => '/dev/tty', # where the data goes
48 width => 0, # columns that an image may take
49 rows => 0, # rows that an image may take
50 types => undef, # types of images shown, all by default
51 osc => 0, # tell the file of each image (kitty)
52 %opt,
53 }, $class;
54 36 $obj->terminal; # a wrong size dies here
55 35 $obj;
56 }
57  
58 # The class of a method, loaded
59 41 ▶sub method_class {
Subroutine method_class: called CC=3 SCAR=11.0
Pod undocumented
60 41 my($class, $name) = @_;
61 41 ▶ $name =~ /\A\w+\z/ or croak "Text::ANSI::Image: not a name of a method: '$name'";
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /\A\w+\z/u or croak("Text::ANSI::Image: not a name of a method: '${name}'") 40 1 41
62 40 my $c = __PACKAGE__ . "::$name";
63 40 ▶ eval "require $c; 1" or croak "Text::ANSI::Image: unknown method: $name";
Branch: 1 branch
BranchTrueFalseTotal
eval "require $c; 1" or croak("Text::ANSI::Image: unknown method: $name") 38 2 40
64 38 $c;
65 }
66  
67 # The name of the method of an object
68 1 ▶sub method {
Subroutine method: called CC=2 SCAR=8.1
Pod documented
69 1 my $self = shift;
70 1 ▶ (ref $self || $self) =~ s/.*:://r;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
100
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
71 }
72  
73 # Whether the terminal supports the method: the method module says
74 0 ▶sub supported { 0 }
Subroutine supported: not called CC=1 SCAR=6.9
Pod documented
75  
76 # The most columns and rows that an image may take, 0 for no limit
77 0 ▶sub max_cells { 0 }
Subroutine max_cells: not called CC=1 SCAR=6.9
Pod documented
78  
79 # Columns, rows and the size of a cell in pixels of the terminal: from
80 # term, "COLSxROWS" or "COLSxROWS:WxH", or from the window size of the
81 # tty. The size of a cell is 0 when it is not known. An empty list
82 # when there is no terminal. As a class method, term is the argument.
83 120 ▶sub terminal {
Subroutine terminal: called CC=17 SCAR=40.9
Pod documented
84 120 my $self = shift;
85 120 ▶ $self = { term => shift } unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 24 96 120
86 120 ▶ $self->{_terminal} //= do {
Condition66%2/3
$self->{"_terminal"} //= do { my $spec = $self->{"term"}; my @r; if (defined $spec and $spec ne "") { @r = $spec =~ /\A(\d+)x(\d+)(?::(\d+)x(\d+))?\z/u or croak("Text::ANSI::Image: COLSxROWS:WxH expected for term, not '${spec}'"); $_ //= 0 foreach (@r); } elsif (open my $tty, "+<", "/dev/tty") { my $TIOCGWINSZ = $^O eq "darwin" ? 1074295912 : 21523; my $buf = "\0\0\0\0\0\0\0\0"; if (ioctl $tty, $TIOCGWINSZ, $buf) { () = unpack("S4", $buf); @r = ($cols, $rows, $cols && $x ? $x / $cols : 0, $rows && $y ? $y / $rows : 0) if $rows and $cols; } ; } ; \@r }
l!l&&r!l&&!r
60600
MC/DC0%0/2
$self->{"_terminal"} //= do { my $spec = $self->{"term"}; my @r; if (defined $spec and $spec ne "") { @r = $spec =~ /\A(\d+)x(\d+)(?::(\d+)x(\d+))?\z/u or croak("Text::ANSI::Image: COLSxROWS:WxH expected for term, not '${spec}'"); $_ //= 0 foreach (@r); } elsif (open my $tty, "+<", "/dev/tty") { my $TIOCGWINSZ = $^O eq "darwin" ? 1074295912 : 21523; my $buf = "\0\0\0\0\0\0\0\0"; if (ioctl $tty, $TIOCGWINSZ, $buf) { () = unpack("S4", $buf); @r = ($cols, $rows, $cols && $x ? $x / $cols : 0, $rows && $y ? $y / $rows : 0) if $rows and $cols; } ; } ; \@r }
$self->{"_terminal"} do { my $spec = $self->{"term"}; my @r; if (defined $spec and $spec ne "") { @r = $spec =~ /\A(\d+)x(\d+)(?::(\d+)x(\d+))?\z/u or croak("Text::ANSI::Image: COLSxROWS:WxH expected for term, not '${spec}'"); $_ //= 0 foreach (@r); } elsif (open my $tty, "+<", "/dev/tty") { my $TIOCGWINSZ = $^O eq "darwin" ? 1074295912 : 21523; my $buf = "\0\0\0\0\0\0\0\0"; if (ioctl $tty, $TIOCGWINSZ, $buf) { () = unpack("S4", $buf); @r = ($cols, $rows, $cols && $x ? $x / $cols : 0, $rows && $y ? $y / $rows : 0) if $rows and $cols; } ; } ; \@r }
Truth table66%2/3
A //= B
A= $self->{"_terminal"}B= do { my $spec = $self->{"term"}; my @r; if (defined $spec and $spec ne "") { @r = $spec =~ /\A(\d+)x(\d+)(?::(\d+)x(\d+))?\z/u or croak("Text::ANSI::Image: COLSxROWS:WxH expected for term, not '${spec}'"); $_ //= 0 foreach (@r); } elsif (open my $tty, "+<", "/dev/tty") { my $TIOCGWINSZ = $^O eq "darwin" ? 1074295912 : 21523; my $buf = "\0\0\0\0\0\0\0\0"; if (ioctl $tty, $TIOCGWINSZ, $buf) { () = unpack("S4", $buf); @r = ($cols, $rows, $cols && $x ? $x / $cols : 0, $rows && $y ? $y / $rows : 0) if $rows and $cols; } ; } ; \@r }
ABresult
1X1
011
000
87 60 my $spec = $self->{term};
88 60 my @r;
89 60 ▶ if (defined $spec and $spec ne '') {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $spec and $spec ne '') { } 56 4 60
elsif (open my $tty, '+<', '/dev/tty') { } 0 4 4
Condition66%2/3
defined $spec and $spec ne ""
!ll&&!rl&&r
4056
MC/DC50%1/2
defined $spec and $spec ne ""
defined $spec $spec ne ""
Truth table66%2/3
A and B
A= defined $specB= $spec ne ""
ABresult
0X0
100
111
90 56 ▶ @r = $spec =~ /\A(\d+)x(\d+)(?::(\d+)x(\d+))?\z/
Branch: 1 branch
BranchTrueFalseTotal
@r = $spec =~ /\A(\d+)x(\d+)(?::(\d+)x(\d+))?\z/u or croak("Text::ANSI::Image: COLSxROWS:WxH expected for term, not '${spec}'") 55 1 56
91 or croak "Text::ANSI::Image: COLSxROWS:WxH expected for term, not '$spec'";
92 55 ▶ $_ //= 0 for @r;
Condition100%2/2
$_ //= 0
l!l
2164
MC/DC100%1/1
$_ //= 0
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
93 } elsif (open my $tty, '+<', '/dev/tty') {
94 0 ▶ my $TIOCGWINSZ = $^O eq 'darwin' ? 0x40087468 : 0x5413;
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'darwin' ? : 0 0 0
95 0 my $buf = "\0" x 8;
96 0 ▶ if (ioctl $tty, $TIOCGWINSZ, $buf) {
Branch: 1 branch
BranchTrueFalseTotal
if (ioctl $tty, $TIOCGWINSZ, $buf) 0 0 0
97 0 my($rows, $cols, $x, $y) = unpack 'S4', $buf;
98 0 ▶ @r = ($cols, $rows,
Branch: 3 branches
BranchTrueFalseTotal
if $rows and $cols 0 0 0
$cols && $x ? : 0 0 0
$rows && $y ? : 0 0 0
Condition0%0/9
$rows and $cols
!ll&&!rl&&r
000
$cols and $x
!ll&&!rl&&r
000
$rows and $y
!ll&&!rl&&r
000
MC/DC0%0/2
$rows and $cols
$rows $cols
MC/DC0%0/2
$cols and $x
$cols $x
MC/DC0%0/2
$rows and $y
$rows $y
Truth table0%0/3
A and B
A= $rowsB= $cols
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $colsB= $x
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $rowsB= $y
ABresult
0X0
100
111
99 $cols && $x ? $x / $cols : 0,
100 $rows && $y ? $y / $rows : 0) if $rows && $cols;
101 }
102 }
103 59 \@r;
104 };
105 119 @{$self->{_terminal}};
106 }
107  
108 # Width, height and type (png, jpeg or gif) of an image file, read
109 # from its header. Only what the header says is believed, not the
110 # name of the file. An empty list when it is none of them.
111 37 ▶sub info {
Subroutine info: called CC=15 SCAR=28.2
Pod documented
112 37 my($class, $file) = @_;
113 37 ▶ open my $fh, '<:raw', $file or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $file or return 36 1 37
114 36 ▶ read $fh, my $head, 32 or return;
Branch: 1 branch
BranchTrueFalseTotal
read $fh, my $head, 32 or return 36 0 36
115 36 ▶ if ($head =~ /\A\x89PNG\r\n\x1a\n....IHDR(.{4})(.{4})/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head =~ /\A\x89PNG\r\n\x1a\n....IHDR(.{4})(.{4})/su) 30 6 36
116 30 return (unpack('N', $1), unpack('N', $2), 'png');
117 }
118 6 ▶ if ($head =~ /\AGIF8[79]a(..)(..)/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head =~ /\AGIF8[79]a(..)(..)/su) 2 4 6
119 2 return (unpack('v', $1), unpack('v', $2), 'gif');
120 }
121 4 ▶ if ($head =~ /\A\xff\xd8/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head =~ /\A\xff\xd8/u) 1 3 4
122 1 seek $fh, 2, 0;
123 1 ▶ while (read($fh, my $m, 4) == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (read($fh, my $m, 4) == 4) 2 0 2
124 2 my($ff, $type, $len) = unpack 'CCn', $m;
125 2 ▶ last if $ff != 0xff or $len < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $ff != 255 or $len < 2 0 2 2
Condition33%1/3
$ff != 255 or $len < 2
l!l&&r!l&&!r
002
MC/DC0%0/2
$ff != 255 or $len < 2
$ff != 255 $len < 2
Truth table33%1/3
A or B
A= $ff != 255B= $len < 2
ABresult
1X1
011
000
126 # a start of frame: SOF0-SOF15 but DHT, JPG and DAC
127 2 ▶ if ($type >= 0xc0 and $type <= 0xcf
Branch: 1 branch
BranchTrueFalseTotal
if ($type >= 192 and $type <= 207 and $type != 196 and $type != 200 and $type != 204) 1 1 2
Condition66%8/12
$type >= 192 and $type <= 207 and $type != 196 and $type != 200 and $type != 204
!ll&&!rl&&r
101
$type >= 192 and $type <= 207 and $type != 196 and $type != 200
!ll&&!rl&&r
101
$type >= 192 and $type <= 207 and $type != 196
!ll&&!rl&&r
101
$type >= 192 and $type <= 207
!ll&&!rl&&r
011
MC/DC20%1/5
$type >= 192 and $type <= 207 and $type != 196 and $type != 200 and $type != 204
$type >= 192 $type <= 207 $type != 196 $type != 200 $type != 204
Truth table33%2/6
A and B and C and D and E
A= $type >= 192B= $type <= 207C= $type != 196D= $type != 200E= $type != 204
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
128 and $type != 0xc4 and $type != 0xc8 and $type != 0xcc) {
129 1 ▶ read $fh, my $sof, 5 or last;
Branch: 1 branch
BranchTrueFalseTotal
read $fh, my $sof, 5 or last 1 0 1
130 1 my(undef, $h, $w) = unpack 'Cnn', $sof;
131 1 return ($w, $h, 'jpeg');
132 }
133 1 seek $fh, $len - 2, 1;
134 }
135 }
136 3 return;
137 }
138  
139 # The size of an image of WxH pixels in cells: as large as its pixels,
140 # and not larger than the room, which is width and rows (or those of
141 # the object), the terminal width and its height but $MARGIN lines,
142 # and max_cells of the method. An empty list when there is no room.
143 32 ▶sub cells {
Subroutine cells: called CC=18 SCAR=30.1
Pod documented
144 32 my($self, $w, $h, %opt) = @_;
145 32 ▶ $w > 0 && $h > 0 or return;
Branch: 1 branch
BranchTrueFalseTotal
$w > 0 and $h > 0 or return 32 0 32
Condition33%1/3
$w > 0 and $h > 0
!ll&&!rl&&r
0032
MC/DC0%0/2
$w > 0 and $h > 0
$w > 0 $h > 0
Truth table33%1/3
A and B
A= $w > 0B= $h > 0
ABresult
0X0
100
111
146 32 ▶ my($tcols, $trows, $cw, $ch) = $self->terminal or return;
Branch: 1 branch
BranchTrueFalseTotal
() = $self->terminal or return 32 0 32
147 32 ▶ ($cw, $ch) = @CELL unless $cw && $ch;
Branch: 1 branch
BranchTrueFalseTotal
unless $cw and $ch 1 31 32
Condition66%2/3
$cw and $ch
!ll&&!rl&&r
1031
MC/DC50%1/2
$cw and $ch
$cw $ch
Truth table66%2/3
A and B
A= $cwB= $ch
ABresult
0X0
100
111
148 32 ▶ my $max_cols = $opt{width} || $self->{width} || $tcols;
Condition83%5/6
$opt{'width'} || $self->{'width'} || $tcols
l!l&&r!l&&!r
8240
$opt{"width"} or $self->{"width"}
l!l&&r!l&&!r
1724
MC/DC0%0/3
$opt{'width'} || $self->{'width'} || $tcols
$opt{"width"} $self->{"width"} $tcols
Truth table75%3/4
A or B || C
A= $opt{"width"}B= $self->{"width"}C= $tcols
ABCresult
1XX1
01X1
0011
0000
149 32 ▶ my $max_rows = $opt{rows} || $self->{rows} || $trows - $MARGIN;
Condition83%5/6
$opt{'rows'} || $self->{'rows'} || $trows - $Text::ANSI::Image::MARGIN
l!l&&r!l&&!r
4280
$opt{"rows"} or $self->{"rows"}
l!l&&r!l&&!r
2228
MC/DC0%0/3
$opt{'rows'} || $self->{'rows'} || $trows - $Text::ANSI::Image::MARGIN
$opt{"rows"} $self->{"rows"} $trows - $Text::ANSI::Image::MARGIN
Truth table75%3/4
A or B || C
A= $opt{"rows"}B= $self->{"rows"}C= $trows - $Text::ANSI::Image::MARGIN
ABCresult
1XX1
01X1
0011
0000
150 32 ▶ if (my $max = $self->max_cells) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $max = $self->max_cells) 32 0 32
151 32 ▶ $max_cols = $max if $max_cols > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $max_cols > $max 1 31 32
152 32 ▶ $max_rows = $max if $max_rows > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $max_rows > $max 1 31 32
153 }
154 32 ▶ return if $max_cols < 1 or $max_rows < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $max_cols < 1 or $max_rows < 1 0 32 32
Condition33%1/3
$max_cols < 1 or $max_rows < 1
l!l&&r!l&&!r
0032
MC/DC0%0/2
$max_cols < 1 or $max_rows < 1
$max_cols < 1 $max_rows < 1
Truth table33%1/3
A or B
A= $max_cols < 1B= $max_rows < 1
ABresult
1X1
011
000
155 32 my $cols = ceil($w / $cw);
156 32 ▶ $cols = $max_cols if $cols > $max_cols;
Branch: 1 branch
BranchTrueFalseTotal
if $cols > $max_cols 10 22 32
157 32 my $rows = ceil($cols * $cw * $h / $w / $ch);
158 32 ▶ if ($rows > $max_rows) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rows > $max_rows) 5 27 32
159 5 $rows = $max_rows;
160 5 ▶ $cols = floor($rows * $ch * $w / $h / $cw) || 1;
Condition100%2/2
floor($rows * $ch * $w / $h / $cw) || 1
l!l
23
MC/DC100%1/1
floor($rows * $ch * $w / $h / $cw) || 1
floor($rows * $ch * $w / $h / $cw)
Truth table100%2/2
A
A= floor($rows * $ch * $w / $h / $cw)
Aresult
11
00
161 }
162 32 ($cols, $rows);
163 }
164  
165 # The rows of an image: lines of text without newlines, or an empty
166 # list when it is not shown, because the file is not an image, its
167 # type is not in types (of the call or of the object), or there is no
168 # room. The method draws them with render.
169 35 ▶sub rows {
Subroutine rows: called CC=8 SCAR=20.8
Pod documented
170 35 my($self, $file, %opt) = @_;
171 35 ▶ -f $file && -r _ or return;
Branch: 1 branch
BranchTrueFalseTotal
-f $file and -r _ or return 31 4 35
Condition66%2/3
-f $file and -r _
!ll&&!rl&&r
4031
MC/DC50%1/2
-f $file and -r _
-f $file -r _
Truth table66%2/3
A and B
A= -f $fileB= -r _
ABresult
0X0
100
111
172 31 ▶ my($w, $h, $type) = $self->info($file) or return;
Branch: 1 branch
BranchTrueFalseTotal
() = $self->info($file) or return 29 2 31
173 29 ▶ if (my $types = $opt{types} // $self->{types}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $types = $opt{"types"} // $self->{"types"}) 5 24 29
Condition100%3/3
$opt{"types"} // $self->{"types"}
l!l&&r!l&&!r
2324
MC/DC100%2/2
$opt{"types"} // $self->{"types"}
$opt{"types"} $self->{"types"}
Truth table100%3/3
A // B
A= $opt{"types"}B= $self->{"types"}
ABresult
1X1
011
000
174 5 ▶ grep { $_ eq $type } @$types or return;
Branch: 1 branch
BranchTrueFalseTotal
grep {$_ eq $type;} @$types or return 2 3 5
175 }
176 26 ▶ my($cols, $rows) = $self->cells($w, $h, %opt) or return;
Branch: 1 branch
BranchTrueFalseTotal
() = $self->cells($w, $h, %opt) or return 26 0 26
177 26 $self->render($file, $w, $h, $type, $cols, $rows);
178 }
179  
180 # render(FILE, W, H, TYPE, COLS, ROWS): the rows of the image in COLS x
181 # ROWS cells. The method module has it.
182 0 ▶sub render { croak ref(shift) . ": no render" }
Subroutine render: not called CC=1 SCAR=6.9
Pod documented
183  
184 # Send what the rows need to the terminal. Nothing by default.
185 0 ▶sub flush { }
Subroutine flush: not called CC=1 SCAR=0.0
Pod documented
186  
187 # A PNG of the image, not wider than MAX pixels: the file itself when
188 # it is such a PNG, or one made by sips (macOS) or ImageMagick. A
189 # larger PNG is the file itself when neither is there. undef when it
190 # cannot be made. The path is given to the command as an argument of
191 # its own, never through a shell, and with a directory in front, so
192 # that it cannot be taken as an option or as a "coder:" of
193 # ImageMagick. The file made is kept until temp_done.
194 28 ▶sub png {
Subroutine png: called CC=13 SCAR=40.9
Pod undocumented
195 28 my($self, $file, $w, $type, $max) = @_;
196 28 ▶ return $file if $type eq 'png' and $w <= $max;
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "png" and $w <= $max 25 3 28
Condition100%3/3
$type eq "png" and $w <= $max
!ll&&!rl&&r
2125
MC/DC100%2/2
$type eq "png" and $w <= $max
$type eq "png" $w <= $max
Truth table100%3/3
A and B
A= $type eq "png"B= $w <= $max
ABresult
0X0
100
111
197 3 my $in = File::Spec->rel2abs($file);
198 3 my $tmp = File::Temp->new(SUFFIX => '.png');
199 3 my @cmd;
200 3 ▶ if (-x $SIPS) {
Branch: 2 branches
BranchTrueFalseTotal
if (-x $Text::ANSI::Image::SIPS) { } 0 3 3
elsif (my $magick = which('magick')) { } 0 3 3
201 0 ▶ @cmd = ($SIPS, '-s', 'format', 'png',
Branch: 1 branch
BranchTrueFalseTotal
$w > $max ? : 0 0 0
202 ($w > $max ? ('--resampleWidth', int $max) : ()),
203 $in, '--out', "$tmp");
204 } elsif (my $magick = which('magick')) {
205 0 ▶ @cmd = ($magick, $in, ($w > $max ? ('-resize', int($max) . 'x') : ()), "png:$tmp");
Branch: 1 branch
BranchTrueFalseTotal
$w > $max ? : 0 0 0
206 } else {
207 3 ▶ return $type eq 'png' ? $file : undef;
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'png' ? : 1 2 3
208 }
209 0 ▶ my $pid = fork // return undef;
Condition0%0/2
fork // (return undef)
l!l
00
MC/DC0%0/1
fork // (return undef)
fork
Truth table0%0/2
A
A= fork
Aresult
11
00
210 0 ▶ if ($pid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 0) 0 0 0
211 0 open STDOUT, '>', File::Spec->devnull;
212 0 open STDERR, '>', File::Spec->devnull;
213 0 ▶ exec { $cmd[0] } @cmd or POSIX::_exit(127);
Branch: 1 branch
BranchTrueFalseTotal
exec {$cmd[0];} @cmd or POSIX::_exit(127) 0 0 0
214 }
215 0 waitpid $pid, 0;
216 0 ▶ $? == 0 and -s "$tmp" or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$? == 0 and -s "$tmp" or return undef 0 0 0
Condition0%0/3
$? == 0 and -s "$tmp"
!ll&&!rl&&r
000
MC/DC0%0/2
$? == 0 and -s "$tmp"
$? == 0 -s "$tmp"
Truth table0%0/3
A and B
A= $? == 0B= -s "$tmp"
ABresult
0X0
100
111
217 0 push @{$self->{_temp}}, $tmp;
218 0 "$tmp";
219 }
220  
221 # Forget the files made by png
222 18 ▶sub temp_done { delete shift->{_temp} }
Subroutine temp_done: called CC=1 SCAR=0.0
Pod undocumented
223  
224 3 ▶sub which {
Subroutine which: called CC=4 SCAR=14.9
Pod undocumented
225 3 my $name = shift;
226 3 for my $dir (File::Spec->path) {
227 3 my $path = "$dir/$name";
228 3 ▶ return $path if -f $path && -x _;
Branch: 1 branch
BranchTrueFalseTotal
if -f $path and -x _ 0 3 3
Condition33%1/3
-f $path and -x _
!ll&&!rl&&r
300
MC/DC0%0/2
-f $path and -x _
-f $path -x _
Truth table33%1/3
A and B
A= -f $pathB= -x _
ABresult
0X0
100
111
229 }
230 3 undef;
231 }
232  
233 25 1;
234  
235 __END__
↑ Summary blib/lib/App/ansipic.pm »