Title: Catalyst Web Framework
1Catalyst Web Framework
Georgi Penkov
Bulgarian Association of Software Developers
www.devbg.org
2Introducing Catalyst
- What is a MVC?
- Acronym for Model-View-Controller. MVC was first
widely defined in the book "Design Patterns" by
Erich Gamma et al. It defines a separation of
concerns in a program where the model defines the
internal data structures of the program, the view
defines how the model is rendered to the user,
and the controller performs the actual actions in
the program that affect the model. - Catalyst - The Elegant MVC Web Framework
- Elegant
- "Combining simplicity power, and a certain
ineffable grace of design."
3(MVC) Model-View-Controller
- MVC object-oriented pattern for separating the
various concerns of an application - accepting and processing input,
- processing information,
- and displaying information.
- The Model object handles the connection to the
backing store (usually a database)? - ! Model does not do any web stuff !
- The View handles presenting information to the
user. - ! The business logic is not in the View object !
- The Controller handles request processing,
including authentication and access control. - Separate web stuff and other components reusable
in cron jobs etc
4Basic Architecture
5Philosophy
- Catalyst is based on a
- "Don't Repeat Yourself" (DRY) principle
- Definitions should only have to be made once.
-
- Automatic class loading
- Automatic Everything Everywhere!
- Manual approach is always an option
- Guiding principle of Catalyst is flexibility
- Promotes the re-use of existing Perl modules
- Has a large selection of Plug-ins
6Simplicity
- Example Installation
- cpan Catalyst
- catalyst.pl MyApp
- cd MyApp
- script/myapp_server.pl
- Simplicity - Catalyst is just a framework
- ! No built-in model !
- ! No built-in view !
7Easy environment setup
- Helpers will get you directly in the development
script/myapp_create.pl controller Foo created
"lib/MyApp/Controller/Foo.pmcreated
"t/Controller/Foo.t"
- Handy installation bundle with everything you
neeed for a successful start
cpan BundleCatalyst script/myapp_create.pl
view TT TT (Template Toolkit)
script/myapp_create.pl model DBIC DBIC
(DBIxClass)?
8Models
- Models regulate the access to the database.
- Based on popular CPAN Modules
- ClassDBI
- The classic OOP database ltgt class projector
- Works with all industry databases
- Extensively tested
- DBIxClass
- Newer
- Faster
- Cleaner
9CatalystModelDBICSchema
- Uses DBIxClassLoader
- Auto-vivifies your table classes
- No need for explicit definition of classes
- If it's there - it'll be loaded
- Use the plain version if you want to do it all
yourself - Caching objects to optimize database connection
10 Variety of Data Models
- Any datasource can be represented as model
- Other popular models (modules in CPAN)?
- SVN - Catalyst Model to browse Subversion
repositories - NetBlogger - Catalyst Model to post and retrieve
blog entries using NetBlogger - EVDB - interface to EVDB, the Events and Venues
Database. - XMLFeed - Use RSS/Atom feeds as a Catalyst
Model - LDAP - It is nothing more than a simple wrapper
for NetLDAP - S3 - Model for Amazon's S3 web service
- YouTube Model to access YouTube web services
11 Views
- Template Toolkit
- Designer-friendly
- Mini-language
- HTMLMason
- Perl all the way down
- One of the most sophisticated template toolkit
systems - HTMLTemplate
- Fast, simple, all markup
- Tested through the years
- Even more views
- RESTXML, RESTYAM
- Petal, PSP, PHP (seriosly!)?
12Plugins!
- Incredible number of plugins, ready to go
- They help us keep the core clean
- Lego principles
- Easy to use
- Everything stored on CPAN
- Easy installation, rapid deployment
use Catalyst qw/StaticSimple/ And now
your app can serve static files
13 Popular AAA tasks
- Lego-able Sessions
- Session
- SessionStoreFile
- SessionStateCookie
- Authenentication and Authorization
- Authenticate against DB data
- via CDBI, DBIC, LDAP, htpasswd
- PAM, RADIUS, Samba, OpenID, ...
- Restrict by Role or by ACL
- Also legoable
14 Caching data
- FastMmap Fast Memory Map
- Shared on a single machine
- MemCached
- Data is shared across a cluster
- PageCache
- Lets you cache rendered output
- Cache whatever you want yourself
- in your controller code
- Memoize, etc.
15 Controllers
- Self-contained controllers
- More attributes
package MyAppCFoo sub hello Local
my (self, c) _at__ c-gtres-gtbody("Hello
world!") Answers /foo/hello
sub login Global /login sub one
Path("foo") /foo/foo sub two
Path("/bar") /bar sub three Path
/foo/
16 Profiling Debugging
- Debugging
- On startup
- Log info about loaded components
- Display URL to method mapping
- At runtime
- Dispatched actions
- Errors caught and reported
- Detailied Dumps
- Profiling
- Debug output shows time per action
- TemplateTimer shows rendering time
17 Log Screenshot
18 Dispatching Flow control
- Advanced dispatchingIntelligent
redispatch
sub foo Regex("/foo/(.)/bar") Matches
available in c-gtsnippets sub bar
LocalRegex("baz/(.)/quux")
/foo/baz/(.)/quux
c-gtforward('foo') Calls sub foo Private in
the current namespace c-gtforward('/foo/bar')
Will call MyAppCFoobar
c-gtforward('ViewTT') Call non-controller
components too
19Packaging
- Easy to use helper script
- Templates are included
- And installed along with the code
- myapp_server.pl will Just Work
- It uploads fine to CPAN too
perl Build.PL ./Build test Just to be
sure )? ./Build dist Creating MyApp-0.01.tar.gz
20Testing
- Helpers create skeleton unit tests
- CatalystTest provides helper functions
- get(...) to grab the content
- request(...) returns a full HTTPResponse object
- remote_request(...) for live testing
- TestWWWMechanizeCatalyst
- Curious According to O'Reilly Article Perl
itself has the most complete tests suite among
all interpreter/bytecode languages
21Development Deployment Cycle
- One codebase for your app, various deployment
possibilities - Deploy under
- Standalone server
- can restart itself on every change made to the
source tree - FastCGI
- Incl integration option w/ Lighttpd
- Apache w/mod_perl
- Various platforms
- Bundling tools
- Includes tools for testsautomation
22Businessess that use it ?
- http//www.editgrid.com/
- Online, real-time updating spreadsheet
servicedesigned for extreme collaboration and
real world use - http//www.iusethis.com/
- I use this, what do you use?
- http//www.mandriva.com/hardware
- Compatible Hardware Database
- http//www.manchestereveningnews.co.uk/
- UK's most popular regional newspaper outside
London. - Commercial support
- Shadowcat Systems (http//www.shadowcatsystems.co.
uk) - Suretec Systems Ltd. (http//www.suretecsystems.co
m) - Robert Sedlacek (http//474.at - Hamburg, GER)?
23Referenced
- Catalyst coordinates
- Home http//catalyst.perl.org/
- List catalyst_at_lists.rawmode.org
- IRC irc.perl.orgcatalyst
- Data for this PPT was extracted from
- Matt Sergeants excellent slides for London.pm
http//shadowcatsystems.co.uk/static/london/cataly
st.xul - The Catalyst Documentation at CPANhttp//search.c
pan.org/search?qcatalystmanual - Catalyst Wikihttp//dev.catalystframework.org/
- The WikiPedia page for Catalyst
http//en.wikipedia.org/wiki/Catalyst_(software)?