Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

mod_perl website structure

by shiftee (Initiate)
on Oct 13, 2011 at 14:07 UTC ( #931249=perlquestion: print w/ replies, xml ) Need Help??
shiftee has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I am trying to use mod_perl to create a website. I have previously done projects using PHP & Servlets and have some experience using perl on the command line.

I am finding the documentation online to be quite technical and am having trouble answering some basic questions.

If 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)

It is my understanding that I should have a handler or script called when a page is requested. This handler should then call a run() or init() function in another file or package where they can still access the request object. Is this correct??

For authentication I want to check the credentials against a database, do the Apache authentication modules have anything to do with this??

Can I use Apache::Asp in conjunction with mod_perl to embed my code into the html files??

If anyone has the code for an example site it would be very much appreciated

Thanks

Mark

Comment on mod_perl website structure
Re: mod_perl website structure
by Anonymous Monk on Oct 13, 2011 at 14:40 UTC

      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

Re: mod_perl website structure
by wfsp (Abbot) on Oct 13, 2011 at 15:12 UTC
Re: mod_perl website structure
by shiftee (Initiate) on Oct 13, 2011 at 18:36 UTC
    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
Re: mod_perl website structure
by scorpio17 (Monsignor) on Oct 14, 2011 at 13:29 UTC

    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.

Re: mod_perl website structure
by shiftee (Initiate) on Oct 14, 2011 at 17:15 UTC
    Thanks guys!!
      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://931249]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2015-07-03 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (54 votes), past polls