Because I am a linux guy I have grown to love the perl language. Now I know many of you despise the language, however it has proven to be worthy in my field many of times. Not only worthy to stand up to loads but also to be flexible in it’s implementation. Am I speaking a little Greek?, forgive me. I say this because Perl is notabely good at parsing data from files, but over the years many of modules and frameworks have made it worthy in the field of web development.

So why don’t we just use PHP, or some other language like ASP if we are doing web development?. Well I have just grown fond of  languages that can be compiled and run as a client application, but also work in web development, or even be a good scripting language for Network Admins. I know there are many other languages out there that supersede Perl, but I give it some credit for putting up a good fight. Anyways I have wondered off the path.

For all those who are new with Perl and/or Catalyst I thought I would give a little instructional on what the different action types there are for Catalyst subroutines. Catalyst is an MVC framework for Perl. The frameworks help to try and leverage some of the great things in web web development, as well as make development more structured and easier. Although I am not sure about the easier part only because I feel frameworks tend to convolute code a bit. Now for a language like Perl, I feel it helps brings things together and make it more Object Oriented.

In MVC your subroutines in your controllers have actions assigned to them. This tells the routine what to part of the path to start from. For example

If the URL was http://localhost/My/Controller/foo

    package MyApp::Controller::My::Controller;
    sub foo : Local() { }

Then Local tell the routine that “foo” is the name of the routine and everything after bar in the url is considered an argument. So if the URL was http://localhost/My/Controller/foo/bar, then “bar” would be an argument passed in. Now another less used action is Global.

    package MyApp::Controller::My::Controller;
    sub foo : Global() { }

For this example, if we use the same URL then “Global” tells the routine to start from the root. In this case the root would be http://localhost/. So if you used $c->request->arguments->[0] then 0 in the array would be “My” instead of “bar” like when we used Local.

All these actions are just a shortcut way of using the action “Path”.  Example would be,

    package MyApp::Controller::My::Controller;
    sub foo : Path { }
    is the same as and matches on http://localhost/My/Controller/foo
    package MyApp::Controller::My::Controller;
    sub foo : Global { }
    and the following example will match on http://localhost/foo/bar
    package MyApp::Controller::My::Controller;
    sub bar: Path('foo/bar') { }

This is something that I had to tear apart and figure out a little bit, so I thought I would share this tidbit. Obviously there is tons more about this to talk about, so feel free to ask questions and I will share.

Advertisements