| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # VarSet.pm - Represents a set of variables and there values | ||||||||||||||||||||||||||||||||||||||||||
| 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::VarSet - Represents a set of variables and there values | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | require Math::Expr::VarSet; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | $s=new Math::Expr::VarSet; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | $s->Set('a', 7); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | $s->Get('a'); | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | Used to represent variables with values and substitutions. | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | package Math::Expr::VarSet; | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | =head2 $s=new Math::Expr::VarSet | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | Create a new VarSet object. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 149 | ▶ | sub new {bless {}, shift} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | =head2 $s->Set($var, $val) | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | Sets $var to $val. Returns 1 if the $var was already set to $val ore did | ||||||||||||||||||||||||||||||||||||||||||
| 53 | not have a value previously, otherwise 0. | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 95 | ▶ | sub Set { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Set: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 95 | my ($self, $var, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 95 | my $ok=1; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | # Parameter sanity checks | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 95 | ▶ | defined $var || warn "Bad param var: $var"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 95 | ▶ | $val->isa("Math::Expr::Opp") || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$val->isa("Math::Expr::Opp") or $val->isa("Math::Expr::Num") or $val->isa("Math::Expr::Var")
$val->isa("Math::Expr::Opp") or $val->isa("Math::Expr::Num")
MC/DC0%0/3
$val->isa("Math::Expr::Opp") or $val->isa("Math::Expr::Num") or $val->isa("Math::Expr::Var")
$val->isa("Math::Expr::Opp")
$val->isa("Math::Expr::Num")
$val->isa("Math::Expr::Var")
Truth table75%3/4
A or B or C
A= $val->isa("Math::Expr::Opp")B= $val->isa("Math::Expr::Num")C= $val->isa("Math::Expr::Var")
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | $val->isa("Math::Expr::Num") || | ||||||||||||||||||||||||||||||||||||||||||
| 65 | $val->isa("Math::Expr::Var") || warn "Bad param val: $val"; | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 95 | ▶ | if (defined $self->{'Vars'}{$var} && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->{"Vars"}{$var} and $self->{"Vars"}{$var}->tostr ne $val->tostr
MC/DC100%2/2
defined $self->{"Vars"}{$var} and $self->{"Vars"}{$var}->tostr ne $val->tostr
defined $self->{"Vars"}{$var}
$self->{"Vars"}{$var}->tostr ne $val->tostr
Truth table100%3/3
A and B
A= defined $self->{"Vars"}{$var}B= $self->{"Vars"}{$var}->tostr ne $val->tostr
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | $self->{'Vars'}{$var}->tostr ne $val->tostr) {$ok=0;} | |||||||||||||||||||||||||||||||||||||||||
| 69 | 95 | $self->{'Vars'}{$var}=$val; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 95 | $ok; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 133 | ▶ | sub Copy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Copy: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 133 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 133 | my $n=new Math::Expr::VarSet; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 133 | foreach (keys %{$self->{'Vars'}}) { | |||||||||||||||||||||||||||||||||||||||||
| 78 | 11 | $n->Set($_, $self->{'Vars'}{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 133 | $n; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | =head2 $s->Insert($set) | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | Inserts all variables from $set into this object | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub Insert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Insert: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my ($self, $set) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $ok=1; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | # Parameter sanity checks | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | $set->isa("Math::Expr::VarSet") || warn "Bad param set: $set\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | foreach (keys %{$set->{'Vars'}}) { | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if (defined $self->{'Vars'}{$_}) {$ok=0;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $self->{'Vars'}{$_}=$set->{'Vars'}{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $ok; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | =head2 $s->tostr | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | Returns a stringrepresentation of the set, usefull for debugging. | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 142 | ▶ | sub tostr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tostr: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 142 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 142 | my $str=""; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 142 | foreach (keys %{$self->{'Vars'}}) { | |||||||||||||||||||||||||||||||||||||||||
| 114 | 24 | $str .= $_ . "=" . $self->{'Vars'}{$_}->tostr . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 142 | $str; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | =head2 $s->Get($var) | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | Returns the value of $var. | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 73 | ▶ | sub Get { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 73 | my ($self, $var) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 73 | $self->{'Vars'}{$var}; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||