File Coverage

blib/lib/Math/SymbolicX/Calculator/Command.pm
Criterion Covered Total %
statement 19 25 76.0
branch 1 4 25.0
condition 0 3 0.0
subroutine 6 7 85.7
pod 1 1 100.0
total 27 40 67.5


line stmt bran cond sub pod time code
1             package Math::SymbolicX::Calculator::Command;
2              
3 1     1   14 use 5.006;
  1         3  
  1         33  
4 1     1   5 use strict;
  1         2  
  1         24  
5 1     1   4 use warnings;
  1         2  
  1         29  
6 1     1   5 use Carp qw/croak/;
  1         1  
  1         58  
7              
8             our $VERSION = '0.02';
9              
10 1     1   4 use vars qw/@CMDS/;
  1         1  
  1         86  
11              
12             # load the command classes.
13             BEGIN {
14 1     1   3 @CMDS = qw(
15             Assignment
16             Transformation
17             DerivativeApplication
18             Insertion
19             );
20 1         2 foreach (@CMDS) {
21 4         219 eval "require Math::SymbolicX::Calculator::Command::$_;";
22 4 50       158 die "Could not load Math::SymbolicX::Calculator::Command::$_. Error: $@"
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 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 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 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 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
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 of the command to
129             create. All paramaters are passed thorugh to the constructed
130             of the implementing subclass. That means if C is C,
131             then C will call
132             Cnew()>
133             with its arguments.
134              
135             =cut
136              
137              
138             sub new {
139 0     0 1   my $proto = shift;
140 0   0       my $class = ref($proto)||$proto;
141              
142 0           my %args = @_;
143              
144 0 0         croak("Need 'type' argument to " . __PACKAGE__ . "->new()")
145             if not defined $args{type};
146 0           $class .= "::" . $args{type};
147 0           return $class->new(@_);
148             }
149              
150              
151             1;
152             __END__