line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Fraction; |
2
|
1
|
|
|
1
|
|
678
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
323
|
|
4
|
|
|
|
|
|
|
our $VERSION = "0.50"; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# numbers with an exact fractional part |
7
|
|
|
|
|
|
|
my %dec = ( |
8
|
|
|
|
|
|
|
'25' => "1/4", |
9
|
|
|
|
|
|
|
'5' => "1/2", |
10
|
|
|
|
|
|
|
'75' => "3/4", |
11
|
|
|
|
|
|
|
'2' => "1/5", |
12
|
|
|
|
|
|
|
'4' => "2/5", |
13
|
|
|
|
|
|
|
'6' => "3/5", |
14
|
|
|
|
|
|
|
'8' => "4/5", |
15
|
|
|
|
|
|
|
'125' => "1/8", |
16
|
|
|
|
|
|
|
'375' => "3/8", |
17
|
|
|
|
|
|
|
'625' => "5/8", |
18
|
|
|
|
|
|
|
'875' => "7/8", |
19
|
|
|
|
|
|
|
'1' => "1/10", |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# two decimal |
23
|
|
|
|
|
|
|
my %tdp = ( |
24
|
|
|
|
|
|
|
'13' => "1/8", |
25
|
|
|
|
|
|
|
'38' => "3/8", |
26
|
|
|
|
|
|
|
'63' => "5/8", |
27
|
|
|
|
|
|
|
'88' => "7/8", |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my %name2char = ( |
31
|
|
|
|
|
|
|
'1/4' => '¼', |
32
|
|
|
|
|
|
|
'1/2' => '½', |
33
|
|
|
|
|
|
|
'3/4' => '¾', |
34
|
|
|
|
|
|
|
'0/3' => '↉', |
35
|
|
|
|
|
|
|
'1/3' => '⅓', |
36
|
|
|
|
|
|
|
'2/3' => '⅔', |
37
|
|
|
|
|
|
|
'1/5' => '⅕', |
38
|
|
|
|
|
|
|
'2/5' => '⅖', |
39
|
|
|
|
|
|
|
'3/5' => '⅗', |
40
|
|
|
|
|
|
|
'4/5' => '⅘', |
41
|
|
|
|
|
|
|
'1/6' => '⅙', |
42
|
|
|
|
|
|
|
'5/6' => '⅚', |
43
|
|
|
|
|
|
|
'1/7' => '⅐', |
44
|
|
|
|
|
|
|
'1/8' => '⅛', |
45
|
|
|
|
|
|
|
'3/8' => '⅜', |
46
|
|
|
|
|
|
|
'5/8' => '⅝', |
47
|
|
|
|
|
|
|
'7/8' => '⅞', |
48
|
|
|
|
|
|
|
'1/9' => '⅑', |
49
|
|
|
|
|
|
|
'1/10' => '⅒', |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
240
|
|
|
240
|
|
237
|
sub _name2char { shift; $name2char{shift()} } |
|
240
|
|
|
|
|
951
|
|
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
1
|
1
|
922
|
sub new { bless {}, shift } |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub tweak |
57
|
|
|
|
|
|
|
{ |
58
|
131
|
|
|
131
|
1
|
63384
|
my ($self, $in) = @_; |
59
|
131
|
|
|
|
|
267
|
return $self->tweak_frac($self->tweak_dec($in)); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub tweak_frac |
63
|
|
|
|
|
|
|
{ |
64
|
131
|
|
|
131
|
1
|
163
|
my ($self, $in) = @_; |
65
|
|
|
|
|
|
|
|
66
|
131
|
|
|
|
|
651
|
my $thingy = join '|', keys %name2char; |
67
|
131
|
|
|
|
|
736
|
$in =~ s{\b($thingy)\b}{ |
68
|
32
|
|
|
|
|
57
|
$self->_name2char($1) |
69
|
|
|
|
|
|
|
}ge; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# repeatin |
72
|
131
|
|
|
|
|
555
|
return $in; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub tweak_dec |
76
|
|
|
|
|
|
|
{ |
77
|
131
|
|
|
131
|
1
|
155
|
my ($self, $in) = @_; |
78
|
|
|
|
|
|
|
|
79
|
131
|
|
|
|
|
540
|
my $thingy = join '|', keys %dec; |
80
|
131
|
|
|
|
|
1154
|
$in =~ s{([0-9]*)\.($thingy)0*\b}{ |
81
|
1
|
|
|
1
|
|
4
|
no warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
73
|
|
82
|
108
|
50
|
|
|
|
433
|
($1+0 ? $1 : "") . $self->_name2char($dec{$2}) |
83
|
|
|
|
|
|
|
}ge; |
84
|
|
|
|
|
|
|
|
85
|
131
|
|
|
|
|
342
|
$thingy = join '|', keys %tdp; |
86
|
131
|
|
|
|
|
611
|
$in =~ s{([0-9]*)\.($thingy)\b}{ |
87
|
1
|
|
|
1
|
|
4
|
no warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
88
|
4
|
50
|
|
|
|
23
|
($1+0 ? $1 : "") . $self->_name2char($tdp{$2}) |
89
|
|
|
|
|
|
|
}ge; |
90
|
|
|
|
|
|
|
|
91
|
131
|
|
|
|
|
210
|
$in =~ s{([0-9]*)\.33+\b}{ |
92
|
1
|
|
|
1
|
|
6
|
no warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
98
|
|
93
|
12
|
50
|
|
|
|
48
|
($1+0 ? $1 : "") . $self->_name2char("1/3") |
94
|
|
|
|
|
|
|
}ge; |
95
|
|
|
|
|
|
|
|
96
|
131
|
|
|
|
|
170
|
$in =~ s{([0-9]*)\.66*7+\b}{ |
97
|
1
|
|
|
1
|
|
5
|
no warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
98
|
12
|
50
|
|
|
|
51
|
($1+0 ? $1 : "") . $self->_name2char("2/3") |
99
|
|
|
|
|
|
|
}ge; |
100
|
|
|
|
|
|
|
|
101
|
131
|
|
|
|
|
180
|
$in =~ s{([0-9]*)\.83+\b}{ |
102
|
1
|
|
|
1
|
|
3
|
no warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
64
|
|
103
|
12
|
50
|
|
|
|
45
|
($1+0 ? $1 : "") . $self->_name2char("5/6") |
104
|
|
|
|
|
|
|
}ge; |
105
|
|
|
|
|
|
|
|
106
|
131
|
|
|
|
|
264
|
$in =~ s{([0-9]*)\.16*7+\b}{ |
107
|
1
|
|
|
1
|
|
4
|
no warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
59
|
|
108
|
12
|
50
|
|
|
|
50
|
($1+0 ? $1 : "") . $self->_name2char("1/6") |
109
|
|
|
|
|
|
|
}ge; |
110
|
|
|
|
|
|
|
|
111
|
131
|
|
|
|
|
158
|
$in =~ s{([0-9]*)\.11+\b}{ |
112
|
1
|
|
|
1
|
|
4
|
no warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
63
|
|
113
|
12
|
50
|
|
|
|
39
|
($1+0 ? $1 : "") . $self->_name2char("1/9") |
114
|
|
|
|
|
|
|
}ge; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# 0.142857142857143 |
117
|
131
|
|
|
|
|
229
|
$in =~ s{ |
118
|
|
|
|
|
|
|
([0-9]*) |
119
|
|
|
|
|
|
|
\. |
120
|
|
|
|
|
|
|
14 |
121
|
|
|
|
|
|
|
(?: |
122
|
|
|
|
|
|
|
3|2(?: |
123
|
|
|
|
|
|
|
9|8(?: |
124
|
|
|
|
|
|
|
6|5(?: |
125
|
|
|
|
|
|
|
7(?: 1(?:4\d*)? )? |
126
|
|
|
|
|
|
|
) |
127
|
|
|
|
|
|
|
) |
128
|
|
|
|
|
|
|
) |
129
|
|
|
|
|
|
|
)? |
130
|
|
|
|
|
|
|
\b}{ |
131
|
1
|
|
|
1
|
|
3
|
no warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
160
|
|
132
|
36
|
50
|
|
|
|
125
|
($1+0 ? $1 : "") . $self->_name2char("1/7") |
133
|
|
|
|
|
|
|
}gex; |
134
|
|
|
|
|
|
|
|
135
|
131
|
|
|
|
|
438
|
return $in; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
__END__ |