blib/lib/Photography/DX.pm

filter: Statementstmt 95.1% 59 / 62 Branchbran 90.9% 20 / 22 Conditioncond 68.5% 24 / 35 MC/DCmcdc 37.5% 6 / 16 Subroutinesub 94.4% 17 / 18 Podpod 83.3% 5 / 6 totaltotal 82.3% 131 / 159 CC 24 SCAR 16.9
CC
24
Cov
87%
is_custom_speed
10.7
BUILDARGS
9.5
__ANON__
4.0
CRAP 5.4
↑ Summary
1 package Photography::DX;
2  
3 4 ▶use 5.022;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Moo 2.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use experimental 'refaliasing';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: Encode/decode DX film codes
11 4 our $VERSION = '0.02'; # VERSION
12  
13  
14 4 my %log;
15 my %speed;
16  
17 4 my %length = (
18 undef => '000',
19 12 => '100',
20 20 => '010',
21 24 => '110',
22 36 => '001',
23 48 => '101',
24 60 => '011',
25 72 => '111',
26 );
27  
28 4 my %tolerance = qw(
29 0.5 00
30 1 10
31 2 01
32 3 11
33 );
34  
35 4 ▶while(<DATA>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline DATA)) 164 4 168
36 {
37 164 ▶ if(/^\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+$/)
Branch: 2 branches
BranchTrueFalseTotal
if (/^\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+$/u) { } 96 68 164
elsif (/^\s+([0-9]+)\s+-\s+([0-9]+)\s+$/u) { } 32 36 68
38 {
39 96 $log{$1} = $2;
40 96 $speed{$1} = $3;
41 }
42 elsif(/^\s+([0-9]+)\s+-\s+([0-9]+)\s+$/)
43 {
44 32 $speed{$1} = $2;
45 }
46 }
47  
48 sub BUILDARGS
49 21 ▶{
Subroutine BUILDARGS: called CC=9 SCAR=22.5
Pod undocumented
50 21 my $class = shift;
51 21 ▶ if(@_ % 2 == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2 == 0) { } 21 0 21
52 {
53 21 my %args = @_;
54
55 21 ▶ if(defined $args{contacts_row_1})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"contacts_row_1"}) 2 19 21
56 {
57 2 state $speed = { reverse %speed };
58 2 for \my %speed ($speed)
59 {
60 2 ▶ $args{speed} = $speed{$args{contacts_row_1}} || die "illegal value for contacts_row_1";
Condition50%1/2
$speed{$args{'contacts_row_1'}} || die('illegal value for contacts_row_1')
l!l
20
MC/DC0%0/1
$speed{$args{'contacts_row_1'}} || die('illegal value for contacts_row_1')
$speed{$args{'contacts_row_1'}}
Truth table50%1/2
A
A= $speed{$args{'contacts_row_1'}}
Aresult
11
00
61 }
62 }
63
64 21 ▶ if(defined $args{contacts_row_2})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"contacts_row_2"}) 2 19 21
65 {
66 2 ▶ if($args{contacts_row_2} =~ /^1([01]{3})([01]{2})$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'contacts_row_2'} =~ /^1([01]{3})([01]{2})$/u) { } 2 0 2
67 {
68 2 state $length = { reverse %length };
69 2 state $tolerance = { reverse %tolerance };
70 2 for \my %length ($length)
71 {
72 2 for \my %tolerance ($tolerance)
73 {
74 2 $args{length} = $length{$1};
75 2 $args{tolerance} = $tolerance{$2};
76 }
77 }
78 }
79 else
80 {
81 0 die "illegal value for contacts_row_2";
82 }
83 }
84
85 21 return \%args;
86 }
87 else
88 {
89 0 die "nope!";
90 }
91 }
92  
93  
94 has speed => (
95 is => 'ro',
96 lazy => 1,
97 1 ▶ default => sub { 100 },
Subroutine __ANON__: called CC=1 SCAR=0.0
98 8 ▶ isa => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
99 die "speed must be a legal ISO arithmetic film speed value between 25 and 5000 or 1-8 (indicating custom film speed values)"
100 8 ▶ unless defined $_[0] && (defined $log{$_[0]} || $_[0] =~ /^[1-8]$/);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] and defined $log{$_[0]} || $_[0] =~ /^[1-8]$/u 1 7 8
Condition83%5/6
defined $_[0] and defined $log{$_[0]} || $_[0] =~ /^[1-8]$/u
!ll&&!rl&&r
017
defined $log{$_[0]} or $_[0] =~ /^[1-8]$/u
l!l&&r!l&&!r
431
MC/DC66%2/3
defined $_[0] and defined $log{$_[0]} || $_[0] =~ /^[1-8]$/u
defined $_[0] defined $log{$_[0]} $_[0] =~ /^[1-8]$/u
Truth table75%3/4
A and B or C
A= defined $_[0]B= defined $log{$_[0]}C= $_[0] =~ /^[1-8]$/u
ABCresult
0XX0
1000
11X1
1011
101 },
102 4 );
103  
104  
105 has length => (
106 is => 'ro',
107 lazy => 1,
108 1 ▶ default => sub { undef },
Subroutine __ANON__: called CC=1 SCAR=0.0
109 9 ▶ isa => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
110 9 ▶ die "length must be one of undef, 12, 20, 24, 36, 48, 60 or 72"
Branch: 1 branch
BranchTrueFalseTotal
unless not defined $_[0] or $_[0] =~ /^(12|20|24|36|48|60|72)$/u 1 8 9
Condition100%3/3
not defined $_[0] or $_[0] =~ /^(12|20|24|36|48|60|72)$/u
l!l&&r!l&&!r
261
MC/DC100%2/2
not defined $_[0] or $_[0] =~ /^(12|20|24|36|48|60|72)$/u
not defined $_[0] $_[0] =~ /^(12|20|24|36|48|60|72)$/u
Truth table100%3/3
not(A) or B
A= not defined $_[0]B= $_[0] =~ /^(12|20|24|36|48|60|72)$/u
ABresult
1X1
011
000
111 unless (!defined $_[0]) || ($_[0] =~ /^(12|20|24|36|48|60|72)$/);
112 },
113 4 );
114  
115  
116 has tolerance => (
117 is => 'ro',
118 lazy => 1,
119 1 ▶ default => sub { 2 },
Subroutine __ANON__: called CC=1 SCAR=0.0
120 8 ▶ isa => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
121 8 ▶ die "tolerance must be one of 0.5, 1, 2, 3"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] and $_[0] =~ /^(0.5|1|2|3)$/u 1 7 8
Condition66%2/3
defined $_[0] and $_[0] =~ /^(0.5|1|2|3)$/u
!ll&&!rl&&r
017
MC/DC50%1/2
defined $_[0] and $_[0] =~ /^(0.5|1|2|3)$/u
defined $_[0] $_[0] =~ /^(0.5|1|2|3)$/u
Truth table66%2/3
A and B
A= defined $_[0]B= $_[0] =~ /^(0.5|1|2|3)$/u
ABresult
0X0
100
111
122 unless (defined $_[0]) && ($_[0] =~ /^(0.5|1|2|3)$/);
123 },
124 4 );
125  
126  
127 0 ▶sub contacts ($self)
Subroutine contacts: not called CC=1 SCAR=6.9
Pod documented
128 {
129 0 return ($self->contacts_row_1, $self->contacts_row_2);
130 }
131  
132  
133 2 ▶sub contacts_row_1 ($self)
Subroutine contacts_row_1: called CC=1 SCAR=0.0
Pod documented
134 {
135 2 return $speed{$self->speed};
136 }
137  
138  
139 2 ▶sub contacts_row_2 ($self)
Subroutine contacts_row_2: called CC=1 SCAR=0.0
Pod documented
140 {
141 2 return '1' . $length{$self->length} . $tolerance{$self->tolerance};
142 }
143  
144  
145 3 ▶sub is_custom_speed ($self)
Subroutine is_custom_speed: called CC=8 SCAR=23.7
Pod documented
146 {
147 3 my $speed = $self->speed;
148 3 ▶ return $speed == 1
Condition61%13/21
$speed == 1 || $speed == 2 || $speed == 3 || $speed == 4 || $speed == 5 || $speed == 6 || $speed == 7 || $speed == 8
l!l&&r!l&&!r
102
$speed == 1 or $speed == 2 or $speed == 3 or $speed == 4 or $speed == 5 or $speed == 6 or $speed == 7
l!l&&r!l&&!r
102
$speed == 1 or $speed == 2 or $speed == 3 or $speed == 4 or $speed == 5 or $speed == 6
l!l&&r!l&&!r
102
$speed == 1 or $speed == 2 or $speed == 3 or $speed == 4 or $speed == 5
l!l&&r!l&&!r
102
$speed == 1 or $speed == 2 or $speed == 3 or $speed == 4
l!l&&r!l&&!r
102
$speed == 1 or $speed == 2 or $speed == 3
l!l&&r!l&&!r
012
$speed == 1 or $speed == 2
l!l&&r!l&&!r
003
MC/DC12%1/8
$speed == 1 || $speed == 2 || $speed == 3 || $speed == 4 || $speed == 5 || $speed == 6 || $speed == 7 || $speed == 8
$speed == 1 $speed == 2 $speed == 3 $speed == 4 $speed == 5 $speed == 6 $speed == 7 $speed == 8
Truth table22%2/9
A or B or C or D or E or F or G || H
A= $speed == 1B= $speed == 2C= $speed == 3D= $speed == 4E= $speed == 5F= $speed == 6G= $speed == 7H= $speed == 8
ABCDEFGHresult
1XXXXXXX1
01XXXXXX1
001XXXXX1
0001XXXX1
00001XXX1
000001XX1
0000001X1
000000011
000000000
149 || $speed == 2
150 || $speed == 3
151 || $speed == 4
152 || $speed == 5
153 || $speed == 6
154 || $speed == 7
155 || $speed == 8;
156 }
157  
158  
159 3 ▶sub logarithmic_speed ($self)
Subroutine logarithmic_speed: called CC=2 SCAR=6.9
Pod documented
160 {
161 3 my $din = $log{$self->speed};
162 3 ▶ croak "Unable to determine ISO logarithmic scale speed for custom " . $self->speed
Branch: 1 branch
BranchTrueFalseTotal
unless defined $din 1 2 3
163 unless defined $din;
164 2 return $din; # no loger a performance penalty in 5.20!
165 }
166  
167  
168 4 1;
169  
170 =pod
171  
172 =encoding utf-8
173  
174 =head1 NAME
175  
176 Photography::DX - Encode/decode DX film codes
177  
178 =head1 VERSION
179  
180 version 0.02
181  
182 =head1 SYNOPSIS
183  
184 use Photography::DX;
185
186 my $film = Photography::DX->new(
187 speed => 100,
188 length => 36,
189 tolerance => 2,
190 );
191
192 # print out the layout of contacts
193 # on the roll of film as a series
194 # of 1s and 0s:
195 print $film->contacts_row_1, "\n";
196 print $film->contacts_row_2, "\n";
197  
198 =head1 DESCRIPTION
199  
200 This class represents a roll of 35mm film, and allows you to compute the
201 DX encoding contacts used by film cameras that automatically detect film
202 speed, the number of exposures and the exposure tolerance of the film
203 (most cameras actually use only the film speed for the DX encoding).
204  
205 =head1 CONSTRUCTOR
206  
207 my $film = Photography::DX->new;
208  
209 In addition the attributes documented below you may pass into
210 the constructor:
211  
212 =over 4
213  
214 =item contacts_row_1
215  
216 The first row of contacts on the roll of film. The speed
217 will be computed from this value.
218  
219 =item contacts_row_2
220  
221 The second row of contacts on the roll of film. The length
222 and tolerance will be computed from this value.
223  
224 =back
225  
226 =head1 ATTRIBUTES
227  
228 =head2 speed
229  
230 The film speed. Must be a legal ISO arithmetic value between 25 and 5000. Defaults to ISO 100.
231  
232 Special values 1-8 denote "custom" values.
233  
234 =head2 length
235  
236 The length of the film in 32x24mm exposures. Must be one of undef (denotes "other"),
237 12, 20, 24, 36, 48, 60, 72.
238  
239 =head2 tolerance
240  
241 The exposure latitude of the film. Must be one of:
242  
243 =over 4
244  
245 =item 0.5 for ±0.5 stop
246  
247 =item 1 for ±1 stop
248  
249 =item 2 for +2 to -1 stops
250  
251 =item 3 for +3 to -1 stops
252  
253 =back
254  
255 =head1 METHODS
256  
257 =head2 contacts
258  
259 my($row1, $row2) = $film->contacts;
260  
261 Returns both rows of contacts.
262  
263 =head2 contacts_row_1
264  
265 Returns the contact layout as a string of 1s and 0s for the first row
266 of electrical contacts. 1 represents a metal contact, 0 represents the
267 lack of metal.
268  
269 =head2 contacts_row_2
270  
271 Returns the contact layout as a string of 1s and 0s for the second row
272 of electrical contacts. 1 represents a metal contact, 0 represents the
273 lack of metal.
274  
275 =head2 is_custom_speed
276  
277 Returns true if the film speed is a custom film speed.
278  
279 =head2 logarithmic_speed
280  
281 Returns the ISO logarithmic scale speed of the film (also known as DIN).
282  
283 =head1 CAVEATS
284  
285 In digital photography, DX also refers to Nikon's crop sensor format DSLRs.
286  
287 DX encoding was introduced in 1980, well after the development of 35mm film
288 and so many types of film do not include DX codes.
289  
290 This module uses features in and requires Perl 5.22.
291  
292 =head1 SEE ALSO
293  
294 =over 4
295  
296 =item L<Photography::EV>
297  
298 =item L<http://en.wikipedia.org/wiki/DX_encoding>
299  
300 =back
301  
302 =head1 AUTHOR
303  
304 Graham Ollis <plicease@cpan.org>
305  
306 =head1 COPYRIGHT AND LICENSE
307  
308 This software is copyright (c) 2015 by Graham Ollis.
309  
310 This is free software; you can redistribute it and/or modify it under
311 the same terms as the Perl 5 programming language system itself.
312  
313 =cut
314  
315 __DATA__
↑ Summary