Diagram2D/NumberPrinter.pm

filter: Statementstmt 11.5% 14 / 121 Branchbran 0.0% 0 / 48 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 36.3% 4 / 11 Podpod 0.0% 0 / 7 totaltotal 9.6% 18 / 187 CC 25 SCAR 43.6
CC
25
Cov
8%
write_number_string
156.0
add_number_string
90.0
new
6.0
CRAP 78.5
« Diagram2D/Axis.pm ↑ Summary Diagram2D/Polyline.pm »
1  
2 package LaTeX::PGF::Diagram2D::NumberPrinter;
3  
4 1 ▶use 5.000000;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our @ISA = qw();
11  
12 1 our $VERSION = '1.00';
13  
14 sub new
15 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
16 0 my $self = undef;
17 0 ▶ if($#_ < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 0) { } 0 0 0
18 0 croak "Usage: LaTeX::PGF::Diagram2D::NumberPrinter->new()";
19 } else {
20 0 my $class = shift;
21 0 $self = {
22 'd' => undef, # Data
23 'ds' => ',', # Decimal sign
24 };
25 0 bless($self, $class);
26 }
27 0 return $self;
28 }
29  
30  
31  
32 sub set_decimal_sign
33 0 ▶{
Subroutine set_decimal_sign: not called CC=2 SCAR=17.9
Pod undocumented
34 0 my $self = undef;
35 0 ▶ if($#_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 1) { } 0 0 0
36 0 croak "Usage: \$numberprinter->set_decimal_sign(character)";
37 } else {
38 0 $self = shift;
39 0 $self->{'ds'} = shift;
40 }
41 0 return $self;
42 }
43  
44  
45  
46 sub init
47 0 ▶{
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
48 0 my $self = undef;
49 0 ▶ if($#_ < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 0) { } 0 0 0
50 0 croak "Usage: \$numberprinter->init()";
51 } else {
52 0 $self = shift;
53 0 $self->{'d'} = {};
54 }
55 0 return $self;
56 }
57  
58  
59 sub add_number_string
60 0 ▶{
Subroutine add_number_string: not called CC=9 SCAR=45.0
Pod undocumented
61 0 my $self = undef;
62 0 ▶ if($#_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 1) { } 0 0 0
63 0 croak "Usage: \$numberprinter->add_number(value)";
64 } else {
65 0 $self = shift;
66 0 my $v = shift;
67 0 my $t = $v;
68 0 my $mantisse = undef;
69 0 my $exponent = 0;
70 0 ▶ if("$t" =~ /(.*)[Ee](.*)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ("$t" =~ /(.*)[Ee](.*)/o) { } 0 0 0
71 0 $mantisse = $1; $exponent = $2; $exponent = 0 + $exponent;
72 } else {
73 0 $mantisse = $t;
74 }
75 0 ▶ while($exponent % 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exponent % 3) 0 0 0
76 0 $mantisse = 10.0 * $mantisse; $exponent--;
77 }
78 0 ▶ while(abs($mantisse) >= 1000.0) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $mantisse >= 1000) 0 0 0
79 0 $mantisse = $mantisse / 1000.0; $exponent += 3;
80 }
81 0 $mantisse = sprintf("%g", $mantisse);
82 0 my $ci = index($mantisse, ".");
83 0 ▶ if($ci >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ci >= 0) 0 0 0
84 0 my $add = length($mantisse) - $ci - 1;
85 0 ▶ if($add > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add > 0) 0 0 0
86 0 my $d = $self->{'d'};
87 0 ▶ if(exists($d->{"$exponent"})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$d{"$exponent"}) { } 0 0 0
88 0 ▶ if($add > $d->{"$exponent"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add > $$d{"$exponent"}) 0 0 0
89 0 $d->{"$exponent"} = $add;
90 }
91 } else {
92 0 $d->{"$exponent"} = $add;
93 }
94 }
95 }
96 }
97 0 return $self;
98 }
99  
100  
101  
102 sub add_number
103 0 ▶{
Subroutine add_number: not called CC=2 SCAR=17.9
Pod undocumented
104 0 my $self = undef;
105 0 ▶ if($#_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 1) { } 0 0 0
106 0 croak "Usage: \$numberprinter->add_number(value)";
107 } else {
108 0 $self = shift;
109 0 my $v = shift;
110 0 $self->add_number_string( sprintf("%g", $v) );
111 }
112 0 return $self;
113 }
114  
115  
116  
117 # File handler
118 # Value to print
119  
120  
121  
122 sub write_number_string
123 0 ▶{
Subroutine write_number_string: not called CC=12 SCAR=50.5
Pod undocumented
124 0 my $self = undef;
125 0 ▶ if($#_ < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 2) { } 0 0 0
126 0 croak "Usage: \$numberprinter->write_number_string(filehandle, number)";
127 } else {
128 0 $self = shift;
129 0 my $fh = shift; # File handler
130 0 my $v = shift; # Value to print
131 0 my $mantisse = undef;
132 0 my $exponent = 0;
133 0 ▶ if("$v" =~ /(.*)[Ee](.*)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ("$v" =~ /(.*)[Ee](.*)/o) { } 0 0 0
134 0 $mantisse = $1; $exponent = $2; $exponent = 0 + $exponent;
135 } else {
136 0 $mantisse = $v;
137 }
138 0 ▶ while($exponent % 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exponent % 3) 0 0 0
139 0 $mantisse = 10.0 * $mantisse; $exponent--;
140 }
141 0 ▶ while(abs($mantisse) >= 1000.0) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $mantisse >= 1000) 0 0 0
142 0 $mantisse = $mantisse / 1000.0; $exponent += 3;
143 }
144 0 my $p1 = undef; my $p2 = undef;
145 0 ▶ if("$mantisse" =~ /(.*)\.(.*)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ("$mantisse" =~ /(.*)\.(.*)/o) { } 0 0 0
146 0 $p1 = $1; $p2 = $2;
147 } else {
148 0 $p1 = $mantisse;
149 }
150 0 print $fh "\\(";
151 0 print $fh "$p1";
152 0 ▶ if(defined($p2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p2) 0 0 0
153 0 print $fh "" . $self->{'ds'} . $p2;
154 }
155 0 my $d = $self->{'d'};
156 0 ▶ if(exists($d->{"$exponent"})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$d{"$exponent"}) 0 0 0
157 0 my $add = $d->{"$exponent"};
158 0 ▶ if(defined($p2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p2) { } 0 0 0
159 0 my $l = length($p2);
160 0 ▶ while($l++ < $add) { print $fh "0"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($l++ < $add) 0 0 0
161 } else {
162 0 print $fh $self->{'ds'};
163 0 ▶ while($add--) { print $fh "0"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($add--) 0 0 0
164 }
165 }
166 0 ▶ if($exponent != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exponent != 0) 0 0 0
167 0 print $fh "\\cdot{}{10}^{" . $exponent . "}";
168 }
169 0 print $fh "\\)";
170 }
171 0 return $self;
172 }
173  
174  
175  
176 sub write_number
177 0 ▶{
Subroutine write_number: not called CC=2 SCAR=17.9
Pod undocumented
178 0 my $self = undef;
179 0 ▶ if($#_ < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 2) { } 0 0 0
180 0 croak "Usage: \$numberprinter->write_number(filehandle, number)";
181 } else {
182 0 $self = shift;
183 0 my $fh = shift; # File handler
184 0 my $v = shift; # Value to print
185 0 $self->write_number_string( $fh, sprintf("%g", $v) );
186 }
187 0 return $self;
188 }
189  
190  
191  
192 1 1;
193 __END__
« Diagram2D/Axis.pm ↑ Summary Diagram2D/Polyline.pm »