This is an example “way of doing things” with CGI::Application. It can’t claim to be ‘best practice’ since there are some better sites out there that happen to do things differently. It’s mainly as a reminder to myself and collaborators of how things should hang together, but if you’re starting out with CGI::Application you could do a lot worse than to copy these suggestions; your aims and requirements will be at least a bit different, but it should be easy to extend or take these notes on a different tack.

Directory Layout

These would usually be under /srv/<app>

bin
Batch scripts (executed by sysadmin)
cfg
Configuration files. eg cfg/app.cnf
cgi
Apache-invoked files for where we can’t configure apache. eg cgi/app.cgi
data
Initialisation or run-time data that is kept in files
doc
Documentation for everything. eg doc/man/man3/Cari::Mysql.3pm.gz
lib
Third-party (upstream) modules. eg lib/Cari/Mysql.pm
log
Log files. eg log/app_err.log
mod/C
Application controller modules. egs mod/C/Mod1.pm, mod/C/Mod1/Submod1.pm
mod/M
Application model modules. eg mod/M/User.pm
mod/V
Application view modules. eg mod/V/Dropdown.pm
test
Test scripts
tmpl
Template files. eg tmpl/mod1/rm1.html
www
Static web-accessible files. eg www/favicon.ico
www/css
Style sheets. eg www/css/app.css
www/img
Icons and images. eg www/img/mod1/banner.jpg
www/js
Javascript. eg www/js/jquery-1.4.2.min.js
Advertisements

There is of course loads of chat about MVC and how to leverage it into web app design. I like the counter-point given by Andy Wordley here:

In fact, there are plenty of other design patterns that are equally, or
more relevant to web applications and to writing good, solid code that
clearly separates concerns. For example, the Chain of Responsibility
(to implement a pipeline processing model), Mediator/Facade (to abstract
internals behind clean interfaces to ease SOC), Strategy (to define
a general strategy for all web applications that can be specialised
for different requests), Abstract Factory and Factory Methods (to
allow different implementations to be switched in/out) and so on.