Tie/Function/Examples.pm

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