your solution is correct. Passing in the $kiosk object makes it accessible to the message handler routine
print "INSTANTIATING KIOSK ==============================\n"; my $kiosk = Kiosk->new($placard, $server, $debug_level); # start the server on port __ print "INSTANTIATING SERVER port $kiosk_port ========================= +=====\n"; my $server = MyWebServer->new($kiosk_port); $server->run(); $server->{kiosk} = $kiosk;
this part in HTTP::Server::Simple::CGI; sees it just fine and responds properly ... so THANK YOU.
sub handle_request { my $self = shift; my $cgi = shift; my $json_string = $cgi->param('POSTDATA'); # { "type":"cardCheck", "date":"1482307795601", "lang": "EN", +"machineName":"PLUSMAKM", "cardNumber":"1234567890", "PIN": "1234" } print "json_string=$json_string\n"; $json_dict = decode_json $json_string; print "json_dict=" . Dumper($json_dict) . "\n"; my $response = $self->{kiosk}->process($json_dict); print "response=$response\n"; return $response; }
there was one issue in fully implementing your solution (the code worked without it). When you add the "new" method to HTTP::Server::Simple::CGI;object as follows you get an execution error
sub new { my $self = {}; $self->{class} = $class; $self->{kiosk} = undef; bless($self,$class); return $self; }
Can't locate object method "run" via package "main" at http_server.pl line 56, <CONF> line 35. line 56 is
$server->run();
this was the original reason I requested help. Now that I see the code a bit more I guess the question is "how do you exend the HTTP::Server::Simple::CGI; object, but that is another topic. SO I thank you for an excelent easy solution and, if you have any ideas about the ast question, I would love to hear it so I can gain more knowledge about OO in Perl.
In reply to Re^2: Mass Class Confusion - Who calls what how?
by holandes777
in thread Mass Class Confusion - Who calls what how?
by holandes777
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |