=encoding utf8
=head1 NAME
Math::Symbolic::Variable - Variable in symbolic calculations
=head1 SYNOPSIS
use Math::Symbolic::Variable;
my $var1 = Math::Symbolic::Variable->new('name');
$var1->value(5);
my $var2 = Math::Symbolic::Variable->new('x', 2);
my $var3 =
Math::Symbolic::Variable->new(
{
name => 'variable',
value => 1,
}
);
=head1 DESCRIPTION
This class implements variables for Math::Symbolic trees.
The objects are overloaded in stringification context to
return their names.
=head2 EXPORT
None by default.
=cut
package Math::Symbolic::Variable;
use 5.006;
use strict;
use warnings;
use Math::Symbolic::ExportConstants qw/:all/;
use base 'Math::Symbolic::Base';
our $VERSION = '0.612';
=head1 METHODS
=head2 Constructor new
First argument is expected to be a hash reference of key-value
pairs which will be used as object attributes.
In particular, a variable is required to have a 'name'. Optional
arguments include a 'value', and a 'signature'. The value expected
for the signature key is a reference to an array of identifiers.
Special case: First argument is not a hash reference. In this
case, first argument is treated as variable name, second as value.
This special case disallows cloning of objects (when used as
object method).
Returns a Math::Symbolic::Variable.
=cut
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
if ( @_ == 1
and ref( $_[0] ) eq 'Math::Symbolic::Variable' )
{
return $_[0]->new();
}
elsif ( @_ and not ref( $_[0] ) eq 'HASH' ) {
my $name = shift;
my $value = shift;
return
bless { name => $name, value => $value, signature => [@_] } => $class;
}
my $self = {
value => undef,
name => undef,
signature => [],
( ref($proto) ? %$proto : () ),
((@_ and ref($_[0]) eq 'HASH') ? %{$_[0]} : ()),
};
bless $self => $class;
}
=head2 Method value
value() evaluates the Math::Symbolic tree to its numeric representation.
value() without arguments requires that every variable in the tree contains
a defined value attribute. Please note that this refers to every variable
I