blib/lib/Photography/EV.pm

filter: Statementstmt 89.3% 42 / 47 Branchbran 83.3% 5 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 92.8% 13 / 14 Podpod 100% 3 / 3 totaltotal 90.6% 68 / 75 CC 9 SCAR 8.8
CC
9
Cov
89%
__ANON__
6.0
_closest
4.0
BEGIN
2.5
CRAP 2.4
↑ Summary
1 4 package Photography::EV 0.07 {
2  
3 4 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶ use 5.020000;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶ use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶ use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶ BEGIN {
Subroutine BEGIN: called CC=2 SCAR=9.2
9 4 ▶ eval q{
Subroutine BEGIN: called CC=1 SCAR=0.0
10 use POSIX qw( pow );
11 };
12 4 ▶ if($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
13 {
14 0 ▶ *pow = sub ($x, $exponent)
Subroutine __ANON__: not called CC=2 SCAR=17.9
15 {
16 0 my $value = 1;
17 0 for(1..$exponent)
18 {
19 0 $value *= $x;
20 }
21 0 $value;
22 }
23 0 }
24 }
25  
26 4 our @EXPORT_OK = qw( ev aperture shutter_speed );
27 4 our @EXPORT = @EXPORT_OK;
28  
29 # ABSTRACT: Calculate exposure value (EV)
30  
31  
32 4 ▶ sub _round :prototype($)
Subroutine _round: called CC=2 SCAR=6.9
33 {
34 4 ▶ return $_[0] ? int($_[0] + $_[0]/abs($_[0]*2)) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 3 1 4
35 }
36  
37 4 ▶ sub _log2 :prototype($)
Subroutine _log2: called CC=1 SCAR=0.0
38 {
39 4 return log($_[0])/log(2);
40 }
41  
42 # returns the closest value in @$list to $exact
43 # returns undef if @$list is empty
44 5 ▶ sub _closest :prototype($$)
Subroutine _closest: called CC=4 SCAR=13.9
45 {
46 5 my($exact, $list) = @_;
47 5 my $answer;
48 my $diff;
49 5 for(@$list)
50 {
51 60 my $maybe = abs($_ - $exact);
52 60 ▶ if((!defined $answer) || $maybe < $diff)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $answer or $maybe < $diff) 41 19 60
Condition100%3/3
not defined $answer or $maybe < $diff
l!l&&r!l&&!r
33819
MC/DC100%2/2
not defined $answer or $maybe < $diff
not defined $answer $maybe < $diff
Truth table100%3/3
not(A) or B
A= not defined $answerB= $maybe < $diff
ABresult
1X1
011
000
53 {
54 41 $answer = $_;
55 41 $diff = $maybe;
56 }
57 }
58 5 $answer;
59 }
60  
61 4 my @apertures = qw(
62 1.0
63 1.4
64 2.8
65 4.0
66 5.6
67 8.0
68 11
69 16
70 22
71 32
72 45
73 64
74 );
75  
76 my @times = (
77 20 (map { $_ * 60 } qw( 32 16 8 4 2 )),
78 ( qw( 60 30 15 8 4 2 1)),
79 4 (map { 1 / $_ } qw( 2 4 8 15 30 125 250 500 1000 2000 4000 8000 ))
80 );
81  
82  
83 4 ▶ sub ev ($aperture, $time)
Subroutine ev: called CC=1 SCAR=0.0
Pod documented
84 {
85 4 return _round _log2 $aperture*$aperture/$time;
86 }
87  
88  
89 2 ▶ sub aperture ($ev, $time, $apertures = \@apertures )
Subroutine aperture: called CC=2 SCAR=6.9
Pod documented
90 {
91 2 return _closest sqrt pow(2, $ev)*$time, $apertures;
92 }
93  
94  
95 3 ▶ sub shutter_speed ($ev, $aperture, $times = \@times )
Subroutine shutter_speed: called CC=2 SCAR=6.9
Pod documented
96 {
97 3 return _closest $aperture*$aperture/pow(2, $ev), $times;
98 }
99  
100 }
101  
102 4 1;
103  
104 __END__
↑ Summary