blib/lib/ICC/Profile/data.pm

filter: Statementstmt 23.7% 14 / 59 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 33.3% 4 / 12 Podpod 16.6% 1 / 6 totaltotal 17.2% 19 / 110 CC 16 SCAR 25.2
CC
16
Cov
16%
sdump
30.0
new
12.0
data
12.0
CRAP 12.4
« blib/lib/ICC/Support/geo2.pm ↑ Summary blib/lib/ICC/Profile/XYZ_.pm »
1 package ICC::Profile::data;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = 0.12;
7  
8 # revised 2018-08-07
9 #
10 # Copyright © 2004-2018 by William B. Birkett
11  
12 # add development directory
13 2 ▶use lib 'lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # inherit from Shared
16 2 ▶use parent qw(ICC::Shared);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # create new data tag object
19 # parameters: ([data_flag, data_string])
20 # returns: (ref_to_object)
21 sub new {
22  
23 # get object class
24 0 ▶ my $class = shift();
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
25
26 # create empty data object
27 0 my $self = [
28 {}, # object header
29 1, # data flag
30 '' # data string
31 ];
32  
33 # if parameter supplied
34 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
35
36 # save data flag
37 0 ▶ $self->[1] = (shift() == 0) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
shift() == 0 ? : 0 0 0
38
39 # save data string
40 0 $self->[2] = shift();
41
42 }
43  
44 # bless object
45 0 bless($self, $class);
46
47 # return object reference
48 0 return($self);
49  
50 }
51  
52 # create data tag object from ICC profile
53 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
54 # returns: (ref_to_object)
55 sub new_fh {
56  
57 # get object class
58 0 ▶ my $class = shift();
Subroutine new_fh: not called CC=2 SCAR=17.9
Pod undocumented
59  
60 # create empty data object
61 0 my $self = [
62 {}, # object header
63 1, # data flag
64 '' # data string
65 ];
66  
67 # verify 3 parameters
68 0 ▶ (@_ == 3) or croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
69  
70 # read data from profile
71 0 _readICCdata($self, @_);
72  
73 # bless object
74 0 bless($self, $class);
75  
76 # return object reference
77 0 return($self);
78  
79 }
80  
81 # writes data tag object to ICC profile
82 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
83 sub write_fh {
84  
85 # verify 4 parameters
86 0 ▶ (@_ == 4) or croak('wrong number of parameters');
Subroutine write_fh: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or croak("wrong number of parameters") 0 0 0
87  
88 # write data to profile
89 0 goto &_writeICCdata;
90  
91 }
92  
93 # get tag size (for writing to profile)
94 # returns: (tag_size)
95 sub size {
96
97 # get parameters
98 0 ▶ my ($self) = @_;
Subroutine size: not called CC=2 SCAR=17.9
Pod undocumented
99
100 # return size
101 0 ▶ return(12 + length($self->[2]) + ($self->[1] == 0 ? 1 : 0));
Branch: 1 branch
BranchTrueFalseTotal
$self->[1] == 0 ? : 0 0 0
102
103 }
104  
105 # get/set data string
106 # parameters: ([data_flag, data_string])
107 # returns: (data_string)
108 sub data {
109  
110 # get object reference
111 0 ▶ my $self = shift();
Subroutine data: not called CC=3 SCAR=24.8
Pod undocumented
112
113 # if parameters supplied
114 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
115
116 # save data flag
117 0 ▶ $self->[1] = shift() == 0 ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
shift() == 0 ? : 0 0 0
118
119 # save data string
120 0 $self->[2] = shift();
121
122 }
123
124 # return data string
125 0 return($self->[2]);
126  
127 }
128  
129 # print object contents to string
130 # format is an array structure
131 # parameter: ([format])
132 # returns: (string)
133 sub sdump {
134  
135 # get parameters
136 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
137  
138 # local variables
139 0 my ($s, $fmt);
140  
141 # resolve parameter to an array reference
142 0 ▶ $p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : [];
Branch: 2 branches
BranchTrueFalseTotal
defined $p ? : 0 0 0
ref $p eq 'ARRAY' ? : 0 0 0
143  
144 # get format string
145 0 ▶ $fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $p->[0] && !ref($p->[0]) ? : 0 0 0
Condition0%0/3
defined $p->[0] and not ref $p->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $p->[0] and not ref $p->[0]
defined $p->[0] not ref $p->[0]
Truth table0%0/3
A and not(B)
A= defined $p->[0]B= not ref $p->[0]
ABresult
0X0
100
111
146  
147 # set string to object ID
148 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
149  
150 # return
151 0 return($s);
152  
153 }
154  
155 # read data tag from ICC profile
156 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
157 sub _readICCdata {
158
159 # get parameters
160 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCdata: not called CC=3 SCAR=24.8
161
162 # local variables
163 0 my ($buf);
164
165 # save tag signature
166 0 $self->[0]{'signature'} = $tag->[0];
167
168 # seek start of tag
169 0 seek($fh, $tag->[1], 0);
170
171 # read type and data flag
172 0 read($fh, $buf, 12);
173
174 # unpack data flag
175 0 $self->[1] = unpack('x8 N', $buf);
176
177 # read remaining data
178 0 read($fh, $buf, $tag->[2] - 12);
179
180 # if ASCII data
181 0 ▶ if ($self->[1] == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->[1] == 0) { } 0 0 0
elsif ($self->[1] == 1) { } 0 0 0
182
183 # unpack ASCII data (zero terminated)
184 0 $self->[2] = unpack('Z*', $buf);
185
186 # if binary data
187 } elsif ($self->[1] == 1) {
188
189 # unpack binary data
190 0 $self->[2] = unpack('a*', $buf);
191
192 } else {
193
194 # print message
195 0 carp('unknown data type');
196
197 }
198
199 }
200  
201 # write data tag to ICC profile
202 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
203 sub _writeICCdata {
204  
205 # get parameters
206 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCdata: not called CC=3 SCAR=24.8
207  
208 # seek start of tag
209 0 seek($fh, $tag->[1], 0);
210  
211 # if ASCII data
212 0 ▶ if ($self->[1] == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->[1] == 0) { } 0 0 0
elsif ($self->[1] == 1) { } 0 0 0
213
214 # write tag
215 0 print $fh pack('a4 x4 N Z*', 'data', $self->[1], $self->[2]);
216
217 # if binary data
218 } elsif ($self->[1] == 1) {
219
220 # write tag
221 0 print $fh pack('a4 x4 N a*', 'data', $self->[1], $self->[2]);
222
223 } else {
224
225 # print message
226 0 carp('unknown data type');
227
228 }
229
230 }
231  
232 2 1;
« blib/lib/ICC/Support/geo2.pm ↑ Summary blib/lib/ICC/Profile/XYZ_.pm »