File Coverage

blib/lib/Acme/Drunk.pm
Criterion Covered Total %
statement 29 34 85.2
branch 2 4 50.0
condition 3 6 50.0
subroutine 10 13 76.9
pod 4 10 40.0
total 48 67 71.6


line stmt bran cond sub pod time code
1             package Acme::Drunk;
2 1     1   27224 use strict;
  1         3  
  1         45  
3              
4             require Exporter;
5 1     1   6 use base qw[Exporter];
  1         1  
  1         122  
6 1     1   6 use vars qw[$VERSION @EXPORT %EXPORT_TAGS];
  1         5  
  1         710  
7              
8             $VERSION = '0.03';
9             @EXPORT = qw[MALE FEMALE drunk floz_to_etoh proof_to_percent];
10             %EXPORT_TAGS = ( ':all' => \@EXPORT );
11              
12             sub ML_IN_FLOZ () { 0.0338140226 }
13              
14             sub MALE () { 0 }
15             sub FEMALE () { 1 }
16              
17             # Widmark r factor (reduced body mass).
18             # Men: 0.50-0.90 avg 0.68.
19             # Women: 0.45-0.63 avg 0.55.
20             sub MALE_WIDMARK_R () { 0.68 }
21             sub FEMALE_WIDMARK_R () { 0.55 }
22              
23             # Widmark beta factor (alcohol metabolized per hour).
24             # Between 1.0% and 2.4%, avg 1.7%.
25             sub WIDMARK_BETA () { 0.017 };
26              
27             # Ethyl Alcohol weight in pounds.
28             sub ETOH_WEIGHT () { 0.0514 }
29              
30             # 1987, Fitzgerald & Hume discover specific
31             # gravity of blood is important, at 1.055 g/ml.
32             sub GRAVITY_OF_BLOOD () { 1.055 }
33              
34             # Body Alcohol Concentration
35             sub bac {
36 1     1 0 3 my ($body_weight, $alcohol_weight) = @_;
37 1         3 $alcohol_weight / $body_weight * 100;
38             }
39              
40             # Portion of body that holds alcohol.
41             sub bha {
42 1     1 0 2 my ($body_weight, $gender) = @_;
43 1 50       9 $body_weight * ( $gender == MALE ? MALE_WIDMARK_R : FEMALE_WIDMARK_R );
44             }
45              
46             # Water Tissue Alcohol Concentration
47             sub wtac {
48 1     1 0 3 my ($body_weight, $alcohol_weight, $gender) = @_;
49 1         5 bac( bha($body_weight, $gender), $alcohol_weight );
50             }
51              
52             # Proof goes to 200.
53             sub proof_to_percent {
54 0     0 1 0 my ($proof) = @_;
55 0         0 $proof / 2;
56             }
57              
58             # For N fluid ounces of alcohol, find pure alcohol content.
59             sub floz_to_etoh {
60 0     0 1 0 my ($ounces, $percent) = @_;
61 0         0 $ounces * $percent;
62             }
63              
64             # For N ml of alcohol, find pure alcohol content.
65             sub ml_to_etoh {
66 0     0 1 0 floz_to_etoh( $_[0] * ML_IN_FLOZ, $_[1] );
67             }
68              
69             # Convert fluid_ounces of EtOH to weight in pounds.
70             sub etoh_to_lbs {
71 1     1 0 2 my ($ounces) = @_;
72 1         8 $ounces * ETOH_WEIGHT;
73             }
74              
75             # multiply wtac with gravity of blood.
76             sub consider_gravity {
77 1     1 0 2 my ($alcohol_weight) = @_;
78 1         5 $alcohol_weight * GRAVITY_OF_BLOOD;
79             }
80              
81             # Remove metabolized alcohol over drinking time.
82             sub remove_metabolized_alcohol {
83 1     1 0 2 my ($alcohol_weight, $hours) = @_;
84 1         4 $alcohol_weight - ( $hours * WIDMARK_BETA );
85             }
86              
87             # Are you drunk?
88             sub drunk {
89 1     1 1 11 my (%params) = @_;
90 1 50       5 $params{gender} = MALE unless defined $params{gender};
91 1   50     4 $params{body_weight} ||= 150;
92 1   50     5 $params{hours} ||= 2;
93 1   50     6 $params{alcohol_weight} = consider_gravity( etoh_to_lbs( $params{alcohol_weight} || 3 ) );
94              
95 1         6 my $concentration = wtac( @params{qw[body_weight alcohol_weight gender]} );
96 1         4 $concentration = remove_metabolized_alcohol( $concentration, $params{hours} );
97              
98 1         5 return $concentration;
99             }
100              
101             1;
102              
103             __END__