Mr. Mental has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I'm new to the site (cudo's btw!) and my problem (challenge) could fit in several sections. So I'd thought I'd put it here,

I developed a picview script: http://www.mrmental.com/cgi-bin/picview.pl
(If you look, check the "Beautiful Rotterdam" one)

It show pictures, thumbs and an event list. It's basically divided into three sections:

#### Overall Script Flow if ($parm{'event'} == -1) { # Build an eventlist event_list(); } elsif ($parm{'pic'} == -1) { # Or build a thumbs page thumbs_page(); } else { # Or show a picture picture_page(); } #### Outa here!
Full source: http://www.mrmental.com/picview.txt

To reduce the use of the visitor bandwidth there are three sizes per picture. The thumb, the preview and the full for download.

It runs in a CGI env. and I want to give it different use when ran from the CLI. When run from the CLI I want it to check for new directories and automatically create the different sizes. No problem here.

What I already ran into in the past is when to create sub's or not. Stuff that's needed more then once could go in a sub routine. But twice is also more then once.

There are the "print_head" and "print_tail" subs, which are fairly simple. On the other hand, it runs as a SSI (server side include) and as a page on its own and therefore it show different navigation icons for both situations. And these are not so easy to disect and put in a sub.

(A big thanx if you're still with me on this!)

I can see a delicate difference between ease of use and absolutely reducing al code the small building blocks.

However, I need you guru's to give me a pointer. So the burning question is:"How far should I take this urge to normalize everything?

Thanx a lot.

Kind regards,

Gerard.
~
~
:wq!

Replies are listed 'Best First'.
Re: Global program flow
by Tanktalus (Canon) on Feb 14, 2005 at 23:39 UTC

    First, thanks for using code tags. Or at least, I presume you did (I'm not a big enough hacker to figure out whether you used code or pre tags...). Lots of new users to the monastary seem to miss that. Minor nit: put your URL's in square brackets - they'll become links that way ;-)

    Now to your burning question (although I'm not sure I'm a guru yet): all the way. Check out CGI::Application ... although I've said in the past that I think it's severely lacking in certain ways, I will not allow an implication that it is anywhere near as bad as without it. It is a revolutionary step from where CGI programming was without it. That said, nothing is perfect, so you may eventually find that it is too limiting in some ways. But you'll be able to move on with a much stronger base knowledge about how to normalise your CGI applications.

Re: Global program flow
by dragonchild (Archbishop) on Feb 15, 2005 at 00:16 UTC
    You will want to take a look at building modules that will encapsulate your main functionality. Then, I would use Apache::ASP (CGI::Application is also good, but Apache::ASP is better for SSI) for the webside and a basic script on the CLI side. They both will use your module(s) that actually do the work. That way, you have the work done in one place and the interface in another. This is an application of MVC, aka Model View Controller.

    I know it's a ton of info, but you also have an open-ended question. :-)

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re: Global program flow
by Anonymous Monk on Feb 15, 2005 at 09:58 UTC
    That's a picture album, isn't? Why would you want to generate the pages on demand? Pictures tend to be quite static. Why not generate the entire album once, producing a static set of HTML pages? That would reduce the load on the server, give faster response times for the users, and greatly simplifies the code you have to write.
Re: Global program flow
by Mr. Mental (Initiate) on Feb 15, 2005 at 11:21 UTC
    Hi guys, First of all thanx for the feedback! Not to start different threads on all replies I'll just express my thoughts in this one. If I've missed one of your points, please tell me so.

    I had a quick look at Apache::ASP and CGI::Application, and turning the picview script into a module seems the way to go (for now anyway). Not to mention the sh*tload of challenges that come with it .. :-)

    Correct me if I'm wrong but the Apache::ASP looks like PHP, which I particularly do not use.
    Please enlighten me on why Apache::ASP is a good choice combined with SSI?

    Also the MVC provides a good piece of reading material and an intriguing view on things. I'm using a webengine developed by a friend of mine, that really fits the profile to be turned into a module as well, but first things first. This one had me going http://ootips.org/persistent-objects.html, and wil be read in the train to work. When am I ever gonna sleep again .. :-)

    One final note on why I didn't just created static HTML pages to all pictures. That's how the script was born in the first place. I'm very systematic and tidy (no to say obsessive). First time I found pictures and thumbs online there was a directory with 50 pics and a thumbs page that had fifty links to 50 pages all with one IMG tag to one picture. So at the time I thought that was to static (read: messy .. ;-)). So an intelligent script was the solution. What I want it to do eventually is monitor a directory for incoming pictures and have the script do the whole thumbs thing by itself. Practically: I have a cell phone with a camera; I take a picture; I send it to an email adress; After XX seconds you can view the picture online (with a thumbnail and description ofcourse).

    It's not an application that would improve the world, but I just thought it would be fun for people to see what I do when I'm on holiday for instance.

    That's it for now. Looking forward to your replies. Hope you can still find the questions up here somewhere.

    Kind Regards,

    Gerard.
    ~
    ~
    :wq!
      One final note on why I didn't just created static HTML pages to all pictures. That's how the script was born in the first place. I'm very systematic and tidy (no to say obsessive). First time I found pictures and thumbs online there was a directory with 50 pics and a thumbs page that had fifty links to 50 pages all with one IMG tag to one picture. So at the time I thought that was to static (read: messy .. ;-)). So an intelligent script was the solution. What I want it to do eventually is monitor a directory for incoming pictures and have the script do the whole thumbs thing by itself. Practically: I have a cell phone with a camera; I take a picture; I send it to an email adress; After XX seconds you can view the picture online (with a thumbnail and description ofcourse).
      Exactly. No need for CGI or another form of pages generated on viewer demand. You'd only generate new pages (and update any indexing/overview pages) whenever a new picture arrives. Seen from the server (and hence the viewer), that's static - the pages are there before the viewer requests them.
        Dear Anonymous Monk, I'm sorry but I'm missing your point. Are you saying to have a cyclic script just check and create html pages? Instead of the on demand script all together? Regards, Gerard.
        ~
        ~
        :wq!