| blib/lib/Math/SymbolicX/Calculator/Interface/Web/Server.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 12 | 25 | 48.0 |
| branch | 0 | 2 | 0.0 |
| condition | n/a | ||
| subroutine | 4 | 7 | 57.1 |
| pod | 1 | 3 | 33.3 |
| total | 17 | 37 | 45.9 |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package Math::SymbolicX::Calculator::Interface::Web::Server; | ||||||
| 2 | 1 | 1 | 2450 | use strict; | |||
| 1 | 3 | ||||||
| 1 | 46 | ||||||
| 3 | 1 | 1 | 18 | use warnings; | |||
| 1 | 2 | ||||||
| 1 | 41 | ||||||
| 4 | 1 | 1 | 7 | use base qw(HTTP::Server::Simple::CGI); | |||
| 1 | 2 | ||||||
| 1 | 1268 | ||||||
| 5 | 1 | 1 | 25145 | use CGI::Ajax; | |||
| 1 | 7454 | ||||||
| 1 | 14 | ||||||
| 6 | |||||||
| 7 | my $pjx = CGI::Ajax->new( 'process_new_input' => \&process_new_input ); | ||||||
| 8 | |||||||
| 9 | our $Calc = Math::SymbolicX::Calculator::Interface::Web->new(); | ||||||
| 10 | |||||||
| 11 | sub handle_request { | ||||||
| 12 | 0 | 0 | 1 | my ($self, $cgi) = @_; | |||
| 13 | 0 | my $html = $pjx->build_html( $cgi, \&Show_HTML ); | |||||
| 14 | 0 | $html =~ s/^[^\n]*\n//; # header?! | |||||
| 15 | 0 | print $html; | |||||
| 16 | #warn $html; | ||||||
| 17 | 0 | return($html); | |||||
| 18 | } | ||||||
| 19 | |||||||
| 20 | sub Show_HTML { | ||||||
| 21 | 0 | 0 | 0 | my $template = <<"HERE"; | |||
| 22 | |||||||
| 23 | |||||||
| 24 | |
||||||
| 25 | |||||||
| 50 | |||||||
| 51 | |||||||
| 142 | |||||||
| 143 | |||||||
| 144 | |||||||
| 145 | Enter [1]: | ||||||
| 146 | |||||||
| 147 | value="Evaluate" | ||||||
| 148 | type="submit" | ||||||
| 149 | onClick="process_new_input( ['new_input'], [apply_new_input] );" | ||||||
| 150 | /> | ||||||
| 151 | |||||||
| 152 | |||||||
| 153 | |||||||
| 154 | |||||||
| 155 | HERE | ||||||
| 156 | 0 | return $template; | |||||
| 157 | } | ||||||
| 158 | |||||||
| 159 | sub process_new_input { | ||||||
| 160 | 0 | 0 | 0 | my $input = shift; | |||
| 161 | |||||||
| 162 | 0 | my $output = $Calc->execute_expression($input); | |||||
| 163 | 0 | 0 | if ($output =~ /^ERROR:/) { | ||||
| 164 | 0 | warn $output; | |||||
| 165 | 0 | return('error', $output); | |||||
| 166 | } | ||||||
| 167 | |||||||
| 168 | 0 | return('new_input', $input, $output); | |||||
| 169 | } | ||||||
| 170 | |||||||
| 171 | 1; | ||||||
| 172 | __END__ |