On Tue, 13 Mar 2007 02:46:01 +0100, Robert Hicks <suppressed> wrote:
Do you tend to make your module names generic like "Site" or "Webapp"? I am doing a couple small sites and I am creating secondary modules to hold things.I have something like: Site.pm Site::Actions.pm Site::Validators.pm Site::SQL.pm Is that good? Or would you replace "Site" with someting? Robert
I have several nested folders: Project::Runmodes::Whatever.pm Project::Runmodes::SecondOne.pmAnd I set the prefix (using CGI::Application::Dispatch) to Project::Runmodes. I also group everything related to "something" in one module - it makes it much
easier to find the code and handle auth(orization/entification). I also have some modules that are usually shared among projects - that is the way I customized CGI-App ...Project::Core::CGIApp.pm - and from my script I use it - not directly CGI::App.
So you end up with:
/index.cgi
/.htaccess - for mod_rewrite
/AutoDealer/ - and everything within it
/AutoDealer/
/Config/
/Runmodes/
/Templates/
/Core/
...
Here is the sample of how I group code:
package AutoDealer::Runmodes::Page;
use base 'AutoDealer::Core::App';
sub display : StartRunmode {
my $self = shift;
my $form = $self->form();
# Check if ./AutoDealer/Pages/page_name_here exists
# This way we limit to only templates from the /Pages/
# folder - yet they can include inside of them templates
# from /templates/ folder.
my $file_name = $form->{page};
if($file_name =~ /(.+)/){
$file_name = $1;
}
unless(-e './AutoDealer/Pages/' . $file_name) {
return $self->ERROR('Page not found!');
}
return $self->tt_process($file_name);
}
sub dealer_details : Runmode {
my $self = shift;
my $form = $self->form();
my $dbt = $self->param('dbt');
my $user_id = $form->{id};
my $dealer_data = $dbt->execute(
sql => 'SELECT us.*, de.* FROM users us LEFT JOIN dealers de
ON us.user_id = de.dealer_user_id
WHERE user_id = ?',
data => [$user_id],
method => 'fetchrow_hashref'
);
return $self->tt_process('Dealer/view_details.tmpl', $dealer_data);
}
sub listing_inquiry : Runmode {
my $self = shift;
my $form = $self->form();
my $dbt = $self->param('dbt');
my ($listing, $dealer);
if($form->{car_id}){
# Get listing data
$listing = $dbt->execute(
sql => 'SELECT * FROM cars WHERE car_id = ?',
data => [$form->{car_id}],
method => 'fetchrow_hashref'
);
unless($listing->{car_id} == $form->{car_id}){
# No car with that ID
return $self->INFO_PAGE(
'No listing found',
'Listing with specified id was not found in our database. Most likely
it has been deleted.'
);
}
# Get dealer data
$dealer = $dbt->execute(
sql => 'SELECT * FROM dealers WHERE dealer_id = ?',
data => [$listing->{car_user_id}],
method => 'fetchrow_hashref'
);
}
}
1;
--
Aleksandar Petrović
www.techcode.net
Web Design & Development
Phone +381.63.330.891
Skype techcode.net
Yahoo! IM johndoeyu
ICQ 75863829
MSN suppressed
AIM tchcode
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.