| 1 | |||
| 2 | =encoding utf8 | ||
| 3 | |||
| 4 | =head1 NAME | ||
| 5 | |||
| 6 | Math::Symbolic::Custom::DefaultDumpers - Default Math::Symbolic output routines | ||
| 7 | |||
| 8 | =head1 SYNOPSIS | ||
| 9 | |||
| 10 | use Math::Symbolic qw/parse_from_string/; | ||
| 11 | $term = parse_from_string(...); | ||
| 12 | my ($sub, $leftover_trees) = $term->to_sub(); | ||
| 13 | |||
| 14 | =head1 DESCRIPTION | ||
| 15 | |||
| 16 | This is a class of default output routines for Math::Symbolic trees. Likewise, | ||
| 17 | Math::Symbolic::Custom::DefaultTests defines default tree testing | ||
| 18 | routines and Math::Symbolic::Custom::DefaultMods has default tree modification | ||
| 19 | methods. | ||
| 20 | For details on how the custom method delegation model works, please have | ||
| 21 | a look at the Math::Symbolic::Custom and Math::Symbolic::Custom::Base | ||
| 22 | classes. | ||
| 23 | |||
| 24 | =head2 EXPORT | ||
| 25 | |||
| 26 | Please see the docs for Math::Symbolic::Custom::Base for details, but | ||
| 27 | you should not try to use the standard Exporter semantics with this | ||
| 28 | class. | ||
| 29 | |||
| 30 | =head1 SUBROUTINES | ||
| 31 | |||
| 32 | =cut | ||
| 33 | |||
| 34 | package Math::Symbolic::Custom::DefaultDumpers; | ||
| 35 | |||
| 36 | 23 | ▶ | use 5.006; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 37 | 23 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 38 | 23 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 39 | 23 | ▶ | no warnings 'recursion'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 40 | |||
| 41 | 23 | our $VERSION = '0.613'; | |
| 42 | |||
| 43 | 23 | ▶ | use Math::Symbolic::Custom::Base; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 44 | 23 | ▶ | BEGIN { *import = \&Math::Symbolic::Custom::Base::aggregate_import } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 45 | |||
| 46 | 23 | ▶ | use Math::Symbolic::ExportConstants qw/:all/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 47 | |||
| 48 | 23 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 49 | |||
| 50 | # Class Data: Special variable required by Math::Symbolic::Custom | ||
| 51 | # importing/exporting functionality. | ||
| 52 | # All subroutines that are to be exported to the Math::Symbolic::Custom | ||
| 53 | # namespace should be listed here. | ||
| 54 | |||
| 55 | 23 | our $Aggregate_Export = [ | |
| 56 | qw/ | ||
| 57 | to_code | ||
| 58 | to_sub | ||
| 59 | / | ||
| 60 | ]; | ||
| 61 | |||
| 62 | =head2 to_string | ||
| 63 | |||
| 64 | The to_string method is currently implemented in the module core namespaces | ||
| 65 | and will be moved to Math::Symbolic::DefaultDumpers in a future release. | ||
| 66 | |||
| 67 | Takes one optional argument indicating whether the Math::Symbolic tree should | ||
| 68 | be transformed to a string using 'postfix' notation or using 'infix' notation. | ||
| 69 | Default is infix which is also more likely to be reparseable by the | ||
| 70 | Math::Symbolic parser. | ||
| 71 | |||
| 72 | =head2 to_code | ||
| 73 | |||
| 74 | This method is a wrapper around the compile_to_code class method in the | ||
| 75 | Math::Symbolic::Compiler module. Takes key/value pairs of variables and | ||
| 76 | integers as argument. The integers should starting at 0 and they determine | ||
| 77 | the order of the variables/parameters to the compiled code. | ||
| 78 | |||
| 79 | Returns the compiled code and a reference to an array of possible leftover | ||
| 80 | tree elements that could not be compiled. | ||
| 81 | |||
| 82 | Please refer to the Math::Symbolic::Compiler man page for details. | ||
| 83 | |||
| 84 | =cut | ||
| 85 | |||
| 86 | 7 | ▶ | sub to_code { |
|
Subroutine
to_code: called CC=1 SCAR=0.0
Pod
documented
| |||
| 87 | 7 | my $self = shift; | |
| 88 | 7 | my $args = [@_]; # \@_ would be evil. @_ is not a real Perl array | |
| 89 | 7 | return Math::Symbolic::Compiler->compile_to_code( $self, $args ); | |
| 90 | } | ||
| 91 | |||
| 92 | =head2 to_sub | ||
| 93 | |||
| 94 | This method is a wrapper around the compile_to_sub class method in the | ||
| 95 | Math::Symbolic::Compiler module. Takes key/value pairs of variables and | ||
| 96 | integers as argument. The integers should starting at 0 and they determine | ||
| 97 | the order of the variables/parameters to the compiled code. | ||
| 98 | |||
| 99 | Returns the compiled sub and a reference to an array of possible leftover | ||
| 100 | tree elements that could not be compiled. | ||
| 101 | |||
| 102 | Please refer to the Math::Symbolic::Compiler man page for details. | ||
| 103 | |||
| 104 | =cut | ||
| 105 | |||
| 106 | 7 | ▶ | sub to_sub { |
|
Subroutine
to_sub: called CC=1 SCAR=0.0
Pod
documented
| |||
| 107 | 7 | my $self = shift; | |
| 108 | 7 | my $args = [@_]; # \@_ would be evil. @_ is not a real Perl array | |
| 109 | 7 | return Math::Symbolic::Compiler->compile_to_sub( $self, $args ); | |
| 110 | } | ||
| 111 | |||
| 112 | 23 | 1; | |
| 113 | __END__ | ||