| 1 | package Math::SymbolicX::Calculator::Command; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use Carp qw/croak/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | our $VERSION = '0.02'; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | ▶ | use vars qw/@CMDS/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | # load the command classes. | ||||||||||||||||||||
| 13 | 1 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.1
| |||||||||||||||||||||
| 14 | 1 | @CMDS = qw( | |||||||||||||||||||
| 15 | Assignment | ||||||||||||||||||||
| 16 | Transformation | ||||||||||||||||||||
| 17 | DerivativeApplication | ||||||||||||||||||||
| 18 | Insertion | ||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||
| 20 | 1 | foreach (@CMDS) { | |||||||||||||||||||
| 21 | 4 | eval "require Math::SymbolicX::Calculator::Command::$_;"; | |||||||||||||||||||
| 22 | 4 | ▶ | die "Could not load Math::SymbolicX::Calculator::Command::$_. Error: $@" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | if $@; | ||||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | =encoding utf8 | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | =head1 NAME | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | Math::SymbolicX::Calculator::Command - Base class for Calculator commands | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | =head1 SYNOPSIS | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | use Math::SymbolicX::Calculator; | ||||||||||||||||||||
| 36 | my $calc = Math::SymbolicX::Calculator->new(); | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | # setup formula to be a Math::Symbolic tree or a transformation... | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | my $assignment = $calc->new_command( | ||||||||||||||||||||
| 41 | type => 'Assignment', symbol => 'foo', object => $formula, | ||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | $calc->execute($assignment); | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =head1 DESCRIPTION | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | This class is a base class for commands to the a | ||||||||||||||||||||
| 49 | L<Math::SymbolicX::Calculator> object. Various commands are implemented as | ||||||||||||||||||||
| 50 | subclasses. See below for a list of core Commands and their usage. | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | =head1 AVAILABLE COMMANDS | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =head2 Assignment | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | L<Math::SymbolicX::Calculator::Command::Assignment> is an assignment | ||||||||||||||||||||
| 57 | of a formula or transformation to a symbol table slot. | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | Parameters to the constructor: | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | symbol => the symbol name to assign to | ||||||||||||||||||||
| 62 | object => Math::Symbolic tree or | ||||||||||||||||||||
| 63 | Math::Symbolic::Custom::Transformation to assign | ||||||||||||||||||||
| 64 | to the symbol | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | Execution of this command returns the following list: | ||||||||||||||||||||
| 67 | C<$sym, '==', $func> where C<$sym> is the name of the modified symbol | ||||||||||||||||||||
| 68 | and C<$func> is its new value. | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =head2 Transformation | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | L<Math::SymbolicX::Calculator::Command::Transformation> is a transformation | ||||||||||||||||||||
| 73 | application to a formula stored in a symbol table slot. | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | Parameters to the constructor: | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | symbol => the name of the symbol to modify | ||||||||||||||||||||
| 78 | trafo => Math::Symbolic::Custom::Transformation object to apply | ||||||||||||||||||||
| 79 | shallow => boolean: Set this to true to apply shallowly or to | ||||||||||||||||||||
| 80 | false to apply recursively (default) | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | Execution of this command returns the following list: | ||||||||||||||||||||
| 83 | C<$sym, '==', $func> where C<$sym> is the name of the modified symbol | ||||||||||||||||||||
| 84 | and C<$func> is its new value. | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | =head2 Insertion | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | L<Math::SymbolicX::Calculator::Command::Insertion> is a replacement | ||||||||||||||||||||
| 89 | of all variables in a formula (in a symbol table slot) by what's found | ||||||||||||||||||||
| 90 | in the symbol table under the corresponding variable names. | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | Parameters to the constructor: | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | symbol => the name of the symbol to modify | ||||||||||||||||||||
| 95 | optional: | ||||||||||||||||||||
| 96 | what => the name of the variable to replace with its symbol | ||||||||||||||||||||
| 97 | table value or '*' for everything | ||||||||||||||||||||
| 98 | Defaults to everything. | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | Execution of this command returns the following list: | ||||||||||||||||||||
| 101 | C<$sym, '==', $func> where C<$sym> is the name of the modified symbol | ||||||||||||||||||||
| 102 | and C<$func> is its new value. | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | =head2 DerivativeApplication | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | L<Math::SymbolicX::Calculator::Command::DerivativeApplication> | ||||||||||||||||||||
| 107 | is the application of all derivatives in a function in a | ||||||||||||||||||||
| 108 | symbol table slot. | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | Parameters to the constructor: | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | symbol => the name of the symbol to modify | ||||||||||||||||||||
| 113 | optional: | ||||||||||||||||||||
| 114 | level => the number of nested derivatives to apply. | ||||||||||||||||||||
| 115 | Defaults to all/any (undef). | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | Execution of this command returns the following list: | ||||||||||||||||||||
| 118 | C<$sym, '==', $func> where C<$sym> is the name of the modified symbol | ||||||||||||||||||||
| 119 | and C<$func> is its new value. | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | =head1 METHODS | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =head2 new | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | Returns a new Command object. Takes named parameters. The only | ||||||||||||||||||||
| 128 | universally mandatory parameter is the C<type> of the command to | ||||||||||||||||||||
| 129 | create. All paramaters are passed thorugh to the constructed | ||||||||||||||||||||
| 130 | of the implementing subclass. That means if C<type> is C<Assignment>, | ||||||||||||||||||||
| 131 | then C<new> will call | ||||||||||||||||||||
| 132 | C<Math::SymbolicX::Calculator::Command::Assignment->new()> | ||||||||||||||||||||
| 133 | with its arguments. | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | =cut | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 139 | 0 | my $proto = shift; | |||||||||||||||||||
| 140 | 0 | ▶ | my $class = ref($proto)||$proto; | ||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 0 | my %args = @_; | |||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | croak("Need 'type' argument to " . __PACKAGE__ . "->new()") | ||||||||||||||||||||
| 145 | 0 | ▶ | if not defined $args{type}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 146 | 0 | $class .= "::" . $args{type}; | |||||||||||||||||||
| 147 | 0 | return $class->new(@_); | |||||||||||||||||||
| 148 | } | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | 1 | 1; | |||||||||||||||||||
| 152 | __END__ | ||||||||||||||||||||