Expr/OpperationDB.pm

filter: Statementstmt 89.5% 43 / 48 Branchbran 92.8% 13 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 75.0% 6 / 8 Podpod 16.6% 1 / 6 totaltotal 81.4% 66 / 81 CC 13 SCAR 16.7
CC
13
Cov
89%
Load
9.0
InitDB
3.0
Find
3.0
CRAP 5.3
« Expr/Rule.pm ↑ Summary Expr/MatchSet.pm »
1 #!/usr/bin/perl
2  
3 # OpperationDB.pm - A db of basic opperands and there properties
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::OpperationDB - A db of basic opperands properties
23  
24 =head1 SYNOPSIS
25  
26 require Math::Expr::OpperationDB;
27 $db=new Math::Expr::OpperationDB($file);
28  
29 =head1 DESCRIPTION
30  
31 This is a database containing info about the different opperations
32 (eg +, -, *, ...). Each opperation is represented by a regexp
33 mathing a type specifikation. That way Real*Real wont be the same
34 opperation as Matrix*Matrix even though the same operation character
35 is used.
36  
37 The data stored for each operation is the return type of the
38 operation and whatever this operation is kommutativ or assosiative.
39  
40 Currently the data is hardcoded into the code, but that is about to
41 chnage.
42  
43 =head1 METHODS
44  
45 =cut
46  
47 package Math::Expr::OpperationDB;
48 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 1 ▶use Math::Expr;
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 =head2 $db=new Math::Expr::OpperationDB;
53  
54 Creates a new db.
55  
56 =cut
57  
58 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
59 1 my $self = bless {}, shift;
60  
61 1 $self->Load(shift);
62  
63 1 $self;
64 }
65  
66 1 ▶sub InitDB {
Subroutine InitDB: called CC=3 SCAR=11.0
Pod undocumented
67 1 my $self=shift;
68 1 my $a=$self->{'opps'};
69  
70 1 foreach (keys %{$a}) {
71 8 ▶ if ($a->{$_}->{'simp'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->{$_}{"simp"}) 2 6 8
72 2 $a->{$_}->{'simp'}=Parse($a->{$_}->{'simp'});
73 }
74 8 $a->{$_}{'TypeReg'}=qr/^$_$/;
75 }
76 }
77  
78 1 ▶sub Load {
Subroutine Load: called CC=9 SCAR=22.0
Pod undocumented
79 1 my ($self, $file) = @_;
80 1 my (%t, @o);
81  
82 1 open (F, "<$file");
83 1 ▶ while (<F>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline F)) 52 1 53
84 52 ▶ if (/^([^:]+)\s*:\s*(.*)$/) {$t{lc($1)}=$2;}
Branch: 1 branch
BranchTrueFalseTotal
if (/^([^:]+)\s*:\s*(.*)$/) 44 8 52
85 52 ▶ if (/^\s*$/ || eof F) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*$/ or eof F) 8 44 52
Condition66%2/3
/^\s*$/ or eof F
l!l&&r!l&&!r
8044
MC/DC50%1/2
/^\s*$/ or eof F
/^\s*$/ eof F
Truth table66%2/3
A or B
A= /^\s*$/B= eof F
ABresult
1X1
011
000
86 8 ▶ if ($t{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t{"type"}) 8 0 8
87 8 my $t=$t{'type'};
88 8 delete $t{'type'};
89  
90 8 ▶ if (defined $t{'prop'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t{"prop"}) 2 6 8
91 2 @o = split(/\s*,\s*/, $t{'prop'});
92 2 foreach (@o) {
93 4 $self->{'opps'}{$t}{lc($_)}=1;
94 }
95 2 delete $t{'prop'};
96 }
97  
98 8 foreach (keys %t) {
99 34 $self->{'opps'}{$t}{$_}=$t{$_};
100 34 delete $t{$_};
101 }
102 }
103 }
104 }
105 }
106  
107 =head2 $db->Find($t)
108  
109 Tries all the type regexps in the db on $t and if one matches that
110 post is returned.
111  
112 =cut
113  
114 585 ▶sub Find {
Subroutine Find: called CC=3 SCAR=11.0
Pod documented
115 585 my ($self, $str) = @_;
116 585 my $opp;
117  
118 585 foreach (values %{$self->{'opps'}}) {
119 3249 ▶ if ($str =~ $_->{'TypeReg'}) {$opp=$_; last;}
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /$_->{"TypeReg"}/) 455 2794 3249
120 }
121  
122 585 $opp;
123 }
124  
125 0 ▶sub Keys {
Subroutine Keys: not called CC=1 SCAR=6.9
Pod undocumented
126 0 my $self = shift;
127  
128 0 keys %{$self->{'opps'}};
129 }
130  
131 0 ▶sub Get {
Subroutine Get: not called CC=1 SCAR=6.9
Pod undocumented
132 0 my ($self, $a) = @_;
133  
134 0 $self->{'opps'}{$a};
135 }
136  
137 1 1;
« Expr/Rule.pm ↑ Summary Expr/MatchSet.pm »