blib/lib/ICC/Profile/text.pm

filter: Statementstmt 79.6% 43 / 54 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.3% 58 / 93 CC 10 SCAR 21.7
CC
10
Cov
64%
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 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 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) or 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 # verify 4 parameters
81 1 ▶ (@_ == 4) or croak('wrong number of parameters');
Subroutine write_fh: called CC=2 SCAR=7.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or croak("wrong number of parameters") 0 1 1
82  
83 # write text data to profile
84 1 goto &_writeICCtext;
85  
86 }
87  
88 # get tag size (for writing to profile)
89 # returns: (tag_size)
90 sub size {
91
92 # get parameters
93 3 ▶ my ($self) = @_;
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
94
95 # get text string
96 3 my $txt = $self->[1];
97
98 # strip out non-ASCII characters
99 3 $txt =~ s/[^\x00-\x7F]//g;
100
101 # return size (string is null terminated)
102 3 return(8 + length($txt) + 1);
103
104 }
105  
106 # get/set text string
107 # parameters: ([text_string])
108 # returns: (text_string)
109 sub text {
110  
111 # get object reference
112 0 ▶ my $self = shift();
Subroutine text: not called CC=2 SCAR=17.9
Pod undocumented
113
114 # if parameter supplied
115 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
116
117 # save it
118 0 $self->[1] = shift();
119
120 }
121
122 # return text string
123 0 return($self->[1]);
124  
125 }
126  
127 # print object contents to string
128 # format is an array structure
129 # parameter: ([format])
130 # returns: (string)
131 sub sdump {
132  
133 # get parameters
134 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
135  
136 # local variables
137 0 my ($s, $fmt);
138  
139 # resolve parameter to an array reference
140 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
141  
142 # get format string
143 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
144  
145 # set string to object ID
146 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
147  
148 # return
149 0 return($s);
150  
151 }
152  
153 # read text tag from ICC profile
154 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
155 sub _readICCtext {
156
157 # get parameters
158 1 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCtext: called CC=1 SCAR=0.0
159
160 # local variables
161 1 my ($buf);
162
163 # save tag signature
164 1 $self->[0]{'signature'} = $tag->[0];
165
166 # seek start of tag
167 1 seek($fh, $tag->[1], 0);
168
169 # read tag
170 1 read($fh, $buf, $tag->[2]);
171
172 # unpack text string (null terminated)
173 1 $self->[1] = unpack('x8 Z*', $buf);
174
175 }
176  
177 # write text tag to ICC profile
178 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
179 sub _writeICCtext {
180  
181 # get parameters
182 1 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCtext: called CC=2 SCAR=7.0
183  
184 # local variables
185 1 my ($txt);
186  
187 # seek start of tag
188 1 seek($fh, $tag->[1], 0);
189  
190 # get text string
191 1 $txt = $self->[1];
192  
193 # strip out non-ASCII characters and warn
194 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
195  
196 # write tag
197 1 print $fh pack('a4 x4 Z*', 'text', $txt);
198  
199 }
200  
201 2 1;
« blib/lib/ICC/Profile/Generic.pm ↑ Summary blib/lib/ICC/Profile/clro.pm »