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