blib/lib/ICC/Profile/text.pm

filter: Statementstmt 80.0% 44 / 55 Branchbran 25.0% 4 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 10 / 12 Podpod 16.6% 1 / 6 totaltotal 62.7% 59 / 94 CC 10 SCAR 21.7
CC
10
Cov
65%
sdump
30.0
text
6.0
new
2.1
CRAP 8.8
« blib/lib/ICC/Profile/Generic.pm ↑ Summary blib/lib/ICC/Profile/clro.pm »
1 package ICC::Profile::text;
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 2016-05-17
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 text tag object
19 # parameters: ([text_string])
20 # returns: (ref_to_object)
21 sub new {
22  
23 # get object class
24 1 ▶ my $class = shift();
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
25
26 # create empty text object
27 1 my $self = [
28 {}, # object header
29 '' # text string
30 ];
31  
32 # if parameter supplied
33 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
34
35 # save it
36 0 $self->[1] = shift();
37
38 }
39  
40 # bless object
41 1 bless($self, $class);
42
43 # return object reference
44 1 return($self);
45  
46 }
47  
48 # create text tag object from ICC profile
49 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
50 # returns: (ref_to_object)
51 sub new_fh {
52  
53 # get object class
54 1 ▶ my $class = shift();
Subroutine new_fh: called CC=2 SCAR=7.0
Pod undocumented
55  
56 # create empty text object
57 1 my $self = [
58 {}, # object header
59 '' # text string
60 ];
61  
62 # verify 3 parameters
63 1 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 1 1
64  
65 # read text data from profile
66 1 _readICCtext($self, @_);
67  
68 # bless object
69 1 bless($self, $class);
70  
71 # return object reference
72 1 return($self);
73  
74 }
75  
76 # writes text tag object to ICC profile
77 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
78 sub write_fh {
79  
80 # get tag reference
81 1 ▶ my $self = shift();
Subroutine write_fh: called CC=2 SCAR=7.1
Pod undocumented
82  
83 # verify 3 parameters
84 1 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 1 1
85  
86 # write text data to profile
87 1 _writeICCtext($self, @_);
88  
89 }
90  
91 # get tag size (for writing to profile)
92 # returns: (tag_size)
93 sub size {
94
95 # get parameters
96 3 ▶ my ($self) = @_;
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
97
98 # get text string
99 3 my $txt = $self->[1];
100
101 # strip out non-ASCII characters
102 3 $txt =~ s/[^\x00-\x7F]//g;
103
104 # return size (string is null terminated)
105 3 return(8 + length($txt) + 1);
106
107 }
108  
109 # get/set text string
110 # parameters: ([text_string])
111 # returns: (text_string)
112 sub text {
113  
114 # get object reference
115 0 ▶ my $self = shift();
Subroutine text: not called CC=2 SCAR=17.9
Pod undocumented
116
117 # if parameter supplied
118 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
119
120 # save it
121 0 $self->[1] = shift();
122
123 }
124
125 # return text string
126 0 return($self->[1]);
127  
128 }
129  
130 # print object contents to string
131 # format is an array structure
132 # parameter: ([format])
133 # returns: (string)
134 sub sdump {
135  
136 # get parameters
137 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
138  
139 # local variables
140 0 my ($s, $fmt);
141  
142 # resolve parameter to an array reference
143 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
144  
145 # get format string
146 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
147  
148 # set string to object ID
149 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
150  
151 # return
152 0 return($s);
153  
154 }
155  
156 # read text tag from ICC profile
157 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
158 sub _readICCtext {
159
160 # get parameters
161 1 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCtext: called CC=1 SCAR=0.0
162
163 # local variables
164 1 my ($buf);
165
166 # save tag signature
167 1 $self->[0]{'signature'} = $tag->[0];
168
169 # seek start of tag
170 1 seek($fh, $tag->[1], 0);
171
172 # read tag
173 1 read($fh, $buf, $tag->[2]);
174
175 # unpack text string (null terminated)
176 1 $self->[1] = unpack('x8 Z*', $buf);
177
178 }
179  
180 # write text tag to ICC profile
181 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
182 sub _writeICCtext {
183  
184 # get parameters
185 1 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCtext: called CC=2 SCAR=7.0
186  
187 # local variables
188 1 my ($txt);
189  
190 # seek start of tag
191 1 seek($fh, $tag->[1], 0);
192  
193 # get text string
194 1 $txt = $self->[1];
195  
196 # strip out non-ASCII characters and warn
197 1 ▶ ($txt =~ s/[^\x00-\x7F]//g) && carp('non-ASCII character(s) removed from \'text\' tag');
Branch: 1 branch
BranchTrueFalseTotal
$txt =~ s/[^\x00-\x7F]//g and carp("non-ASCII character(s) removed from 'text' tag") 0 1 1
198  
199 # write tag
200 1 print $fh pack('a4 x4 Z*', 'text', $txt);
201  
202 }
203  
204 2 1;
« blib/lib/ICC/Profile/Generic.pm ↑ Summary blib/lib/ICC/Profile/clro.pm »