Monks,

Small epiphany of the obvious today. I am implementing/building a Content Management System in mod_perl. One of the things I worked quite a while on was figuring out how to store files on the filesystem but still have them plug into the security system I have.

So, clever me, I used File::MMagic to figure out the mime types of uploaded files and then stored them on the filesytem, along with data about them in a mySQL DB.

Rather proud of myself, I thought "cool. All I have to do is get the mime-type from the DB, open and print the file and voila! It fits into my security system."

A few issues-

  1. I'm using CGI::Application, which requires you NEVER TO PRINT TO STDOUT. You return your header properties and HTML from a subroutine, which CGI::Application intercepts and prints to stdout. This means I had to read the entire file into a variable, set the mime-type, and then "return" it.
  2. Byte-serving (page-at-a-time downloading) of PDFs wouldn't be implemented. This bugged me, but wasn't killer (even though I have a vast amount of large PDFs that we're managing). I could always adapt a script made by adobe to fix this.

Everything was working beautifully- docs on the filesystem were secure, things were humming along.

I started testing- downloading large PDFs (some 4 meg +). It took a little while (no byteserving, you know) but this wasn't a huge issue. Still, something didn't feel quite right about this system.

Then I looked at my HTTPD processes. Some were over 50 meg in size! Oof! This was because I had to slurp the file in and return it, and I'm programming in a persistent mod_perl environment.

Needless to say, I ditched the above system and wrote a mod_perl handler (my first serious one) to take care of access control based on my security system. Now I have byte-serving, sanely-sized HTTPD processes, and a much better solution overall.

When looking at the project at it's start, my intial thought was to write a mod_perl handler or use something like Apache::AuthzDBI, but I dismissed these because I didn't feel comfortable enough in mod_perl using anything beyond Apache::Registry. This was wrong, very wrong. The amount of time I took writing and rewriting was much more than if I had figured out Apache:AuthzDBI.

So, the moral of the story? Use the fruit of OTHER people's labors. Figure out what modules there are that solve your problems and use them. Hand-roll as an academic exercise, or if you absolutely have to.

-Any sufficiently advanced technology is
indistinguishable from doubletalk.


In reply to Let the experts do their jobs, or, A Lesson Learned, or, the CPAN coulda saved by butt by Hero Zzyzzx

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.