blib/lib/ICC/Profile/Generic.pm

filter: Statementstmt 72.3% 34 / 47 Branchbran 21.4% 3 / 14 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 9 / 12 Podpod 16.6% 1 / 6 totaltotal 53.9% 48 / 89 CC 10 SCAR 21.9
CC
10
Cov
57%
sdump
30.0
data
6.0
new
3.4
CRAP 9.0
« blib/lib/ICC/Profile/sig_.pm ↑ Summary blib/lib/ICC/Profile/text.pm »
1 package ICC::Profile::Generic;
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.21;
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 generic tag object
19 # parameters: ()
20 # parameters: (ref_to_attribute_hash)
21 # returns: (ref_to_object)
22 sub new {
23  
24 # get object class
25 1 ▶ my $class = shift();
Subroutine new: called CC=3 SCAR=12.3
Pod undocumented
26  
27 # create empty generic object
28 1 my $self = [
29 {}, # object header
30 '' # data
31 ];
32  
33 # if single parameter is a scalar
34 1 ▶ if (@_ == 1 && ! ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and not ref $_[0]) 0 1 1
Condition33%1/3
@_ == 1 and not ref $_[0]
!ll&&!rl&&r
100
MC/DC0%0/2
@_ == 1 and not ref $_[0]
@_ == 1 not ref $_[0]
Truth table33%1/3
A and not(B)
A= @_ == 1B= not ref $_[0]
ABresult
0X0
100
111
35  
36 # set object data
37 0 $self->[1] = shift();
38  
39 }
40  
41 # bless object
42 1 bless($self, $class);
43  
44 # return object reference
45 1 return($self);
46  
47 }
48  
49 # create generic tag object from ICC profile
50 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
51 # returns: (ref_to_object)
52 sub new_fh {
53  
54 # get object class
55 12 ▶ my $class = shift();
Subroutine new_fh: called CC=2 SCAR=7.0
Pod undocumented
56  
57 # create empty generic object
58 12 my $self = [
59 {}, # object header
60 '' # data
61 ];
62  
63 # verify 3 parameters
64 12 ▶ (@_ == 3) or croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 12 12
65  
66 # read generic data from profile
67 12 _readICCgeneric($self, @_);
68  
69 # bless object
70 12 bless($self, $class);
71  
72 # return object reference
73 12 return($self);
74  
75 }
76  
77 # writes generic tag object to ICC profile
78 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
79 sub write_fh {
80  
81 # verify 4 parameters
82 12 ▶ (@_ == 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 12 12
83  
84 # write generic data to profile
85 12 goto &_writeICCgeneric;
86  
87 }
88  
89 # get tag size (for writing to profile)
90 # returns: (tag_size)
91 sub size {
92
93 # get parameters
94 0 ▶ my ($self) = @_;
Subroutine size: not called CC=1 SCAR=6.9
Pod undocumented
95
96 # return size
97 0 return(length($self->[1]));
98
99 }
100  
101 # get/set data string
102 # parameters: ([data])
103 # returns: (data)
104 sub data {
105  
106 # get object reference
107 0 ▶ my $self = shift();
Subroutine data: not called CC=2 SCAR=17.9
Pod undocumented
108  
109 # if parameter supplied
110 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
111
112 # save it
113 0 $self->[1] = shift();
114
115 }
116  
117 # return text string
118 0 return($self->[1]);
119  
120 }
121  
122 # print object contents to string
123 # format is an array structure
124 # parameter: ([format])
125 # returns: (string)
126 sub sdump {
127  
128 # get parameters
129 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
130  
131 # local variables
132 0 my ($s, $fmt);
133  
134 # resolve parameter to an array reference
135 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
136  
137 # get format string
138 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
139  
140 # set string to object ID
141 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
142  
143 # return
144 0 return($s);
145  
146 }
147  
148 # read generic tag from ICC profile
149 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
150 sub _readICCgeneric {
151
152 # get parameters
153 12 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCgeneric: called CC=1 SCAR=0.0
154
155 # save tag signature
156 12 $self->[0]{'signature'} = $tag->[0];
157
158 # seek start of tag
159 12 seek($fh, $tag->[1], 0);
160
161 # read tag
162 12 read($fh, $self->[1], $tag->[2]);
163
164 }
165  
166 # write generic tag to ICC profile
167 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
168 sub _writeICCgeneric {
169
170 # get parameters
171 12 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCgeneric: called CC=1 SCAR=0.0
172
173 # seek start of tag
174 12 seek($fh, $tag->[1], 0);
175
176 # write tag
177 12 print $fh $self->[1];
178
179 }
180  
181 2 1;
« blib/lib/ICC/Profile/sig_.pm ↑ Summary blib/lib/ICC/Profile/text.pm »