Evan Carew has asked for the wisdom of the Perl Monks concerning the following question:

I'm converting an existing CGI style app from Apache/CGI to Starman/PSGI, and am running into trouble. The specific error I'm getting is:
Body should be an array ref or filehandle: <html>...
And my problem is that the ensuing stacktrace doesn't give me the problem starting point within my code. Does anyone have a pointer to a good debugger for plack? I've seen references for one of the REST (browser based) plugins. I'm just curious what people think is a good solution for apps that don't require a ton of setup. Thanks for pointing out an interesting feature of PLACK while requesting an example of my code. Below, please find the snippet from my code which isn't working:
#!/usr/bin/perl use strict; use Plack::Request; use Plack::Builder; use Plack::App::File; use HTML::Template; my $app = sub{ my $env = shift; my $html = get_html(); my $request = Plack::Request->new($env); if($request->param('file')){ $html = thankyou(); } return ['200', ['Content-Type'=>'text/html'],[$html]]; }; sub get_html{ # open the html template my $template = HTML::Template->new(filename => 'scriptup.html'); return $template->output(); } sub thankyou{ return <<HTML; <html><body>Thanks!</body></html> HTML }

Replies are listed 'Best First'.
Re: New Plack App (with HTML::Template & file upload) help
by Corion (Patriarch) on Jul 27, 2015 at 07:27 UTC

    You could help us help you better by posting the relevant part of your code. Most likely, you have in your request handler something like:

    sub handle_request { ... my $html = '<html><head>...</html>'; ... return [ 200, ['Content-Type','text/html'], $html] };

    But that is not how the PSGI protocol works. It wants you to return an array reference:

    sub handle_request { ... my $html = '<html><head>...</html>'; ... return [ 200, ['Content-Type','text/html'], [$html]] };
Re: New Plack App (with HTML::Template & file upload) help
by Anonymous Monk on Jul 27, 2015 at 00:03 UTC

    And my problem is that the ensuing stacktrace doesn't give me the problem starting point within my code. Does anyone have a pointer to a good debugger for plack?

    See https://metacpan.org/pod/PSGI#The-Response and Plack::Response

    PSGI is simple, but just like CGI, you have to know the absolute minimum of basics