| 1 | # This code is part of Perl distribution Math-Formula version 0.18. | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # The POD got stripped from this file by OODoc version 3.03. | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # For contributors see file ChangeLog. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2023-2025 by Mark Overmeer. | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | #oodist: *** DO NOT USE THIS VERSION FOR PRODUCTION *** | ||||||||||||||||||||||||||||||||||||||||||
| 12 | #oodist: This file contains OODoc-style documentation which will get stripped | ||||||||||||||||||||||||||||||||||||||||||
| 13 | #oodist: during its release in the distribution. You can use this file for | ||||||||||||||||||||||||||||||||||||||||||
| 14 | #oodist: testing, however the code of this development version may be broken! | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | package Math::Formula::Context;{ | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 15 | our $VERSION = '0.18'; | |||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 15 | ▶ | use Log::Report 'math-formula'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 15 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 16 | ▶ | sub new(%) { my $class = shift; (bless {}, $class)->init({@_}) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | sub _default($$$$) | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 64 | ▶ | { my ($self, $name, $type, $value, $default) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default: called CC=6 SCAR=21.5
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 64 | ▶ | my $form | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | = ! $value ? $type->new(undef, $default) | ||||||||||||||||||||||||||||||||||||||||||
| 35 | : ! blessed $value ? ($value ? Math::Formula->new($name, $value) : undef) | ||||||||||||||||||||||||||||||||||||||||||
| 36 | : $value->isa('Math::Formula') ? $value | ||||||||||||||||||||||||||||||||||||||||||
| 37 | : $value->isa('Math::Formula::Type') ? $value | ||||||||||||||||||||||||||||||||||||||||||
| 38 | : error __x"unexpected value for '{name}' in #{context}", name => $name, context => $self->name; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | sub init($) | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 16 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 16 | ▶ | my $name = $args->{name} or error __x"context requires a name"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 16 | ▶ | my $node = blessed $name ? $name : MF::STRING->new(undef, $name); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 16 | $self->{MFC_name} = $node->value; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 16 | my $now; | |||||||||||||||||||||||||||||||||||||||||
| 48 | $self->{MFC_attrs} = { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | ctx_name => $node, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | ctx_version => $self->_default(version => 'MF::STRING', $args->{version}, "1.00"), | ||||||||||||||||||||||||||||||||||||||||||
| 51 | ctx_created => $self->_default(created => 'MF::DATETIME', $args->{created}, $now = DateTime->now), | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ctx_updated => $self->_default(updated => 'MF::DATETIME', $args->{updated}, $now //= DateTime->now), | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 16 | ▶ | ctx_mf_version => $self->_default(mf_version => 'MF::STRING', $args->{mf_version}, $Math::Formula::VERSION), | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$now //= "DateTime"->now
MC/DC0%0/2
$now //= "DateTime"->now
$now
"DateTime"->now
Truth table33%1/3
A //= B
A= $nowB= "DateTime"->now
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 16 | ▶ | $self->{MFC_lead} = $args->{lead_expressions} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"lead_expressions"} // ""
MC/DC100%1/1
$args->{"lead_expressions"} // ""
$args->{"lead_expressions"}
Truth table100%2/2
A
A= $args->{"lead_expressions"}
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 16 | $self->{MFC_forms} = { }; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 16 | $self->{MFC_frags} = { }; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 16 | ▶ | if(my $forms = $args->{formulas}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | ▶ | { $self->add(ref $forms eq 'ARRAY' ? @$forms : $forms); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 16 | $self->{MFC_claims} = { }; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 16 | $self->{MFC_capts} = [ ]; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 16 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # For save() | ||||||||||||||||||||||||||||||||||||||||||
| 69 | sub _index() | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_index: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | +{ attributes => $self->{MFC_attrs}, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | formulas => $self->{MFC_forms}, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | fragments => $self->{MFC_frags}, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 13 | ▶ | sub name { $_[0]->{MFC_name} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 20 | ▶ | sub lead_expressions { $_[0]->{MFC_lead} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lead_expressions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | sub attribute($) | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | ▶ | { my ($self, $name) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attribute: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | ▶ | my $def = $self->{MFC_attrs}{$name} or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | Math::Formula->new($name => $def); | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 91 | #XXX example with fragment | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | sub add(@) | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 41 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=10 SCAR=28.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 41 | ▶ | unless(ref $_[0]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 34 | { my $name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 34 | ▶ | return $name =~ s/^#// ? $self->addFragment($name, @_) : $self->addFormula($name, @_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 7 | foreach my $obj (@_) | |||||||||||||||||||||||||||||||||||||||||
| 101 | 9 | ▶ | { if(ref $obj eq 'HASH') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 7 | { $self->add($_, $obj->{$_}) for keys %$obj; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | ▶ | elsif(blessed $obj && $obj->isa('Math::Formula')) | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
builtin::blessed($obj) and $obj->isa("Math::Formula")
MC/DC0%0/2
builtin::blessed($obj) and $obj->isa("Math::Formula")
builtin::blessed($obj)
$obj->isa("Math::Formula")
Truth table33%1/3
A and B
A= builtin::blessed($obj)B= $obj->isa("Math::Formula")
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 2 | { $self->{MFC_forms}{$obj->name} = $obj; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | ▶ | elsif(blessed $obj && $obj->isa('Math::Formula::Context')) | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
builtin::blessed($obj) and $obj->isa("Math::Formula::Context")
MC/DC0%0/2
builtin::blessed($obj) and $obj->isa("Math::Formula::Context")
builtin::blessed($obj)
$obj->isa("Math::Formula::Context")
Truth table0%0/3
A and B
A= builtin::blessed($obj)B= $obj->isa("Math::Formula::Context")
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | { $self->{MFC_frags}{$obj->name} = $obj; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | else | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | { panic __x"formula add '{what}' not understood", what => $obj; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 7 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | sub addFormula(@) | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 45 | ▶ | { my ($self, $name) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addFormula: called CC=19 SCAR=30.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 45 | my $next = $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 45 | my $forms = $self->{MFC_forms}; | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 45 | ▶ | if(ref $name) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | { return $forms->{$name->name} = $name | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not @_ and builtin::blessed($name) and $name->isa("Math::Formula")
not @_ and builtin::blessed($name)
MC/DC0%0/3
not @_ and builtin::blessed($name) and $name->isa("Math::Formula")
not @_
builtin::blessed($name)
$name->isa("Math::Formula")
Truth table25%1/4
not(A) and B and C
A= not @_B= builtin::blessed($name)C= $name->isa("Math::Formula")
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | if !@_ && blessed $name && $name->isa('Math::Formula'); | ||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | ▶ | elsif(! ref $name && @_) | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
not ref $name and @_
MC/DC0%0/2
not ref $name and @_
not ref $name
@_
Truth table33%1/3
not(A) and B
A= not ref $nameB= @_
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 44 | ▶ | { return $forms->{$name} = $next | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@_ == 1 and builtin::blessed($next) and $next->isa("Math::Formula")
@_ == 1 and builtin::blessed($next)
MC/DC100%3/3
@_ == 1 and builtin::blessed($next) and $next->isa("Math::Formula")
@_ == 1
builtin::blessed($next)
$next->isa("Math::Formula")
Truth table100%4/4
A and B and C
A= @_ == 1B= builtin::blessed($next)C= $next->isa("Math::Formula")
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | if @_==1 && blessed $next && $next->isa('Math::Formula'); | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 39 | ▶ | return $forms->{$name} = Math::Formula->new($name, @_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | if ref $next eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 38 | ▶ | return $forms->{$name} = Math::Formula->new($name, @_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($next) and $next->isa("Math::Formula::Type")
MC/DC50%1/2
builtin::blessed($next) and $next->isa("Math::Formula::Type")
builtin::blessed($next)
$next->isa("Math::Formula::Type")
Truth table66%2/3
A and B
A= builtin::blessed($next)B= $next->isa("Math::Formula::Type")
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | if blessed $next && $next->isa('Math::Formula::Type'); | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 25 | ▶ | my ($data, %attrs) = @_==1 && ref $next eq 'ARRAY' ? @$next : $next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ == 1 and ref $next eq "ARRAY"
MC/DC100%2/2
@_ == 1 and ref $next eq "ARRAY"
@_ == 1
ref $next eq "ARRAY"
Truth table100%3/3
A and B
A= @_ == 1B= ref $next eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 25 | ▶ | if(my $r = $attrs{returns}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 5 | ▶ | { my $typed = $r->isa('MF::STRING') ? $r->new(undef, $data) : $data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 5 | return $forms->{$name} = Math::Formula->new($name, $typed, %attrs); | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 20 | ▶ | if(length(my $leader = $self->lead_expressions)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 3 | ▶ | { my $typed = $data =~ s/^\Q$leader// ? $data : \$data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 3 | return $forms->{$name} = Math::Formula->new($name, $typed, %attrs); | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 17 | return $forms->{$name} = Math::Formula->new($name, $data, %attrs); | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | error __x"formula declaration '{name}' not understood", name => $name; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 55 | ▶ | sub formula($) { $_[0]->{MFC_forms}{$_[1]} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
formula: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | sub addFragment($;$) | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addFragment: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | ▶ | my ($name, $fragment) = @_==2 ? @_ : ($_[0]->name, $_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | $self->{MFC_frags}{$name} = MF::FRAGMENT->new($name, $fragment); | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 7 | ▶ | sub fragment($) { $_[0]->{MFC_frags}{$_[1]} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fragment: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | sub evaluate($$%) | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 32 | ▶ | { my ($self, $name) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | # Wow, I am impressed! Caused by prefix(#,.) -> infix | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 32 | ▶ | length $name or return $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 32 | ▶ | my $form = $name =~ /^ctx_/ ? $self->attribute($name) : $self->formula($name); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 32 | ▶ | unless($form) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | { warning __x"no formula '{name}' in {context}", name => $name, context => $self->name; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 32 | my $claims = $self->{MFC_claims}; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 32 | ▶ | ! $claims->{$name}++ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | or error __x"recursion in expression '{name}' at {context}", name => $name, context => $self->name; | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 32 | my $result = $form->evaluate($self, @_); | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 32 | delete $claims->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 32 | $result; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | sub run($%) | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 21 | ▶ | { my ($self, $expr, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 21 | ▶ | my $name = delete $args{name} || join '#', (caller)[1,2]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $args{'name'} || join('#', (caller)[1, 2])
MC/DC0%0/2
delete $args{'name'} || join('#', (caller)[1, 2])
delete $args{'name'}
join('#', (caller)[1, 2])
Truth table33%1/3
A || B
A= delete $args{'name'}B= join('#', (caller)[1, 2])
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 21 | my $result = Math::Formula->new($name, $expr)->evaluate($self, %args); | |||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 21 | ▶ | while($result && $result->isa('MF::NAME')) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$result and $result->isa("MF::NAME")
MC/DC50%1/2
$result and $result->isa("MF::NAME")
$result
$result->isa("MF::NAME")
Truth table66%2/3
A and B
A= $resultB= $result->isa("MF::NAME")
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 6 | { $result = $self->evaluate($result->token, %args); | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 21 | $result; | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | sub value($@) | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 12 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 12 | my $result = $self->run(@_); | |||||||||||||||||||||||||||||||||||||||||
| 209 | 12 | ▶ | $result ? $result->value : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 10 | ▶ | sub setCaptures($) { $_[0]{MFC_capts} = $_[1] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setCaptures: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 7 | ▶ | sub _captures() { $_[0]{MFC_capts} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_captures: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 4 | ▶ | sub capture($) { $_[0]->_captures->[$_[1]] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capture: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 15 | 1; | |||||||||||||||||||||||||||||||||||||||||