Hello, monks. Finally, I was able to generate a web page using PSGI /Plack. However, I have noticed that my CSS failed to work properly. The css file was on my browser, but it was empty. It seems to me that there is a disconnect between PSGI and the document root (/Library/WebServer/Documents) where I currently keep my static files. Below is a snippet of the code that I used,

#!/usr/bin/perl use strict; use warnings; use diagnostics; use template; my $app = sub { my $html = get_html(); return [ 200, ['Content-Type' => 'text/html'], [$html], ]; }; sub get_html{ # open template file open(my $reader,'< :encoding(UTF-8)',"/library/webserver/documents +/html.html"); my $input; do{$input .= $_} while(<$reader>); # Initialize HTML template my $template = Template->new(); my $vars = {greeting => 'Howdy, Cowboy!',debt => '$1.50',sender => + 'John Wayne'}; my $html; $template->process(\$input,$vars,\$html) || die "Template process failed: ", $template->error(), "\n"; return $html; }

The filename of the above code has a .psgi extension and I ran it using the plackup command. I named my HTML template html.html:

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http:/ +/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xml:lang='en' xmlns='http://www.w3.org/1999/xhtml' lang='en-US' +> <head> <title>Loan Shark</title> <link rel='stylesheet' type='text/css' href='funky.css' media='' /> </head> <body> <p><span id='try'>[% GET greeting %]</span>, It has come to our attention that your account is in arrears to the sum of [% GET debt %]. Please settle your account before the end of the year or you will face + severe embarrassment. Yours truly, [% sender %]</p> </body> </html>

I used Plack::App::File hoping that my css file would be served properly but it didn't work.

#!/usr/bin/perl use strict; use warnings; use diagnostics; use Plack::App::File; my $app = Plack::App::File->new(root => "/Library/Webserver/Documents" +)->to_app;

After running Plack::App::File, I again checked the browser. The css file contained only a copy of the generated HTML. I tried using Plack::App::Directory and, similarly, yielded the same unsuccessful result. I'd greatly appreciate it if anyone could share an insight into this problem. Thank you.


In reply to CSS and PSGI by tiny_monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.