Expr/Num.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 4 / 4 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 11 / 11 Podpod 16.6% 1 / 6 totaltotal 85.4% 53 / 62 CC 5 SCAR 8.5
CC
5
Cov
95%
SubMatch
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.3
« Expr/Node.pm ↑ Summary Expr/Var.pm »
1 #!/usr/bin/perl
2  
3 # Num.pm - A perl representation of numbers
4 # (c) Copyright 1998 Hakan Ardo <hakan@debian.org>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  
20 =head1 NAME
21  
22 Math::Expr::Num - Represents one number in a parsed expression tree
23  
24 =head1 SYNOPSIS
25  
26 require Math::Expr::Opp;
27 require Math::Expr::Var;
28 require Math::Expr::Num;
29
30 # To represent the expression "x+7":
31 $n=new Math::Expr::Opp("+");
32 $n->SetOpp(0,new Math::Expr::Var("x"));
33 $n->SetOpp(1,new Math::Expr::Num(7));
34 print $n->tostr . "\n";
35  
36 =head1 DESCRIPTION
37  
38 Used by the Math::Expr to represent numbers.
39  
40 =head1 METHODS
41  
42 =cut
43  
44 package Math::Expr::Num;
45 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 1 ▶use Math::Expr::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 1 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
49 1 @ISA = qw(Math::Expr::Node);
50  
51 =head2 $n=new Math::Expr::Num($num)
52  
53 Creates a new representation of the number $num.
54  
55 =cut
56  
57 20 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
58 20 my($class, $val) = @_;
59 20 my $self = bless { }, $class;
60  
61 20 $self->{'Val'}=$val;
62 20 $self;
63 }
64  
65 =head2 $n->tostr
66  
67 Returns the string representation of the number which in perl is
68 the same as the number itsefle
69  
70 =cut
71 296 ▶sub tostr {
Subroutine tostr: called CC=1 SCAR=0.0
Pod documented
72 296 my $self = shift;
73 296 $self->{'Val'};
74 }
75  
76 12 ▶sub toText {shift->tostr}
Subroutine toText: called CC=1 SCAR=0.0
Pod undocumented
77  
78 145 ▶sub strtype {
Subroutine strtype: called CC=1 SCAR=0.0
Pod undocumented
79 145 "Real";
80 }
81  
82 145 ▶sub BaseType {shift->strtype(@_)}
Subroutine BaseType: called CC=1 SCAR=0.0
Pod undocumented
83  
84 3 ▶sub _toMathML {
Subroutine _toMathML: called CC=1 SCAR=0.0
85 3 my $self = shift;
86 3 "<mn>".$self->{'Val'}."</mn>";
87 }
88  
89  
90 8 ▶sub SubMatch {
Subroutine SubMatch: called CC=5 SCAR=16.2
Pod undocumented
91 8 my ($self, $rule, $mset) = @_;
92  
93 8 ▶ if ($rule->isa('Math::Expr::Var') && $self->BaseType eq $rule->BaseType) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule->isa("Math::Expr::Var") and $self->BaseType eq $rule->BaseType) 4 4 8
Condition66%2/3
$rule->isa("Math::Expr::Var") and $self->BaseType eq $rule->BaseType
!ll&&!rl&&r
404
MC/DC50%1/2
$rule->isa("Math::Expr::Var") and $self->BaseType eq $rule->BaseType
$rule->isa("Math::Expr::Var") $self->BaseType eq $rule->BaseType
Truth table66%2/3
A and B
A= $rule->isa("Math::Expr::Var")B= $self->BaseType eq $rule->BaseType
ABresult
0X0
100
111
94 4 $mset->SetAll($rule->{'Val'},$self);
95 4 return 1;
96 }
97 4 ▶ if ($rule->isa('Math::Expr::Num') && $self->BaseType eq $rule->BaseType) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rule->isa("Math::Expr::Num") and $self->BaseType eq $rule->BaseType) 2 2 4
Condition66%2/3
$rule->isa("Math::Expr::Num") and $self->BaseType eq $rule->BaseType
!ll&&!rl&&r
202
MC/DC50%1/2
$rule->isa("Math::Expr::Num") and $self->BaseType eq $rule->BaseType
$rule->isa("Math::Expr::Num") $self->BaseType eq $rule->BaseType
Truth table66%2/3
A and B
A= $rule->isa("Math::Expr::Num")B= $self->BaseType eq $rule->BaseType
ABresult
0X0
100
111
98 2 return 1;
99 }
100 2 return 0;
101 }
102  
103 =head2 $n->Copy
104  
105 Returns a new copy of itself.
106  
107 =cut
108  
109 6 ▶sub _Copy {
Subroutine _Copy: called CC=1 SCAR=0.0
110 6 my $self= shift;
111  
112 6 new Math::Expr::Num($self->{'Val'});
113 }
114  
115  
116 =head1 AUTHOR
117  
118 Hakan Ardo <hakan@debian.org>
119  
120 =head1 SEE ALSO
121  
122 L<Math::Expr::Opp>
123  
124 =cut
125  
126 1 1;
« Expr/Node.pm ↑ Summary Expr/Var.pm »