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