line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Vitals::Util; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Data::Vitals::Util - Utility methods for the Perl "Vital Statistics" Library |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Data::Vitals::Util defines a set of functions that are used in various |
12
|
|
|
|
|
|
|
places within the L classes. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
All functions are importable using the standard Exporter mechanism |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Data::Vitals::Util 'cm2inch'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 FUNCTIONS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
11
|
|
|
11
|
|
1342
|
use strict; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
512
|
|
23
|
11
|
|
|
11
|
|
64
|
use Exporter (); |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
378
|
|
24
|
|
|
|
|
|
|
|
25
|
11
|
|
|
11
|
|
58
|
use vars qw{$VERSION @ISA @EXPORT_OK}; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
1939
|
|
26
|
|
|
|
|
|
|
BEGIN { |
27
|
11
|
|
|
11
|
|
28
|
$VERSION = '0.05'; |
28
|
11
|
|
|
|
|
223
|
@ISA = 'Exporter'; |
29
|
11
|
|
|
|
|
2053
|
@EXPORT_OK = qw{cm2inch inch2cm}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# A pair of cm <-> inch conversion functions. |
37
|
|
|
|
|
|
|
# These are specialised DWIM converters for body measurements. |
38
|
|
|
|
|
|
|
# A key requirement for the integrity of the data is that the conversion |
39
|
|
|
|
|
|
|
# path inch->cm->inch is always guarenteed to be the same value. |
40
|
|
|
|
|
|
|
# The same is NOT true for cm->inch->cm, but since we always store and |
41
|
|
|
|
|
|
|
# calculate in cm this should not be a problem. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=pod |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 cm2inch $cm |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
The C function is a specialised method for converting a centimetre |
48
|
|
|
|
|
|
|
measurement to inchs. It converts using the standard 2.54004 multiplier, |
49
|
|
|
|
|
|
|
but rounds down to the half-inch. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
The algorithm used is specifically designed so that, when used as a pair |
52
|
|
|
|
|
|
|
with the inch2cm method, any value that C is |
53
|
|
|
|
|
|
|
always true, although it may not be true of the reverse. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
It takes as argument a number without any 'cm' indicator, and returns the |
56
|
|
|
|
|
|
|
number of inches as a similar plain number. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub cm2inch { |
61
|
204
|
|
|
204
|
1
|
851868
|
my $cm = 0 + shift; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# We round down slightly, but it should be less than half |
64
|
|
|
|
|
|
|
# an inch and so not a big issue from a fitting perspective. |
65
|
204
|
|
|
|
|
442
|
my $inch = int($cm / 2.54004); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Support half-inches |
68
|
204
|
|
|
|
|
353
|
my $part = ($cm / 2.54004) - $inch; |
69
|
204
|
100
|
|
|
|
674
|
$inch += 0.5 if $part >= 0.5; |
70
|
|
|
|
|
|
|
|
71
|
204
|
|
|
|
|
540
|
$inch; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=pod |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 inch2cm $cm |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The C function is a specialised method for converting an inch |
79
|
|
|
|
|
|
|
measurement to centimetres. It converts using the standard 2.54004 |
80
|
|
|
|
|
|
|
multiplier, but rounds up to the nearest centimetre. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
The algorithm used is specifically designed so that, when used as a pair |
83
|
|
|
|
|
|
|
with the cm2inch method, any value that C is |
84
|
|
|
|
|
|
|
always true, although it may not be true of the reverse. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
It takes as argument a number without any 'inch' indicator, and returns the |
87
|
|
|
|
|
|
|
number of centimetres as a similar plain number. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub inch2cm { |
92
|
188
|
|
|
188
|
1
|
87190
|
my $inch = 0 + shift; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# We round up slightly, but it should be less than a cm |
95
|
|
|
|
|
|
|
# and so not a big issue from a fitting perspective. |
96
|
188
|
|
|
|
|
456
|
my $cm = $inch * 2.54004; |
97
|
188
|
50
|
|
|
|
543
|
if ( $cm - int($cm) ) { |
98
|
188
|
|
|
|
|
246
|
$cm = int($cm) + 1; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
188
|
|
|
|
|
506
|
$cm; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=pod |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 SUPPORT |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Bugs should always be reported via the CPAN bug tracker |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
L |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
For other issues, contact the maintainer. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHORS |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Adam Kennedy Eadamk@cpan.orgE |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 ACKNOWLEGEMENTS |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Thank you to Phase N (L) for permitting |
123
|
|
|
|
|
|
|
the open sourcing and release of this distribution. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 COPYRIGHT |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Copyright 2004 - 2008 Adam Kennedy. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This program is free software; you can redistribute |
130
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
The full text of the license can be found in the |
133
|
|
|
|
|
|
|
LICENSE file included with this module. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |