John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

I've asked this on the mason mailing list too, but it seems to be dead.

I read the article at http://www.perl.com/pub/a/2004/04/01/masongal.html and installed http://search.cpan.org/dist/faceplant, and figured out enough to get it almost working. But I still can't figure something out.

A URL like <http://bkcg.lamp4/gallery/June> gives a 404, "The requested URL /gallery/June was not found on this server." A URL like <http://bkcg.lamp4/gallery/June/_MG_2571.JPG.html> works as expected.

The real directory docroot/gallery contains files autohandler.mason, dhandler.mason, and index.html, and subdirectories css, images, js, and pictures. index.html is just inherit => 'dhandler.mason' in flags. Everything with a URL under gallery is really made up by this script.

Meanwhile, <http://bkcg.lamp4/gallery> itself does not work either, but <http://bkcg.lamp4/gallery/index.html> does. Note that automatically finding the index.html file works on other locations. This offers a work-around for the top-level gallery, anyway.

Presumably this worked for him! I'd like to better understand what the deal is with directories vs locations in a directory when handled by a higher-level in the URI's name. And I need to know what is still wrong here.

Here is my configuration:

        # site-wide setting
	<LocationMatch "(\.html|\.txt)$">
	    SetHandler perl-script
	    PerlHandler HTML::Mason::ApacheHandler
	</LocationMatch>

        # all URI's here, will include names for graphics files + query args.
	<Location /gallery/images>
	    SetHandler perl-script
	    PerlHandler HTML::Mason::ApacheHandler
	</Location>

        # keep private stuff from being explicitly fetched
	<LocationMatch "(\.mason|dhandler|autohandler)$">
	    SetHandler perl-script
	    PerlInitHandler Apache::Constants::NOT_FOUND
	</LocationMatch>

Replies are listed 'Best First'.
Re: Mason newbe question
by ForgotPasswordAgain (Vicar) on Jul 15, 2008 at 07:13 UTC

    Your config seems quite different than what I see in the article. Why are you using autohandler.mason, dhandler.mason, instead of autohandler and dhandler? It's as if you named your Perl scripts foo.Perl instead of foo.pl.

    I think you're missing the first part of the configuration in your article:

    PerlModule HTML::Mason::ApacheHandler <Location /gallery> SetHandler perl-script PerlHandler HTML::Mason::ApacheHandler </Location>
    Without that, how would Apache know that Mason is in charge of things under /gallery?

      I named the files with an extension so my text editor knows what "type" they are, and I'm used to files having extensions. And BTW, I do use ".perl" as an extension for perl programs.

      The /gallery location you cite causes big problems because all the .js and .css files get processed too! The download code is fancier than the article's version. So /gallery gets changed to (just) gallery/images and my cite-wide LocationMatch for .html files.

      The reason to handle all files in this subdirectory is because URI's will be generated for image file names with query strings, and that will pick up the real file from a different directory and resize it. I normally don't have Mason process .JPG files, and only want to turn that on in this special directory.

      So, if I change that back to /gallery, how do I exclude the gallery/css and other subdirectories?

      I can see in my own design I should learn this lesson and not mix up the virtual directories (gallery/Vacation/June/...) and its implementation file directories (gallery/js, gallery/css).

      —John

        Well, okay this is mostly Apache config not Perl:

        # By default, Mason handles everything <Directory /var/www-mason> SetHandler perl-script PerlHandler HTML::Mason::ApacheHandler Options Includes FollowSymLinks AllowOverride None Order allow,deny Allow from all # whatever else... </Directory> # But we don't want bare autohandler or dhandler served by Apache <LocationMatch "handler$"> SetHandler perl-script PerlInitHandler Apache::Constants::NOT_FOUND </LocationMatch> # Nor do we want Mason touching stylesheets, javascript, or images <Location /css> SetHandler default-handler </Location> <Location /js> SetHandler default-handler Options FollowSymLinks Indexes </Location> <Location /img> SetHandler default-handler </Location>

        And if there's some directory under Mason control that I want to switch to non-HTML, I can put this in an autohandler if for example I wanted to output JSON:

        <%init>; # get rid of crap from parent autohandler $m->clear_buffer(); # change content-type $r->content_type('application/json; charset=utf-8'); # call any dhandlers, etc. $m->call_next(); $m->flush_buffer(); # but don't go back to the parent autohandler $m->abort(); </%init>

        And well generally there are other tricks but it depends on what you're doing.

Re: Mason newbe question
by pjotrik (Friar) on Jul 15, 2008 at 07:48 UTC
    There's no location for the uri you're requesting, you'll have to add something like
    <Location /gallery> SetHandler perl-script PerlHandler What::Ever </Location>
    Note: watch out for trailing slashes. Already a few times I've created a location like /gallery/ and wondered why http://server/gallery doesn't work.
Re: Mason newbe question
by Anonymous Monk on Jul 15, 2008 at 07:45 UTC
    Maybe this
    Or try increasing apache LogLevel...
Re: Mason newbe question
by wade (Pilgrim) on Jul 15, 2008 at 15:26 UTC

    Okay, _huge_ digression, here... When I saw the "Mason newbe question" subject line, I was unaware of the mason mailing list. The first thing that popped into my mind was a line from a short-lived TV show called "Dead Like Me" in which a boss-like character says to his people, "Have a nice day. And by 'have a nice day', I mean 'don't f*** up'. And by 'f*** up', I mean 'Mason'."

    That quote puts this question in a whole other light...

    --
    Wade
      Like tottaly, I'm the reaper :p