line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Tie::Function::Examples; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
@ISA = qw(Tie::StdHash Exporter); |
5
|
|
|
|
|
|
|
@EXPORT_OK = qw(%thoucomma %nothoucomma %addcents %q_shell %q_perl %round %sprintf %line_numbers); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Tie::Hash; |
8
|
|
|
|
|
|
|
require Exporter; |
9
|
2
|
|
|
2
|
|
603
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
144
|
|
10
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
53
|
|
11
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
84
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.44; |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
15221
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
tie our %q_perl, 'Tie::Function::Examples', |
18
|
|
|
|
|
|
|
sub { |
19
|
|
|
|
|
|
|
my ($string) = @_; |
20
|
|
|
|
|
|
|
$string =~ s/'/'."'".'/g; |
21
|
|
|
|
|
|
|
return "'$string'"; |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
tie our %q_shell, 'Tie::Function::Examples', |
25
|
|
|
|
|
|
|
sub { |
26
|
|
|
|
|
|
|
my ($file) = @_; |
27
|
|
|
|
|
|
|
return $file if $file =~ /^[-,_\.+=:\/0-9a-zA-Z]+$/; |
28
|
|
|
|
|
|
|
$file =~ s/'/'\\''/g; |
29
|
|
|
|
|
|
|
return "'$file'"; |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
tie our %sprintf, 'Tie::Function::Examples', |
34
|
|
|
|
|
|
|
sub { |
35
|
|
|
|
|
|
|
my ($format, @args) = split($; , $_[0]); |
36
|
|
|
|
|
|
|
return sprintf($format, @args); |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
tie our %round, 'Tie::Function::Examples', |
40
|
|
|
|
|
|
|
sub { |
41
|
|
|
|
|
|
|
my ($amount, $scale) = split($; , $_[0]); |
42
|
|
|
|
|
|
|
require POSIX; |
43
|
|
|
|
|
|
|
$scale = 1 unless $scale; |
44
|
|
|
|
|
|
|
# scale = .01 for cents |
45
|
|
|
|
|
|
|
# scale = 1000 for thousands |
46
|
|
|
|
|
|
|
$amount /= $scale; |
47
|
|
|
|
|
|
|
$amount += .5; |
48
|
|
|
|
|
|
|
$amount = POSIX::floor($amount); |
49
|
|
|
|
|
|
|
$amount *= $scale; |
50
|
|
|
|
|
|
|
return $amount; |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
tie my %decomma, 'Tie::Function::Examples', |
54
|
|
|
|
|
|
|
sub { |
55
|
|
|
|
|
|
|
my ($f) = @_; |
56
|
|
|
|
|
|
|
$f =~ s/,//g; |
57
|
|
|
|
|
|
|
return $f; |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
tie our %nothoucomma, 'Tie::Function::Examples', |
61
|
|
|
|
|
|
|
sub { |
62
|
|
|
|
|
|
|
my ($number) = @_; |
63
|
|
|
|
|
|
|
$number =~ s/(\A|\D)(\d\d?\d?)(,\d\d\d)+(\D|\z)/$1$2$decomma{$3}$4/g; |
64
|
|
|
|
|
|
|
return $number; |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
tie our %thoucomma, 'Tie::Function::Examples', |
68
|
|
|
|
|
|
|
sub { |
69
|
|
|
|
|
|
|
my ($number) = @_; |
70
|
|
|
|
|
|
|
1 while ($number =~ s/(?
|
71
|
|
|
|
|
|
|
return $number; |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
tie our %addcents, 'Tie::Function::Examples', |
75
|
|
|
|
|
|
|
sub { |
76
|
|
|
|
|
|
|
my ($money) = @_; |
77
|
|
|
|
|
|
|
1 while ($money =~ s/(?
|
78
|
|
|
|
|
|
|
1 while ($money =~ s/(?
|
79
|
|
|
|
|
|
|
1 while ($money =~ s/(?
|
80
|
|
|
|
|
|
|
$money =~ s/(\d+\.\d\d\d+)([^\d,]|\z|,(?!\d))/$sprintf{'%.2f', $1}$2/g; |
81
|
|
|
|
|
|
|
$money =~ s/(\d[\d,]+\.\d\d\d+)([^\d,]|\z|,(?!\d))/$thoucomma{$sprintf{'%.2f', $nothoucomma{$1}}}$2/g; |
82
|
|
|
|
|
|
|
return $money; |
83
|
|
|
|
|
|
|
}; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
tie our %line_numbers, 'Tie::Function::Examples', |
86
|
|
|
|
|
|
|
sub { |
87
|
|
|
|
|
|
|
my $text = shift; |
88
|
|
|
|
|
|
|
my @x = split(/\n/, $text); |
89
|
|
|
|
|
|
|
my $c = 0; |
90
|
|
|
|
|
|
|
return join("\n", map { sprintf("%-4d%s", $c++, $_) } @x); |
91
|
|
|
|
|
|
|
}; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# |
94
|
|
|
|
|
|
|
# |
95
|
|
|
|
|
|
|
# |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub TIEHASH |
98
|
|
|
|
|
|
|
{ |
99
|
19
|
|
|
19
|
|
39
|
my ($pkg, $func, @args) = @_; |
100
|
19
|
|
|
|
|
80
|
return bless [ |
101
|
|
|
|
|
|
|
$func, |
102
|
|
|
|
|
|
|
[@args], |
103
|
|
|
|
|
|
|
{}, |
104
|
|
|
|
|
|
|
]; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub FETCH |
108
|
|
|
|
|
|
|
{ |
109
|
33
|
|
|
33
|
|
22833
|
my ($self, $lookup) = @_; |
110
|
33
|
|
|
|
|
67
|
return &{$self->[0]}($lookup, $self->[2], @{$self->[1]}); |
|
33
|
|
|
|
|
81
|
|
|
33
|
|
|
|
|
62
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
0
|
|
|
sub STORE { $_[0]->[2]{$_[1]} = $_[2] } |
114
|
0
|
|
|
0
|
|
|
sub FIRSTKEY { my $a = scalar keys %{$_[0]->[2]}; each %{$_[0]->[2]} } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
115
|
0
|
|
|
0
|
|
|
sub NEXTKEY { each %{$_[0]->[2]} } |
|
0
|
|
|
|
|
|
|
116
|
0
|
|
|
0
|
|
|
sub EXISTS { exists $_[0]->[2]{$_[1]} } |
117
|
0
|
|
|
0
|
|
|
sub DELETE { delete $_[0]->[2]{$_[1]} } |
118
|
0
|
|
|
0
|
|
|
sub CLEAR { %{$_[0]->[2]} = () } |
|
0
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__END__ |