Math-SymbolicX-Calculator-Interface-Web

 view release on metacpan or  search on metacpan

lib/Math/SymbolicX/Calculator/Interface/Web.pm  view on Meta::CPAN

# Matches identifiers
my $Ident = $Math::SymbolicX::Calculator::Identifier_Regex;

=head1 NAME

Math::SymbolicX::Calculator::Interface::Web - An AJAXy web interface to the calculator

=head1 SYNOPSIS

  # simplest form of usage:
  use Math::SymbolicX::Calculator::Interface::Web;
  my $interface = Math::SymbolicX::Calculator::Interface::Web->new();
  # But you probably want to use
  # Math::SymbolicX::Calculator::Interface::Web::Server instead!

=head1 DESCRIPTION

This module implements an AJAX-enabled web interface to the
Math::SymbolicX::Calculator.

B<This is alpha software!>

You probably want to look at the C<symbolic_calculator_web_server>
script or the L<Math::SymbolicX::Calculator::Interface::Web::Server>
module which come with this distribution instead!

=head1 METHODS

=cut


# defined or
sub _dor {
    foreach (@_) {
        return $_ if defined $_;
    }
    return(undef);
}


=head2 new

Returns a new web interface object.

Optional parameters: (default in parenthesis)

  calc => a Math::SymbolicX::Calculator object to use

=cut

sub new {
    my $proto = shift;
    my $class = ref($proto)||$proto;

    my %args = @_;

    my $self = {
        calc             => $args{calculator}
                            || Math::SymbolicX::Calculator->new(),
    };
    bless $self => $class;

    return $self;
}

=head2 execute_expression

Runs a single expression.

=cut

sub execute_expression {
    my $self = shift;

    my $expr = shift;
    my $out;
        
        my $cmd;
        # What type of command?
        if ($expr =~ /=~~?/) {
            $cmd = $self->_parse_transformation($expr);
        }
        elsif ($expr =~ /=/) {
            $cmd = $self->_parse_assignment($expr);
        }
        else {
            $cmd = $self->_parse_command($expr);
        }
    
        if (not defined $cmd) {
            return("ERROR: Invalid expression. Neither assignment, replacement, nor command.");
        }
        elsif (_INSTANCE($cmd, 'Math::SymbolicX::Calculator::Command')) {
            my @output = $self->calc->execute($cmd);
            $out .= $self->_generic_out(@output);
        }
        elsif (ref($cmd) eq 'ARRAY') {
            if ($cmd->[0] eq 'print') {
                $out .= $self->_generic_out(@{$cmd}[1..$#$cmd]);
            }
        }
        else {
    
        }


    return($out);
}

=head2 calc

Returns the Calculator object of this Web Interface.

=cut

sub calc {
    my $self = shift;
    return $self->{calc};
}

=head2 exit_hook

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.763 second using v1.00-cache-2.02-grep-82fe00e-cpan-dad7e4baca0 )