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.01";
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 71 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod documented
33 71 my($class, %opt) = @_;
34 71 ▶ if ($class eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) 38 33 71
35 38 ▶ my $method = delete $opt{method} // 'auto';
Condition100%2/2
delete $opt{"method"} // "auto"
l!l
362
MC/DC100%1/1
delete $opt{"method"} // "auto"
delete $opt{"method"}
Truth table100%2/2
A
A= delete $opt{"method"}
Aresult
11
00
36 38 ▶ if ($method eq 'auto') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "auto") 3 35 38
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 35 return $class->method_class($method)->new(%opt);
44 }
45 33 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 %opt,
52 }, $class;
53 33 $obj->terminal; # a wrong size dies here
54 32 $obj;
55 }
56  
57 # The class of a method, loaded
58 38 ▶sub method_class {
Subroutine method_class: called CC=3 SCAR=11.0
Pod undocumented
59 38 my($class, $name) = @_;
60 38 ▶ $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}'") 37 1 38
61 37 my $c = __PACKAGE__ . "::$name";
62 37 ▶ 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") 35 2 37
63 35 $c;
64 }
65  
66 # The name of the method of an object
67 1 ▶sub method {
Subroutine method: called CC=2 SCAR=8.1
Pod documented
68 1 my $self = shift;
69 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
70 }
71  
72 # Whether the terminal supports the method: the method module says
73 0 ▶sub supported { 0 }
Subroutine supported: not called CC=1 SCAR=6.9
Pod documented
74  
75 # The most columns and rows that an image may take, 0 for no limit
76 0 ▶sub max_cells { 0 }
Subroutine max_cells: not called CC=1 SCAR=6.9
Pod documented
77  
78 # Columns, rows and the size of a cell in pixels of the terminal: from
79 # term, "COLSxROWS" or "COLSxROWS:WxH", or from the window size of the
80 # tty. The size of a cell is 0 when it is not known. An empty list
81 # when there is no terminal. As a class method, term is the argument.
82 111 ▶sub terminal {
Subroutine terminal: called CC=17 SCAR=40.9
Pod documented
83 111 my $self = shift;
84 111 ▶ $self = { term => shift } unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 24 87 111
85 111 ▶ $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
54570
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
86 57 my $spec = $self->{term};
87 57 my @r;
88 57 ▶ if (defined $spec and $spec ne '') {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $spec and $spec ne '') { } 53 4 57
elsif (open my $tty, '+<', '/dev/tty') { } 0 4 4
Condition66%2/3
defined $spec and $spec ne ""
!ll&&!rl&&r
4053
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
89 53 ▶ @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}'") 52 1 53
90 or croak "Text::ANSI::Image: COLSxROWS:WxH expected for term, not '$spec'";
91 52 ▶ $_ //= 0 for @r;
Condition100%2/2
$_ //= 0
l!l
2044
MC/DC100%1/1
$_ //= 0
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
92 } elsif (open my $tty, '+<', '/dev/tty') {
93 0 ▶ my $TIOCGWINSZ = $^O eq 'darwin' ? 0x40087468 : 0x5413;
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'darwin' ? : 0 0 0
94 0 my $buf = "\0" x 8;
95 0 ▶ if (ioctl $tty, $TIOCGWINSZ, $buf) {
Branch: 1 branch
BranchTrueFalseTotal
if (ioctl $tty, $TIOCGWINSZ, $buf) 0 0 0
96 0 my($rows, $cols, $x, $y) = unpack 'S4', $buf;
97 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
98 $cols && $x ? $x / $cols : 0,
99 $rows && $y ? $y / $rows : 0) if $rows && $cols;
100 }
101 }
102 56 \@r;
103 };
104 110 @{$self->{_terminal}};
105 }
106  
107 # Width, height and type (png, jpeg or gif) of an image file, read
108 # from its header. Only what the header says is believed, not the
109 # name of the file. An empty list when it is none of them.
110 34 ▶sub info {
Subroutine info: called CC=15 SCAR=28.2
Pod documented
111 34 my($class, $file) = @_;
112 34 ▶ open my $fh, '<:raw', $file or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $file or return 33 1 34
113 33 ▶ read $fh, my $head, 32 or return;
Branch: 1 branch
BranchTrueFalseTotal
read $fh, my $head, 32 or return 33 0 33
114 33 ▶ 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) 27 6 33
115 27 return (unpack('N', $1), unpack('N', $2), 'png');
116 }
117 6 ▶ if ($head =~ /\AGIF8[79]a(..)(..)/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head =~ /\AGIF8[79]a(..)(..)/su) 2 4 6
118 2 return (unpack('v', $1), unpack('v', $2), 'gif');
119 }
120 4 ▶ if ($head =~ /\A\xff\xd8/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head =~ /\A\xff\xd8/u) 1 3 4
121 1 seek $fh, 2, 0;
122 1 ▶ while (read($fh, my $m, 4) == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (read($fh, my $m, 4) == 4) 2 0 2
123 2 my($ff, $type, $len) = unpack 'CCn', $m;
124 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
125 # a start of frame: SOF0-SOF15 but DHT, JPG and DAC
126 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
127 and $type != 0xc4 and $type != 0xc8 and $type != 0xcc) {
128 1 ▶ read $fh, my $sof, 5 or last;
Branch: 1 branch
BranchTrueFalseTotal
read $fh, my $sof, 5 or last 1 0 1
129 1 my(undef, $h, $w) = unpack 'Cnn', $sof;
130 1 return ($w, $h, 'jpeg');
131 }
132 1 seek $fh, $len - 2, 1;
133 }
134 }
135 3 return;
136 }
137  
138 # The size of an image of WxH pixels in cells: as large as its pixels,
139 # and not larger than the room, which is width and rows (or those of
140 # the object), the terminal width and its height but $MARGIN lines,
141 # and max_cells of the method. An empty list when there is no room.
142 29 ▶sub cells {
Subroutine cells: called CC=18 SCAR=30.1
Pod documented
143 29 my($self, $w, $h, %opt) = @_;
144 29 ▶ $w > 0 && $h > 0 or return;
Branch: 1 branch
BranchTrueFalseTotal
$w > 0 and $h > 0 or return 29 0 29
Condition33%1/3
$w > 0 and $h > 0
!ll&&!rl&&r
0029
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
145 29 ▶ my($tcols, $trows, $cw, $ch) = $self->terminal or return;
Branch: 1 branch
BranchTrueFalseTotal
() = $self->terminal or return 29 0 29
146 29 ▶ ($cw, $ch) = @CELL unless $cw && $ch;
Branch: 1 branch
BranchTrueFalseTotal
unless $cw and $ch 1 28 29
Condition66%2/3
$cw and $ch
!ll&&!rl&&r
1028
MC/DC50%1/2
$cw and $ch
$cw $ch
Truth table66%2/3
A and B
A= $cwB= $ch
ABresult
0X0
100
111
147 29 ▶ my $max_cols = $opt{width} || $self->{width} || $tcols;
Condition83%5/6
$opt{'width'} || $self->{'width'} || $tcols
l!l&&r!l&&!r
8210
$opt{"width"} or $self->{"width"}
l!l&&r!l&&!r
1721
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
148 29 ▶ 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
4250
$opt{"rows"} or $self->{"rows"}
l!l&&r!l&&!r
2225
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
149 29 ▶ if (my $max = $self->max_cells) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $max = $self->max_cells) 29 0 29
150 29 ▶ $max_cols = $max if $max_cols > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $max_cols > $max 1 28 29
151 29 ▶ $max_rows = $max if $max_rows > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $max_rows > $max 1 28 29
152 }
153 29 ▶ return if $max_cols < 1 or $max_rows < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $max_cols < 1 or $max_rows < 1 0 29 29
Condition33%1/3
$max_cols < 1 or $max_rows < 1
l!l&&r!l&&!r
0029
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
154 29 my $cols = ceil($w / $cw);
155 29 ▶ $cols = $max_cols if $cols > $max_cols;
Branch: 1 branch
BranchTrueFalseTotal
if $cols > $max_cols 10 19 29
156 29 my $rows = ceil($cols * $cw * $h / $w / $ch);
157 29 ▶ if ($rows > $max_rows) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rows > $max_rows) 5 24 29
158 5 $rows = $max_rows;
159 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
160 }
161 29 ($cols, $rows);
162 }
163  
164 # The rows of an image: lines of text without newlines, or an empty
165 # list when it is not shown, because the file is not an image, its
166 # type is not in types (of the call or of the object), or there is no
167 # room. The method draws them with render.
168 32 ▶sub rows {
Subroutine rows: called CC=8 SCAR=20.8
Pod documented
169 32 my($self, $file, %opt) = @_;
170 32 ▶ -f $file && -r _ or return;
Branch: 1 branch
BranchTrueFalseTotal
-f $file and -r _ or return 28 4 32
Condition66%2/3
-f $file and -r _
!ll&&!rl&&r
4028
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
171 28 ▶ my($w, $h, $type) = $self->info($file) or return;
Branch: 1 branch
BranchTrueFalseTotal
() = $self->info($file) or return 26 2 28
172 26 ▶ if (my $types = $opt{types} // $self->{types}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $types = $opt{"types"} // $self->{"types"}) 5 21 26
Condition100%3/3
$opt{"types"} // $self->{"types"}
l!l&&r!l&&!r
2321
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
173 5 ▶ grep { $_ eq $type } @$types or return;
Branch: 1 branch
BranchTrueFalseTotal
grep {$_ eq $type;} @$types or return 2 3 5
174 }
175 23 ▶ my($cols, $rows) = $self->cells($w, $h, %opt) or return;
Branch: 1 branch
BranchTrueFalseTotal
() = $self->cells($w, $h, %opt) or return 23 0 23
176 23 $self->render($file, $w, $h, $type, $cols, $rows);
177 }
178  
179 # render(FILE, W, H, TYPE, COLS, ROWS): the rows of the image in COLS x
180 # ROWS cells. The method module has it.
181 0 ▶sub render { croak ref(shift) . ": no render" }
Subroutine render: not called CC=1 SCAR=6.9
Pod documented
182  
183 # Send what the rows need to the terminal. Nothing by default.
184 0 ▶sub flush { }
Subroutine flush: not called CC=1 SCAR=0.0
Pod documented
185  
186 # A PNG of the image, not wider than MAX pixels: the file itself when
187 # it is such a PNG, or one made by sips (macOS) or ImageMagick. A
188 # larger PNG is the file itself when neither is there. undef when it
189 # cannot be made. The path is given to the command as an argument of
190 # its own, never through a shell, and with a directory in front, so
191 # that it cannot be taken as an option or as a "coder:" of
192 # ImageMagick. The file made is kept until temp_done.
193 25 ▶sub png {
Subroutine png: called CC=13 SCAR=40.9
Pod undocumented
194 25 my($self, $file, $w, $type, $max) = @_;
195 25 ▶ return $file if $type eq 'png' and $w <= $max;
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "png" and $w <= $max 22 3 25
Condition100%3/3
$type eq "png" and $w <= $max
!ll&&!rl&&r
2122
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
196 3 my $in = File::Spec->rel2abs($file);
197 3 my $tmp = File::Temp->new(SUFFIX => '.png');
198 3 my @cmd;
199 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
200 0 ▶ @cmd = ($SIPS, '-s', 'format', 'png',
Branch: 1 branch
BranchTrueFalseTotal
$w > $max ? : 0 0 0
201 ($w > $max ? ('--resampleWidth', int $max) : ()),
202 $in, '--out', "$tmp");
203 } elsif (my $magick = which('magick')) {
204 0 ▶ @cmd = ($magick, $in, ($w > $max ? ('-resize', int($max) . 'x') : ()), "png:$tmp");
Branch: 1 branch
BranchTrueFalseTotal
$w > $max ? : 0 0 0
205 } else {
206 3 ▶ return $type eq 'png' ? $file : undef;
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'png' ? : 1 2 3
207 }
208 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
209 0 ▶ if ($pid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 0) 0 0 0
210 0 open STDOUT, '>', File::Spec->devnull;
211 0 open STDERR, '>', File::Spec->devnull;
212 0 ▶ exec { $cmd[0] } @cmd or POSIX::_exit(127);
Branch: 1 branch
BranchTrueFalseTotal
exec {$cmd[0];} @cmd or POSIX::_exit(127) 0 0 0
213 }
214 0 waitpid $pid, 0;
215 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
216 0 push @{$self->{_temp}}, $tmp;
217 0 "$tmp";
218 }
219  
220 # Forget the files made by png
221 18 ▶sub temp_done { delete shift->{_temp} }
Subroutine temp_done: called CC=1 SCAR=0.0
Pod undocumented
222  
223 3 ▶sub which {
Subroutine which: called CC=4 SCAR=14.9
Pod undocumented
224 3 my $name = shift;
225 3 for my $dir (File::Spec->path) {
226 3 my $path = "$dir/$name";
227 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
228 }
229 3 undef;
230 }
231  
232 25 1;
233  
234 __END__
↑ Summary blib/lib/App/ansipic.pm »