blib/lib/Math/Matlab/Server.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 61 CC 6 SCAR 31.7
CC
6
Cov
0%
handler
42.0
BEGIN
2.0
BEGIN
2.0
CRAP 23.8
1 package Math::Matlab::Server;
2  
3 use strict;
4 use vars qw($VERSION $CONFIG);
5  
6 BEGIN {
7 $VERSION = sprintf "%d.%03d", q$Revision: 1.5 $ =~ /: (\d+)\.(\d+)/;
8 }
9  
10 use Apache::Constants qw(:common);
11 use Apache::Request;
12  
13 ##----- Public Class Methods -----
14 sub handler {
15 my $r = Apache::Request->instance(shift);
16 my $code = $r->param('CODE');
17  
18 if ($code) {
19 my $rel_mwd = join( '/', $r->path_info, $r->param('REL_MWD'));
20 $rel_mwd =~ s:^\/::; ## strip leading slash
21 $rel_mwd =~ s:\/$::; ## strip trailing slashes
22 $rel_mwd =~ s:\/\/\/*:\/:; ## strip multiple slashes
23 $r->content_type('text/plain');
24 $r->send_http_header;
25 return OK if $r->header_only;
26  
27 my $matlab;
28 eval {
29 my $class = $CONFIG->{class} or die '$' . __PACKAGE__ . '::CONFIG not defined.';
30 $matlab = $class->new( $CONFIG->{args} );
31 $matlab->execute($code, $rel_mwd) || die "Execute returned false.";
32 };
33 if ($@) {
34 $r->print( $@ );
35 } else {
36 $r->print( $r->param('RAW_OUTPUT') ? $matlab->fetch_raw_result : $matlab->fetch_result );
37 }
38 # $r->print( "\n==========================\n" .
39 # "MWD: '" . $matlab->root_mwd . "\n" .
40 # "PATH_INFO: '" . $r->path_info . "'\n" .
41 # "REL_MWD: '" . $r->param('REL_MWD') . "'\n" .
42 # "\$rel_mwd: '" . $rel_mwd . "'\n" .
43 # "==========================\n" );
44 } else {
45 $r->content_type('text/html');
46 $r->send_http_header;
47 return OK if $r->header_only;
48 $r->print(<<END_OF_PAGE);
49 <HTML>
50 <HEADER>
51 <TITLE>Math::Matlab::Server</TITLE>
52 </HEADER>
53 <BODY BGCOLOR="white">
54 <H2>Math::Matlab::Server</H2>
55  
56 <HR>
57  
58 <FORM METHOD="POST">
59 <TABLE>
60 <TR>
61 <TD>Relative Matlab Working Directory: <INPUT TYPE="text" NAME="REL_MWD" SIZE="16" MAXLENGTH="64"></TD>
62 <TD><INPUT TYPE="checkbox" NAME="RAW_OUTPUT" VALUE="1"> Raw Output</TD>
63 </TR>
64 <TR>
65 <TD COLSPAN="2">
66 Matlab code:<BR>
67 <TEXTAREA NAME="CODE" ROWS="30" COLS="70">fprintf('Hello world!\\n');
68 </TEXTAREA>
69 </TD>
70 </TR>
71 <TR>
72 <TD COLSPAN="2" ALIGN="CENTER"><INPUT TYPE="submit" VALUE="Execute"></TD>
73 </TR>
74 </TABLE>
75 </FORM>
76  
77 </BODY>
78 </HTML>
79 END_OF_PAGE
80  
81 }
82  
83 return OK;
84 }
85  
86 1;
87 __END__