Synchronize/GroupedInfo.pm

filter: Statementstmt 13.7% 10 / 73 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 25.0% 3 / 12 Podpod 100% 9 / 9 totaltotal 15.9% 22 / 138 CC 25 SCAR 41.9
CC
25
Cov
9%
get_context
156.0
set
42.0
stringify
30.0
CRAP 66.0
↑ Summary Synchronize/CameraOffsets.pm »
1 package Image::Synchronize::GroupedInfo;
2
3 1 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 1 ▶use overload '""' => \&stringify;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 =head1 NAME
10
11 Image::Synchronize::GroupedInfo - a data collection in support of
12 Image::Synchronize
13
14 =cut
15
16 =head1 METHODS
17
18 =head2 new
19
20 $egi = new Image::Synchronize::GroupedInfo;
21
22 Create a new instance of the class.
23
24 =cut
25
26 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
27 0 my ($class) = @_;
28 0 return bless {}, $class;
29 }
30
31 =head2 set
32
33 $egi->set($tag, $value);
34 $egi->set($group, $tag, $value);
35
36 Associated the C<$value> with the C<$tag> and (optionally) C<$group>.
37 The C<$group> and C<$tag> must be scalars, but the C<$value> may be of
38 any type. Returns C<$egi>.
39
40 =cut
41
42 0 ▶sub set {
Subroutine set: not called CC=6 SCAR=37.4
Pod documented
43 0 my $self = shift;
44 0 my ( $group, $tag, $value );
45 0 ▶ if ( scalar(@_) == 3 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 3) { } 0 0 0
elsif (scalar @_ == 2) { } 0 0 0
46 0 ( $group, $tag, $value ) = @_;
47 }
48 elsif ( scalar(@_) == 2 ) {
49 0 ( $tag, $value ) = @_;
50 }
51 else {
52 0 croak "Expected tag and value, or group, tag, and value.";
53 }
54 0 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 0 0 0
55 0 ▶ $self->{$tag}->{ $group // '' } = $value;
Condition0%0/2
$group // ""
l!l
00
MC/DC0%0/1
$group // ""
$group
Truth table0%0/2
A
A= $group
Aresult
11
00
56 }
57 else { # delete
58 0 ▶ if ( defined $group ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $group) { } 0 0 0
59 0 $self->delete( $group, $tag );
60 }
61 else {
62 0 $self->delete($tag);
63 }
64 }
65 0 return $self;
66 }
67
68 =head2 get_context
69
70 $value = $egi->get_context($group, $tag);
71
72 # get_context value from preferred group
73 $value = $egi->get_context($tag);
74
75 # list context: also return group name
76 ($group, $value) = $egi->get_context($group, $tag);
77 ($group, $value) = $egi->get_context($tag);
78
79 Returns the value for the specified C<$tag> in the specified C<$group>
80 or in the preferred group. In list mode, returns the group and the
81 value. Returns C<undef> if the value is undefined or if there is no
82 value for that tag and group.
83
84 =cut
85
86 0 ▶sub get_context {
Subroutine get_context: not called CC=12 SCAR=50.5
Pod documented
87 0 my ($self) = shift;
88 0 my ( $group, $tag );
89 0 ▶ if ( scalar(@_) == 2 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 2) { } 0 0 0
elsif (scalar @_ == 1) { } 0 0 0
90 0 ( $group, $tag ) = @_;
91 }
92 elsif ( scalar(@_) == 1 ) {
93 0 ($tag) = @_;
94 }
95 else {
96 0 croak "Expected tag, or group and tag.";
97 }
98 0 ▶ return unless exists $self->{$tag};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$tag} 0 0 0
99 0 ▶ if ( defined $group ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $group) { } 0 0 0
100 return
101 0 ▶ wantarray ? ( $group, $self->{$tag}->{$group} ) : $self->{$tag}->{$group};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
102 }
103 else {
104 # look for groups in descending order of preference
105 0 foreach my $group ( '', 'XMP', 'EXIF', 'File' ) {
106 0 my $v = $self->{$tag}->{$group};
107 0 ▶ if ( defined $v ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) 0 0 0
108 0 ▶ return wantarray ? ( $group, $v ) : $v;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
109 }
110 }
111
112 # otherwise return value for lexicographically first group
113 0 my $g = ( sort keys %{ $self->{$tag} } )[0];
114 0 ▶ if (defined $g) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $g) { } 0 0 0
115 0 ▶ return wantarray ? ( $g, $self->{$tag}->{$g} ) : $self->{$tag}->{$g};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
116 } else {
117 0 ▶ return wantarray ? () : undef;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
118 }
119 }
120 }
121
122 =head2 get
123
124 $value = $egi->get($group, $tag);
125
126 # get value from preferred group
127 $value = $egi->get($tag);
128
129 Returns the value for the specified C<$tag> in the specified C<$group>
130 or in the preferred group. Returns C<undef> if the value is undefined
131 or if there is no value for that tag and group.
132
133 Is like L</get_context> but always returns just the value.
134
135 =cut
136
137 0 ▶sub get {
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
138 0 my $v = get_context(@_);
139 0 return $v;
140 }
141
142 =head2 delete
143
144 $egi->delete($tag);
145 $egi->delete($group, $tag);
146
147 Deletes data associated with the C<$tag>. If the C<$group> is
148 specified, then deletes the tag's data for that group only. Otherwise
149 deletes the tag's data for any group. Returns C<$egi>.
150
151 =cut
152
153 0 ▶sub delete {
Subroutine delete: not called CC=4 SCAR=30.0
Pod documented
154 0 my ($self) = shift;
155 0 my ( $group, $tag );
156 0 ▶ if ( scalar(@_) == 2 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 2) { } 0 0 0
elsif (scalar @_ == 1) { } 0 0 0
157 0 ( $group, $tag ) = @_;
158 }
159 elsif ( scalar(@_) == 1 ) {
160 0 ($tag) = @_;
161 }
162 else {
163 0 croak "Expected tag, or group and tag.";
164 }
165 0 ▶ if ( defined $group ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $group) { } 0 0 0
166 0 delete $self->{$tag}->{$group};
167 }
168 else {
169 0 delete $self->{$tag};
170 }
171 0 return $self;
172 }
173
174 =head2 tags
175
176 @tags = $egi->tags;
177
178 Returns a list of all tags for which a value was specified.
179
180 =cut
181
182 0 ▶sub tags {
Subroutine tags: not called CC=1 SCAR=6.9
Pod documented
183 0 my ($self) = @_;
184 0 return sort keys %{$self};
185 }
186
187 =head2 tags_count
188
189 $count = $egi->tags_count;
190
191 Returns the count of tags for which a value was specified.
192
193 =cut
194
195 0 ▶sub tags_count {
Subroutine tags_count: not called CC=1 SCAR=6.9
Pod documented
196 0 my ($self) = @_;
197 0 return scalar(keys %{$self});
198 }
199
200 =head2 groups
201
202 @groups = $egi->groups($tag);
203
204 Returns a list of all groups for which a value was specified for the
205 C<$tag>.
206
207 =cut
208
209 0 ▶sub groups {
Subroutine groups: not called CC=2 SCAR=17.9
Pod documented
210 0 my ( $self, $tag ) = @_;
211 0 ▶ return () unless exists $self->{$tag};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$tag} 0 0 0
212 0 return sort keys %{ $self->{$tag} };
213 }
214
215 =head2 stringify
216
217 $text = $egi->stringify;
218 $text = "$egi";
219
220 Returns a text version of the contents of C<$egi>.
221
222 =cut
223
224 0 ▶sub stringify {
Subroutine stringify: not called CC=5 SCAR=34.0
Pod documented
225 0 my ( $self, $prefix ) = @_;
226 0 ▶ $prefix //= '';
Condition0%0/2
$prefix //= ""
l!l
00
MC/DC0%0/1
$prefix //= ""
$prefix
Truth table0%0/2
A
A= $prefix
Aresult
11
00
227 0 my @text;
228 0 foreach my $tag ( $self->tags ) {
229 0 foreach my $group ( $self->groups($tag) ) {
230 0 my $key = $tag;
231 0 ▶ $key .= " ($group)" if $group;
Branch: 1 branch
BranchTrueFalseTotal
if $group 0 0 0
232 0 push @text,
233 $prefix . sprintf( '%-35s : ', $key ) . $self->get( $group, $tag );
234 }
235 }
236 0 return join( "\n", @text );
237 }
238
239 =head1 AUTHOR
240
241 Louis Strous E<lt>LS@quae.nlE<gt>
242
243 =head1 LICENSE AND COPYRIGHT
244
245 Copyright (c) 2020 Louis Strous.
246
247 This program is free software; you can redistribute it and/or modify
248 it under the same terms as Perl itself.
249
250 =cut
251
252 1 1;
↑ Summary Synchronize/CameraOffsets.pm »