SlideShare a Scribd company logo
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips
10 Catalyst Tips

More Related Content

KEY
Zen: Building Maintainable Catalyst Applications
KEY
Building Better Applications with Data::Manager
PDF
Smolder @Silex
KEY
dotCloud and go
PDF
Perl web app 테스트전략
PDF
I, For One, Welcome Our New Perl6 Overlords
PPTX
Webrtc mojo
PDF
Perl 5.28 new features
Zen: Building Maintainable Catalyst Applications
Building Better Applications with Data::Manager
Smolder @Silex
dotCloud and go
Perl web app 테스트전략
I, For One, Welcome Our New Perl6 Overlords
Webrtc mojo
Perl 5.28 new features

What's hot (20)

PDF
Keeping objects healthy with Object::Exercise.
PDF
BSDM with BASH: Command Interpolation
PDF
Bag of tricks
PDF
Perl Bag of Tricks - Baltimore Perl mongers
PDF
6 things about perl 6
PDF
PHPSpec BDD Framework
KEY
Good Evils In Perl (Yapc Asia)
PDF
Metadata-driven Testing
PDF
TRunner
PDF
優しいWAFの作り方
PDF
Findbin libs
ODP
PDF
How to develop modern web application framework
PDF
Perl v5.26 Features (AmsterdamX.pm)
TXT
fabfile.py
PDF
The $path to knowledge: What little it take to unit-test Perl.
ODP
Nigel hamilton-megameet-2013
PDF
Get your teeth into Plack
PDF
Perl Sucks - and what to do about it
PDF
BASH Variables Part 1: Basic Interpolation
Keeping objects healthy with Object::Exercise.
BSDM with BASH: Command Interpolation
Bag of tricks
Perl Bag of Tricks - Baltimore Perl mongers
6 things about perl 6
PHPSpec BDD Framework
Good Evils In Perl (Yapc Asia)
Metadata-driven Testing
TRunner
優しいWAFの作り方
Findbin libs
How to develop modern web application framework
Perl v5.26 Features (AmsterdamX.pm)
fabfile.py
The $path to knowledge: What little it take to unit-test Perl.
Nigel hamilton-megameet-2013
Get your teeth into Plack
Perl Sucks - and what to do about it
BASH Variables Part 1: Basic Interpolation
Ad

Similar to 10 Catalyst Tips (20)

KEY
SPL, not a bridge too far
PDF
Building Testable PHP Applications
PDF
What's up with Prototype and script.aculo.us?
KEY
Modern Catalyst
PPTX
2012 coscup - Build your PHP application on Heroku
PDF
Hacking with ruby2ruby
PDF
LISA QooxdooTutorial Slides
PPT
Adventures in infrastructure as code
PDF
Perl web frameworks
PDF
Curscatalyst
PDF
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
PPT
Testing of javacript
KEY
PHPUnit testing to Zend_Test
PDF
Dependency Injection Smells
KEY
Anatomy of a PHP Request ( UTOSC 2010 )
KEY
PDF
Symfony 2.0
PPTX
Workshop 1: Good practices in JavaScript
PDF
Static Optimization of PHP bytecode (PHPSC 2017)
ODP
The why and how of moving to PHP 5.4/5.5
SPL, not a bridge too far
Building Testable PHP Applications
What's up with Prototype and script.aculo.us?
Modern Catalyst
2012 coscup - Build your PHP application on Heroku
Hacking with ruby2ruby
LISA QooxdooTutorial Slides
Adventures in infrastructure as code
Perl web frameworks
Curscatalyst
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Testing of javacript
PHPUnit testing to Zend_Test
Dependency Injection Smells
Anatomy of a PHP Request ( UTOSC 2010 )
Symfony 2.0
Workshop 1: Good practices in JavaScript
Static Optimization of PHP bytecode (PHPSC 2017)
The why and how of moving to PHP 5.4/5.5
Ad

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PPTX
A Presentation on Artificial Intelligence
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Getting Started with Data Integration: FME Form 101
PDF
Mushroom cultivation and it's methods.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
Machine Learning_overview_presentation.pptx
Spectroscopy.pptx food analysis technology
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
A Presentation on Artificial Intelligence
Programs and apps: productivity, graphics, security and other tools
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
TLE Review Electricity (Electricity).pptx
Unlocking AI with Model Context Protocol (MCP)
Encapsulation_ Review paper, used for researhc scholars
Spectral efficient network and resource selection model in 5G networks
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Getting Started with Data Integration: FME Form 101
Mushroom cultivation and it's methods.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Assigned Numbers - 2025 - Bluetooth® Document
cloud_computing_Infrastucture_as_cloud_p
Machine Learning_overview_presentation.pptx

Editor's Notes

  • #3: The first topic is Catalyst plugins, authoring them and using them.
  • #4: The simple advice is to stop. Don’t use plugins. They’re grossly abused, misused, overused and generally wrong.
  • #5: There is only one single case when it is ok to use Plugins. Only one. No more, and no exceptions. When you need to inspect, modify or otherwise muck with dispatching. This includes parameter munging, altering the Catalyst chain of execution and things like this.
  • #6: There are so many Catalyst::Plugin modules that shouldn’t be out there. While they let you add methods onto your context ($c) object, that’s just bad form. Most of them should be models, and some just shouldn’t exist (Catalyst::Plugin::Message!).
  • #7: Ok, there are exceptions to the rule. Authentication and Session are probably valid reasons, but there are reasons behind the exception. You need to inflate the session before even the root level begin action is called (for cache-based requests), and the authorization plugin makes sense as a plugin. It bypasses dispatching at the application level, so it requires the user to be inflated. In all these, you could do them as controllers. A root level begin action could handle inflating the session, restoring the user and then running the access controls to determine validity.
  • #8: These convenience methods are worth the Plugin. However, unless you’re writing something that is completely global, the exception to the “Don’t write plugins” rule probably won’t hold up. If you write plugins, and then upload them to CPAN, the Catalyst core team dies a little bit inside. Especially MST.
  • #9: Up next is debugging your Catalyst application. On the mailing list, a lot of people post problems and don’t really know how to get enough information on their own to solve them. I’m just going to run down a common set of the problems that users have.
  • #10: Syntax error in the code while method attribute parsing is happening. There are patches to fix this, but a lot of repositories don’t have it yet. You can do perl -cw on the file and still get the syntax error, but it’s frustrating and annoying.
  • #11: You can get a lot of information from Catalyst when running in debug mode. Aside from what shows up in the console, you can run the request and then dump everything out to the screen in a nicely formatted view. This can be very good for writing automated tests to inspect the stash and configuration, or just fixing that weird bug when you don’t want to modify templates to put in debugging statements.
  • #12: Writing mechanize test that use Test::WWW::Mechanize::Catalyst are really easy, and quickly expose bugs in controllers. I highly recommend doing this and then when your code breaks and you need debugging help, you can say, “I have this test” and the Catalyst community will jump at the chance to help someone with the foresight to post the problem with a test.
  • #14: Every Catalyst component, including the application (MyApp.pm), has a config accessor. As a rule, only modify this BEFORE setup is completed. After that, you can get heisenbugs. You’ve been warned. So, this is how you configure something in a controller.
  • #15: To configure that same controller at a higher precedence, you do it at the application level. These two configuration examples are identical and produce the same results.
  • #16: And to get at it, the big thing is to simply use accessors to get at the configuration key.
  • #17: A moose example to create the ‘foo’ accessor, since we have the ‘foo’ config key (that was set to ‘bar’)
  • #18: Or the old school way
  • #19: And yes, config keys are merged into $self in a Catalyst component.
  • #20: So, you have the hash entry ‘foo’ that is set for you in your component to work with. This is merged in the way you would expect.
  • #21: So if you have the configuration specified in the myapp_local file, that gets set in $self->{foo}. It just works down from there, traversing into the myapp.conf file and then the application configuration and finally the controller itself.
  • #22: But, people still do this wrong.
  • #23: This is wrong. While it will -probably- be right, don’t do it. Simply do $self->{fo}. That is what you want, and in all cases will be the right value.
  • #24: But, that case will almost always be correct. This case, however, will most likely not be. At component creation time, the configuration is merged into $self already. So use that.
  • #25: As you can see, the rule here is to always use $self for configuration values that are specific to a component. Application level configuration can be inspected from $c->config, but only generalized configuration.
  • #26: Once you get an understanding of configuration, you really should use it and abuse it. Doing so will really enhance your applications and hopefully get you writing less code that does more. Which leads conveniently to the next point, number 4.
  • #27: What makes a better controller? Well, to me, the thinner the better. The best way to do this is base classes.
  • #28: A lot of controllers fit into specific types of behaviors, most of which are configurable. With the knowledge you now have of configuration, you can make very thin controllers that inherit from thicker base controllers and still delegate as much as possible to the models.
  • #29: For most cases, sometimes your classes can really be nothing more than a config block. If you have a DBIC CRUD application, this is very easy to accomplish.
  • #30: There’s a package on CPAN that does this exactly, and gets you very far with nothing more than configuration blocks. I urge you to give it a try, as for most cases it works very well. Since it’s a base class, you can override any methods it uses. It uses Chained, so it’s very simple to alter behavior.
  • #31: Chained is a simple dispatch method that unfortunately confuses a lot of people, and that’s because method attributes are terrible. Maybe not, but that’s my theory.
  • #32: The entire methodology is a route, letting you incrementally travel from point A to B. The steps can be easily modified and logged, so it’s very very powerful.
  • #33: It does, however, require you to stop thinking about actions being part of your URI. No more of thinking that your action name has to correspond to the URI.
  • #34: Before Chained, you have a controller, say “Bar”, with a method foo and that becomes the URI. You just have /bar/foo. This, however, is silly.
  • #35: Your URI is your publicly facing URI, it shouldn’t matter what your private action is called. It certainly shouldn’t follow each step that you invariably end up with, with several private actions as common code gets moved.
  • #36: Right, you see, method attributes suck.
  • #37: Point A to B is a bad example, because you just have two points. But lets say you have a real use case here, where you want to test user permissions, then test if an object exists (like /foo/123) and then some action based off that in a nice CRUD format. So you start with a URI
  • #38: Before Chained, you’d have a hard time building a URL like this. That’s not really why you want to use Chained though, you want to use Chained because you can get executable actions at every step of the chain. At /foo, at the 123 and finally at the edit.
  • #39: You get auto actions, except at every step. Since I’ve switched to Chained, I’ve not used an auto action. To have the power to incrementally build your pipeline and relationships like this is awesome.
  • #40: If you have an action ‘setup_object’ you tell Catalyst where it is chained from. Here, we’re using “/” which is the root action. By default, the path part is also the method name but can be overriden with the PathPart attribute.
  • #41: The CaptureArgs attribute is the most important part of Chained. It determines exactly how many arguments to intercept in the dispatch chain. Looking back at the URL, the CaptureArgs is the ‘123’
  • #42: The 123 is passed in to the action arguments
  • #43: So, you can catch it and then dispatch accordingly. This is usually where you would fetch the object from the database, check permissions and other actions. However, at this point we do not yet have an end point that is accessible to the user. To define the end point, we have to define additional methods.
  • #44: Here is the end point defined, and it chains itself to the other method
  • #45: We use the private action path in the Chained argument, which is in most cases simply the method name.
  • #46: The Args, not CaptureArgs, defines that this method is an end-point.
  • #47: The end-point method, which can also be overridden by PathPart, is listed at the end -- after the capture arguments. In this case, our method is called ‘edit’ so that’s what we end up with.
  • #48: But I know that these slides don’t let you understand it fully, but that’s ok. I just want to convince you to try it. I have an application for you, just for this purpose.
  • #49: Look at my Catalyst examples on github, you can play around with some Chained examples that are nicely documented and hopefully get you started.
  • #52: This means that your webserver (Apache) is spawning the FastCGI processes and handling the process management directly. This requires restarting your webserver to restart your application. I don’t like that.
  • #53: I prefer the external method, using a separate process manager and starting the FastCGI daemon and have it listen on a unix socket. This has a couple benefits
  • #54: The best one is zero downtime, achieved by the wonderful facility of unix sockets having multiple applications listening to them. So, the technique is simply “Start the new version before you shutdown the old one.” If you have a really catastrophic change in your application, a cold start is probably best but it still is a fantastic way to upgrade your application without incurring a penalty when the FastCGI socket dies.
  • #55: The second best reason to use External FastCGI is that you are an independent, free thinking entity. So should your application, and you shouldn’t restart your web server to restart your application. There are a few init scripts floating around, and I’ve posted my favorites on http://our.coldhardcode.com/
  • #56: There is a simple “just start, restart and be done” script, as well as a zero-downtime script. Both are configurable, and I really want to write something that manages the processes better. If you want to, let me know and we can share brains.
  • #57: We’ve all heard of mod_perl, and some of us have even used it.
  • #58: But you should already know enough about mod_perl to use it. I’m not saying it is bad, I’m just saying that if you don’t know that you need it, you probably don’t need it. So lets move on.
  • #59: A nice Perl based preforking server, that is very similar to Mongrel but still uses the Catalyst scripts for process management. I’ve tried to use mongrel, and it pisses me off. HTTP::Prefork hasn’t yet, and still offloads what it can to C-level functions (and XS) so it’s very fast, lightweight and works well. You don’t get the middle-man load of FastCGI, and don’t lose the capability to independently restart your application.
  • #60: While the code base is pretty robust, stable and written by some smart people who know this stuff I still don’t know of any high-profile and high-traffic sites that are deployed on HTTP::Prefork. I’ve used it, and sitting behind something like nginx is fantastic, but again, only for my own internal applications and nothing getting real user base. So, please, give it a try and let us know if it falls down. It has some strong merits, but some other points that remain to be solved.
  • #61: The one that matters to me is that it loses the unix socket zero downtime trick. While there are other ways to do it, such as load balancing between two ports and upgrading each port incrementally, it isn’t as easy to get done as External FastCGI.
  • #63: Catalyst::Log is a very good start for a basic logging mechanism. It provides a rudimentary buffer, with a flush mechanism and the typical debug levels.
  • #64: The already on CPAN enhanced logging package is Catalyst::Log::Log4perl, which really brings out a lot of power. You get all of the power of Log::Log4perl, but still it exists as $c->log.
  • #65: Even if you use a logger that has all sorts of fantastic methods, you probably don’t want to use them. Using the standard debug, info, warning, error and fatal methods gets you what you want, and there really aren’t a lot of convincing arguments. If you adhere to those methods, then you can swap loggers in and out without having to update your app.
  • #66: The fantastic _dump method gives you a pretty-printed output similar to what you’d get with Data::Dump (and uses Data::Dump under the hood). This is an undocumented “private” method because it deviates from the standard logging methods above, but Catalyst::Log and Catalyst::Log::Log4perl both support it. It emits the message as an info message.
  • #68: Action classes are eventually going to be replaced with roles, which is a much better way of doing things. You can skip ahead, and reap the benefits by using...
  • #69: This exchanges the idea of Action Classes and replaces them with roles, which is really what an action class is (describing that it does something). Catalyst::Controller::ActionRole is on CPAN, and available for playing with.
  • #70: You can ignore this if you don’t already fully understand roles or use them. They’re very useful, but I’m trying to keep the Meta to a minimum.
  • #71: Action classes can turn into Roles, which works out a bit better as far as semantic coding.
  • #72: If you want to see more, there is plenty of information out there.
  • #73: So, back to action classes. These are very useful because they essentially wrap the action’s execution in a method that you control. A very popular action class is the REST action class, which takes the action name, inspects the request method (like POST, PUT) and then dispatches to another method specifically for the request.
  • #74: Usually when you have some “meta” actions that happen around the action. Perhaps it is parameter munging on an per-action basis that isn’t suitable for a plugin. I recently wrote an ActionClass that fetches page properties for the specific action, so that marketing people can modify certain aspects of the behavior of the action in a GUI. The action class then populates the stash with some defaults. While you can do this with a model, having the role of an action being taken just cleans up some syntax, and also lets you interrupt dispatching in more powerful ways that still keeps your controllers thin.
  • #76: The main point of local::lib is that it separates your application from the vendor supplied paths. What this generally means is that on a per-user basis, you can have your own perl lib tree. Stuffing everything in the vendor perl has a lot of limitations, and it just isn’t a good way to do it. You’re really bound to whatever version of perl, bugs and all, the vendor supplies because updating Perl may break your entire system. Additionally, security patches supplied by your vendor may break Perl (Like Apple’s latest security update).
  • #77: You can do it, and most people do with few negative side-effects. It doesn’t make it good, and considering how easy local::lib is to get going, there really isn’t a reason to not use it.
  • #78: In your application, if you keep your Makefile.PL (or Build.PL) up to date, you can install all the dependencies as the user that is running the application. You’re guaranteed that the packages you install via local::lib are those running your application, so on a multi-user system (or multi-application, with one application per user) you can run different versions of different software.
  • #79: In most cases, your application shouldn’t run as root. You shouldn’t have your dependencies requiring root, either. If you use external FastCGI, local::lib, you can run and deploy your entire application without ever touching the root account.
  • #80: To setup local::lib, just install it from CPAN. When you load local::lib, it dumps out environment variable settings to use. Simply store those in your bash or cshrc profiles and you are set to go. Installing modules from CPAN or from a tarball puts them in a local, sanitary directory.
  • #81: Want to start from scratch? No Problem. You still have a fallback to work from with your Perl, so removing your local::lib directory won’t destroy Perl. You can start from scratch.
  • #82: local::lib defaults to a ‘perl’ directory that lives in your home directory. However, it is very trivial to have a lot of local::lib paths, and to even switch between them. This is particularly useful for doing smoke testing, if you have multiple environments.
  • #83: Contributing to Catalyst is easy. There’s a lot of things you could do, and a lot of them don’t involve a lot of code.
  • #84: Documentation is always good
  • #85: Tests are even better
  • #86: But getting the word out, showing off applications and simply doing something with Perl and Catalyst is the best thing you can do to help Catalyst and the Perl community. Perl in general is languishing because we’re very inventor heavy. We have a lot of names that work in theory, and build tools, but not a lot of people who are out building applications. So, if you find something cool to do with Catalyst then blog about it.
  • #87: If you have an application out the door, tell the world it is running on Catalyst. Help other people out by showing how you did it, and even discussing some problems. This has a lot of benefits, and it helps get your name out there and even helps hire better developers.
  • #88: The more applications that are still running and built on Perl means the more developers will be using Perl. It’s viral. If you want to help Perl and the Catalyst community, build end-user sites. Talk about how you did it. You’ll get better developers, and more of them.
  • #89: A big reason why people assume Perl is dead is because too few new sites talk about using Perl. I know a lot of developers who don’t even know that Vox is written in Perl (let alone Catalyst). There’s reasons for this
  • #90: See, this is good for me but bad for Vox. Perl isn’t any better, but I’m not the top result so you don’t get to see it. Talk about how you build your site, and you will get better search results. Of course, if you’re working on an internal site you can ignore this point. But don’t ignore the last 9!