Catalyst
This is part gimmick and the code discussions won’t be deep but it should be fun for anyone interested and useful for newcomers to Catalyst and Perl hackers looking to blaze into wilder territories. I feel that the model part of the MVC is the crux of any application and has the most room to play and improve an application.
Your Controllers are half-done from the jump. If you’re doing straight HTTP and trying to be REST-ful, the dispatch mostly writes itself.
Your Views are somewhat similar. JSON or XML or nice bare XHTML. It’s neither that difficult nor that likely to be elaborate—well, CSS can be quite elaborate—unless yur doin’ it rong.
Your Models can handle more and remove the necessity of more logic trees from the app than you’d expect. To some degree this is just pushing the complexity around but it’s the right way, unquestionably2, to do it.
This list is subject to change but now I’ve at least committed to ten of them. Most will be a bit fluffy but the techniques can be used in any Catalyst application and it should give a decent range of things to try and ways to do them. These will get you thinking about models more as services and maybe get you to approach them more creatively.
Models we’ll tackle (subject to substitution)
Random quote.
Moon phase information.
Cover images via Amazon.com’s APA.
Random numbers and really truly random numbers.
Stock quotes (Catalyst::Model::Adaptor).
Log file model (Apache access log).
Page view counter (SQLite).
Graphical title elements.
TheSchwartz job queue.
Fixing legacy code by not fixing it.
In the final post I’ll include the sample code every article as a regular Perl distribution in a Catalyst app so you can run the examples without having to put them together in each article. Note that manually putting them together is the best way to get the knowledge under your belt. So play along if you can.
All examples proceed from the following set-up
I use emacs and that’s what’s on the command line examples. You can use any editor you like, of course.
Create your test application
shell# catalyst.pl MyApp
created "MyApp"
created "MyApp/script"
created "MyApp/lib"
created "MyApp/root"
created "MyApp/root/static"
created "MyApp/root/static/images"
created "MyApp/t"
created "MyApp/lib/MyApp"
created "MyApp/lib/MyApp/Model"
created "MyApp/lib/MyApp/View"
created "MyApp/lib/MyApp/Controller"
created "MyApp/myapp.conf"
created "MyApp/lib/MyApp.pm"
created "MyApp/lib/MyApp/Controller/Root.pm"
created "MyApp/README"
created "MyApp/Changes"
created "MyApp/t/01app.t"
created "MyApp/t/02pod.t"
created "MyApp/t/03podcoverage.t"
created "MyApp/root/static/images/catalyst_logo.png"
created "MyApp/root/static/images/btn_120x50_built.png"
created "MyApp/root/static/images/btn_120x50_built_shadow.png"
created "MyApp/root/static/images/btn_120x50_powered.png"
created "MyApp/root/static/images/btn_120x50_powered_shadow.png"
created "MyApp/root/static/images/btn_88x31_built.png"
created "MyApp/root/static/images/btn_88x31_built_shadow.png"
created "MyApp/root/static/images/btn_88x31_powered.png"
created "MyApp/root/static/images/btn_88x31_powered_shadow.png"
created "MyApp/root/favicon.ico"
created "MyApp/Makefile.PL"
created "MyApp/script/myapp_cgi.pl"
created "MyApp/script/myapp_fastcgi.pl"
created "MyApp/script/myapp_server.pl"
created "MyApp/script/myapp_test.pl"
created "MyApp/script/myapp_create.pl"
Make a few local modifications
Then you can run your test server with the following command and it should nicely restart whenever you make changes–
./script/myapp_server.pl -d -r -p 3000
The -r flag is for “restart.” It’s one of the best things about Catalyst development if you didn’t already know. You can develop and see changes instantly (well, as fast as the server can restart) and without having to do anything yourself. Take that, compiled languages. Note, port 3000 is the default. It’s included FYI and so you can tweak without looking it up.
Check :
http://jp8000.shellmix.com:3000/


Tutorials 