| [reply] [Watch: Dir/Any] |
Thanks, I am in college and want to try using a new technology, I would also prefer using perl for other back-end work and export functions,
My requirements are a quite basic database front-end so there should be no real issue there.
I have put together a small site here but I was only guessing really at how it should be put together. The script figures out what to do by parsing the passed url. If I use cookies and server side incudes would the code be acceptable??
I have also thought about using Mason but I feel I should try doing a small site myself first.
Basically I have a feeling that I am wasting enormous amounts of time because I am am missing how the pages should go together. I am looking into server side includes at the moment, it looks promising
| [reply] [Watch: Dir/Any] |
| [reply] [Watch: Dir/Any] |
Okay, i've put together the framework of what I imagine a small perl website to be, basically I would like to know if I have done anything horrendously wrong yet
# file:Fyp/Main.pm ######################################
package Fyp::Main; #This file is linked to /fyp location
use strict;
use warnings;
use Apache2::RequestRec ();
use Apache2::Const -compile => qw(OK);
use Fyp::Index;
sub handler {
my $r = shift;
$r->content_type('text/html');
Fyp::Index::init();
return Apache2::Const::OK;
}
1;
# file: Fyp/Index.pm ####################################
# Mark O'Donovan 2011
package Fyp::Index;
use strict;
use warnings;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Const -compile => qw(OK);
use Fyp::Html;
use Fyp::Security;
sub init() {
#my $r = shift;
#$r->content_type('text/plain');
#print "mod_perl 2.0 rocks!\n";
Fyp::Html::printHeader();
Fyp::Security::checkLogin();
Fyp::Html::printFooter();
}
1;
# file: Fyp/Html.pm #####################################
# Mark O'Donovan 2011
package Fyp::Html;
use strict;
use warnings;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Const -compile => qw(OK);
sub printHeader() {
print << "END";
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w
+3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Carina - Web Interface</title>
+
<link rel="stylesheet" type="text/css" href="fyp.css" />
</head>
<body>
<h1>Welcome to Carina</h1>
END
}
sub printFooter() {
print << "END";
</body>
</html>
END
}
1;
# file: Fyp::Security.pm ################################
# Mark O'Donovan 2011
package Fyp::Security;
use strict;
use warnings;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Const -compile => qw(OK);
sub checkLogin() {
print "\t<p>You are not logged in</p>\n";
}
1;
Thanks very much for the info so far,
Mark | [reply] [Watch: Dir/Any] [d/l] [select] |
Nothing wrong really , but a common strategy is to seperate concerns, which you've done by using functions , but you could seperate them out a bit further, by means of model view controller pattern, which becomes more important the bigger your project becomes
More things to read (start with the pm links)
If your application isn't tied to a particular implementation (mod_perl), if you target PSGI/Plack, you can run on mod_perl or practically any webserver
| [reply] [Watch: Dir/Any] |
I would advise you to try using CGI::Application, and run it as plain CGI until all all the kinks are worked out. Then, consider "upgrading" to mod_perl - but only if you're getting so much traffic that the CGI version seems slow.
| [reply] [Watch: Dir/Any] |
I am reading Practical Mod Perl.
I want to use perl to generate the pages, do I need to tell httpd.conf to serve e.g. index.pl automatically instead of index.html OR should I set a handler for the location DocRoot?? (if i want to put dynamic content on the first page)
DirectoryIndex directive in httpd.conf will look up index.pl, index.html, or somthing you like. Your Fyp::Main have handler() function, so, you have to tell apache that when the http request come, apache should kick Fyp::Main::handler. httpd.conf for Fyp::Main will looks like this( from Practical Mod Perl p.254).
PerlModule Fyp::Main #load your module
<Location /test/Fyp>
SetHandler perl-script #invoke mod_perl to run the script
PerlHandler Apache::Registry #not Apache::PerlRun,but with Apache::R
+egistry
PerlHandler Fyp::Main #call hander() in Fyp:Main
</Location>
With this, Fyp::Main::handler will be called when you visit /test/Fyp.
For authentication I want to check the credentials against a database, do the Apache authentication modules have anything to do with this??
I noticed that this was my very concern when I began to read Practical Mod Perl. There seems a lot of things for mod_perl and now I am in Chapter 17 of this book, it began to talk about database at last. Appendix of this book seems to have authentication staff. And there seems to be a module like mod_auth_mysql and somthing.
I mean ... I'm in the way. As Anonymous Monk says, to understand web application frameworks, like Catalyst, Mojolicious , or O/R mapper like DBI::classX seems to have great importance nowadays. But anyway, Practical Mod Perl is very very interesting.
| [reply] [Watch: Dir/Any] [d/l] |