in reply to Re^2: Tk vs browser-based applications
in thread Tk vs browser-based applications

I don't recommend distributing Apache for use in an end user desktop app, basically because it's overkill. The node I linked above describes a way to build the web server into your Perl program so that when the user runs it, the embedded web server starts and then the user's browser simply points to it. It's a pretty elegant solution in my view, which is why I used it in the app mentioned in my home node.

Replies are listed 'Best First'.
Re^4: Tk vs browser-based applications
by kiat (Vicar) on Jul 05, 2005 at 07:50 UTC
    Hm...I copy and pasted the code at GUI with HTTP::Daemon and then ran it by double-clicking on the script. The perl interpreter was started and all I could see was the Dos box with C:\perl\test\pizza.pl as the title.

    Am I missing something?

        I named the file pizza.pl. Where do I place it so that when I type http://localhost/pizza.pl, the server knows where to locate the file? With apache, I indicate the location of the files via the httpd.conf. Btw, the content of pizza.pl is as follows (from GUI with HTTP::Daemon):
        use strict; use HTTP::Daemon; use HTTP::Status; use CGI::Simple; sub res { HTTP::Response->new( RC_OK, OK => [ 'Content-Type' => 'text/html' ], shift ) } my %pages = ( index => sub { res qq[ <html><body> <h1>Pizza cost calculator</h1> <form method=post action=calc> Total cost: <input name=cost><br> Number of eaters: <input name=ppl><br> <input type=submit value=Submit> </form> </body></html> ]; }, calc => sub { my ($request) = @_; my $cgi = CGI::Simple->new( $request->content ); res sprintf q[ <html><body> <h1>Result</h1> Cost per eater: %.2f<br> <a href=index>Again!</a> </body></html> ], $cgi->param('cost') / $cgi->param('ppl'); }, ); my $daemon = HTTP::Daemon->new(LocalAddr => '127.0.0.1') or die; my $ppid = $$; if (my $pid = fork) { while (my $client = $daemon->accept) { while (my $request = $client->get_request) { my ($page) = $request->url->path =~ m[^/(\w+)$]; $page ||= 'index'; if (exists $pages{$page}) { $client->send_response( $pages{$page}->($request) ); } else { $client->send_error(RC_NOT_FOUND); } } $client->close; } } elsif (defined $pid) { my $url = $daemon->url; my @browsers = qw(firefox konqueror mozilla opera start); { @browsers or die "Couldn't start a browser."; my $b = shift @browsers; my $r = system("$b $url"); redo if $r; } } else { die "Couldn't fork!"; }