Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

I want to professionalise my quick-and-dirty web app

by Cody Fendant (Friar)
on Apr 24, 2012 at 00:41 UTC ( #966706=perlquestion: print w/replies, xml ) Need Help??
Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:

I have a perl/MySQL website which is running well and suiting the client needs, but I'd be the first to admit, it's a bit rough. I'd be a bit embarrassed if one of you monks had to take it over from me, put it that way.

How it works is:

  • If a URL on the site exists as a static file, it's served as normal.
  • If not, Apache redirects to a single perl script.
  • That script splits the path and acts accordingly,
    • say the path is /chicago/south/drycleaners/j-smith-and-sons, that's the path to a specific business, so $mode = 'business' and the if($mode eq 'business'){ ... } block is invoked,
    • but if it's just /chicago/south/drycleaners/ that's a list of all businesses in a certain category so the if($mode eq 'category'){ ... } block runs, and so on.

Things I need to fix:

  • This single perl script is getting large and complex, so I should probably think about putting the different code sections into modules.
  • It would be better to use a framework, though not a very complicated one -- would Catalyst be overkill for something like this? Maybe CGI::App? Maybe just moving those big blocks into MyApp::BusinessMode and MyApp::CategoryMode modules would be enough?
  • More flexibility for the future when the client has new ideas.
  • Like I said above, just generally more professionally organised code so that whoever works with it in future, including me, it's more logical and modular.

By the way, there's only reading from the database and HTML display involved. No updates or inserts, no authentication/personalisation, just pulling data, putting it into HTML::Template and output to the browser.

Any suggestions very gratefully received.

Replies are listed 'Best First'.
Re: I want to professionalise my quick-and-dirty web app
by GrandFather (Sage) on Apr 24, 2012 at 06:43 UTC

    From your description so far it's not clear how categories map to the database. With a good mapping the code to resolve a path to a database row or set of rows should be fairly compact. Perhaps you could show us a small sample of the parsing and rendering code and tell us a little about how the database is structured?

    True laziness is hard work
Re: I want to professionalise my quick-and-dirty web app
by sundialsvc4 (Abbot) on Apr 24, 2012 at 13:22 UTC

    CGI::Application is a venerable piece of code that has had many followers ... too many to list here.   If you search for that module-name you’ll find some of those followers, paying homage to it.   The core responsibilities of parsing a URL-string, identifying a handler, possibly loading that handler and executing it are available in many routines ... Mojolicious, for example.

    My suggestion would simply be that you consider several of them:   without changing anything about your code, consider what the changes might be.   With a number-two pencil and a piece of paper, and with a wastebin nearby, start making sketches and to-do lists.

    When you do get ready to make changes, then it’s definitely time to first put the whole thing under version-control, e.g. with git.   (I suggest git because it requires virtually no setup and no server; of course, it’s free, and if it’s good enough for managing the Linux Kernel it’s good enough for you.)   You can introduce the code, make one “branch” from that which represents “what you’ve got now,” then from the same root-point make other “branches” which represent your various experimentations.   You can safely and reliably now switch between them at-will.   You can, if you will, “now afford to completely screw-up”   :-)   because, well, merely checkout another branch and (presto!) you didn’t screw-up at all.   You can take the code from that or any other starting-point (one branch), make explorations in a new branch or branches, and always be able to reliably get back to precisely that starting-point.

Re: I want to professionalise my quick-and-dirty web app
by Anonymous Monk on Apr 24, 2012 at 07:33 UTC
Re: I want to professionalise my quick-and-dirty web app
by scorpio17 (Abbot) on Apr 24, 2012 at 13:16 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://966706]
Approved by GrandFather
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2018-06-24 13:42 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.