luis.roca has asked for the wisdom of the Perl Monks concerning the following question:

*NOTE: I'm reposting this reply from the thread: CGI form help with buttons

“What other knowledge is assumed before using a Mojolicious or Dancer? I ask this as much for myself as for Steve. I know that these tools abstract a lot of what CGI, mod_perl or FCGI do but when I look at the tutorial listing there's honestly a few things... Ok more than a few things on there that I'm either not familiar with or don't know very well. What would be a good way to approach a Mojolicious assuming little to no previous experience building web applications?”

A Rough List of Prerequisites So Far:

Before I get (deservedly?) slammed for stating the painfully obvious, understand again that this is what one would suggest to a new Perl user who has little to no experience with web applications. (I'll go ahead and include myself in this group.) The questions get asked more and more here that are either:

That last one concerns me personally. In the referenced parent thread above, I suggested to Steve that he check out Melody (CGI::Application), CGI::FormBuilder and the CGI 101 Free chapters to get started. Those are mature peer reviewed resources that provide good, effective solutions — right? I know that I appreciate having lots of different options but there is definitely a 'New' vs 'Old' way to do it that sometimes (IMHO) teeters towards 'Correct' vs 'Wrong'.

What direction, without a 'One True Way' manifesto, do we give new Perl programmers looking to develop web applications?

Luis


* UPDATE (Same Day): Corrected the example defining (SoC) Separation of Concerns to include: (...presentation layer, business logic layer, data access layer, database layer) from the original (Data, Business Logic and Presentation.). The example is pulled from the Separation of concerns Wikipedia entry. Thanks to davido for the heads up.


"...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." — Don Quixote
  • Comment on CGI/Frameworks: What is a good entry point?

Replies are listed 'Best First'.
Re: CGI/Frameworks: What is a good entry point?
by zentara (Cardinal) on Jul 29, 2011 at 19:30 UTC
    If you are just starting out, I think it pays to generate some pages manually, just so you know what is involved. The easiest entry point into that, is to use use CGI qw(:standard), to just parse input, and here-docs ( print << EOHTML;) for manual html output. It teaches you about headers, and if you send out forms, it teaches basic logic. I know that is way simpler than what you are after.

    If you don't want to write code, but just manage content, the big thing around here now is Drupal , which is (gag!) Php. But I did see Googling for a Perl counterpart, Melody.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      HTML, CSS, TT, Formfu, DBIx::Class (or perl DBI)
Re: CGI/Frameworks: What is a good entry point?
by onelesd (Pilgrim) on Jul 30, 2011 at 08:41 UTC

    I highly recommend Dancer - it's winning. Dancer::Introduction and Dancer::Cookbook for more info. It's a minimalist framework that stays out of your way, which is what I prefer in a perl framework. I like to do things my way, and not be forced to change my coding habits too much. If you know any perl at all, and you have a solid understanding of HTTP you are golden.

    Use dbicdump to auto-generate all the boring code using your database schema.
    Use Dancer::Plugin::Database and DBIx::Class to get at your database (make sure to use all those modules you just auto-generated).
    Dancer::Plugin::DataFu for your view.

    Now add Plack and get access to all it's middlewares you might need. If you want TLS, look at tlsme.

Re: CGI/Frameworks: What is a good entry point?
by davido (Cardinal) on Jul 30, 2011 at 16:59 UTC

    You and I discussed this a little in the CB before you posted here. I mentioned I would think about it and try to come up with my own version of an answer. It took me a day, but here goes. As background, I recently read The Definitive Guide to Catalyst, and recently built a project around Mojolicious.

    I think it's important, despite frameworks not being CGI, for people to learn some basics about CGI first. It's just a good foundation even though it's an aging set of concepts. For CGI, my trusted source is the 2nd edition of the Mouse book, CGI Programming with Perl. It's very old; a lot has changed since then in web work, but it does a good job of introducing the issues that will confront web developers. And one thing I can say about the Mouse book (2nd ed.): you can trust it. So many of the other CGI related books of that era were script-kiddie rubbish.

    It's important to learn to use Perl's DBI. There is the O'Reilly book Programming the Perl DBI. It's also pretty old, but still relevant. It doesn't go into DBIx::Class, but does introduce Class::DBI. At any rate, developers are going to need to know how to use Perl's database API, and should learn basic SQL. At minimum, in the context of SQLite, but eventually PostgreSQL or MySQL. That can come with time.

    Unit testing and TDD concepts are very important in a web framework setting, because you're marrying components that don't know about each other. The model needs to be thoroughly tested. The view needs to be thoroughly tested, and the controller. This will give you confidence that all the pieces will fit together correctly and do what they should. In a web environment bugs can be harder to track down than elsewhere, and the penalty can be greater, so test driven development will help to squash them before you put all the pieces together into a big monolith that obscures where the problems are. Plus, TDD gives you the confidence of being able to make big code changes if necessary. If the tests pass, your changes didn't cause problems. If they fail, you still have work to do.

    Understanding templating, HTML, some JavaScript, and modern client-side or client-server interactions are important too. I know you recently finished the Template::Toolkit book from O'Reilly. I'm sure that has been helpful, although the framework I'm going to discuss later here uses its own templating system (with the option of overlaying anything you want, including TT2.)

    Finally, there's dealing with the frameworks themselves. Catalyst is a "big job" getting it all going, but is extremely flexible. To use it you will need a good grasp on Moose too. Mojolicious is a lot easier to get going, though you sacrifice some flexibility. That often is not a problem.

    Let's look at Mojolicious::Lite. Install Mojolicious using the docs; they're pretty easy to follow at that point. The Mojolicious people are proud of their simple, terse documentation. But sometimes its terseness forgets that people reading it for the first time haven't been through this before yet, and may need a little more help. (Yes, I know, patches are welcome.) Once you install it, open up the docs for Mojolicious::Lite. Create a directory somewhere in your home folder: ~/mojodev for example. cd into that folder and type 'mojo generate lite_app'. Inside that folder, find myapp.pl, and paste into it the first example from the Mojolicious::Lite docs. Then on the command line type: "./myapp.pl daemon" (must be executable).

    Now on port 3000 of localhost you will be running a Mojolicious test/development server which is running your little application. Test it out. Visit the URL http://localhost:3000/welcome. Now visit some other localhost URL and see what happens when the document can't be found. Now begin tinkering with myapp.pl. Add some get handlers, and try them out. Notice how your URL doesn't need to map to directories anymore like old fashioned CGI. Now it maps to actions that you define.

    Now you've learned the basics of playing with Mojolicious. The next step is to start building. Even within the context of a single-file (or file with helper modules) application facilitated by Mojolicious::Lite, you can still develop small models, controllers, and views, all in that one file. As your tinkering grows, they will be easy to migrate to a full Mojolicious application.

    Deployment will be the next issue after that. You'll have to decide upon a back end: PSGI/Plack, FastCGI, CGI, mod_perl, etc. Configure the server with its supporting plugins, set up the server to run Mojolicious applications, and then set up your Mojolicious application folders with webserver-available permissions. Deploy, and test. Start simple by layering onto old fashioned CGI (since you already read the mouse book by now). Then when performance becomes an issue look into other options.

    Update: I just realized that though I mentioned reading the Definitive Guide to Catalyst up at the top of the post, I really didn't mention anything about it later. The book starts out with a quick introduction to Moose, to building modules, and to test driven development before proceeding into Catalyst itself. While I am glad I read the book, I have to say that one thing I learned from it was that not every project needs a framework as big and as flexible as Catalyst. tye suggested to me a few months ago that I look into Mojolicious, and I'm glad because it saved me a lot of work. But the book did motivate me to dig deeper into testing, which is worth a lot to me.


    Dave

Re: CGI/Frameworks: What is a good entry point?
by metaperl (Curate) on Jul 30, 2011 at 00:37 UTC
Re: CGI/Frameworks: ... good entry point? (UPDATE)
by luis.roca (Deacon) on Aug 01, 2011 at 17:25 UTC

    Thank you to everyone who gave great advice here, in the CB and even via direct /msg. I very much hope this helps people looking to expand and/or update their knowledge in regards to the prerequisites for Perl's modern web frameworks. In the interest of sharing what I've discovered and learned in my self imposed homework assignment, here are a few articles that address some of the essential knowledge discussed in this thread (in addition to what has already been recommended):


    "...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." — Don Quixote
Re: CGI/Frameworks: What is a good entry point?
by Anonymous Monk on Jul 30, 2011 at 13:35 UTC
    Is this in "Meditations?" If not, it should be. It is easy, too easy, for folks who have already painfully learned something to forget how painful it is to learn it.
Re: CGI/Frameworks: What is a good entry point?
by Anonymous Monk on Jul 30, 2011 at 17:29 UTC
    Use aXML...
      lol