• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Catalyst And Chained
 

Catalyst And Chained

on

  • 5,992 views

A talk discussing the structure and merits of using Chained and base classes.

A talk discussing the structure and merits of using Chained and base classes.

Statistics

Views

Total Views
5,992
Views on SlideShare
5,965
Embed Views
27

Actions

Likes
5
Downloads
47
Comments
0

3 Embeds 27

http://www.slideshare.net 22
http://basirat.org 4
http://www.basirat.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Catalyst And Chained Catalyst And Chained Presentation Transcript

  • Catalyst & Chained MVC Bondage Friday, February 6, 2009
  • Catalyst & Chained Jay Shirley: ‘jshirley’ •Director, National Auto Sport Assoc. •Business Director, Cold Hard Code •Catalyst, DBIx::Class •http://our.coldhardcode.com/jshirley/ •JAPH Friday, February 6, 2009
  • Catalyst & Chained What is Catalyst? Friday, February 6, 2009
  • Catalyst & Chained What Catalyst Is Not. Friday, February 6, 2009
  • Catalyst & Chained What Catalyst Is Not •An experiment or prototype. •A toy. •Opinionated. •An “all in one” package. •Complicated. Friday, February 6, 2009
  • Catalyst & Chained What Catalyst Is •Simple Framework. •Trusts the developer. •Buckets. •Easily extensible. Friday, February 6, 2009
  • Catalyst & Chained The Basics •MVC Oriented. •Promotes good code design. •Use all of CPAN, easily. •Built-in server. Friday, February 6, 2009
  • Catalyst & Chained Dispatching •Getting from here to there •/public/url => /private/action •Types: •Chained •Local •Regular Expressions Friday, February 6, 2009
  • Catalyst & Chained What is Chained? Friday, February 6, 2009
  • Catalyst & Chained Chained in 4 Sentences •Defined execution path •“Route” of methods to take •Configurable URLs •Spans Multiple Controllers Friday, February 6, 2009
  • Catalyst & Chained In Code: sub base { } sub after_base { } sub after_after_base { } Friday, February 6, 2009
  • Catalyst & Chained: 999 Words In Pictures (and code) A B display Private Path: /a/b/end sub A : Chained(‘/’) CaptureArgs(0){} sub B : Chained(‘A’) CaptureArgs(0){} sub display : Chained(‘B’) Args(0){} Friday, February 6, 2009
  • Catalyst & Chained What’s the point? •Public URI != Internal Actions •Easily add “automatic” code (no more sub auto { }) •Each step is executed, in order. •Can capture URI arguments Friday, February 6, 2009
  • Catalyst & Chained: If you know mst, you know it isn’t a... Free Lunch •Short-circuit any request at any point. •Easily add midpoint actions. •Descend namespaces. •Sane and programmatic URI construction. •Easy abstraction. Friday, February 6, 2009
  • Catalyst & Chained Benefits Friday, February 6, 2009
  • Catalyst & Chained Configurable URLs •Public Paths: PathPart(‘public_url_part’) •Internal Action: sub action_name : ... { } •Easily modifiable public paths to change URL structure. Friday, February 6, 2009
  • Catalyst & Chained: Your own personal Voltron Configurable Paths __PACKAGE__->config( action => { ‘action_name’ => { Chained => ‘/’, PathPart(‘public’) } } ); # Public URL: /public Friday, February 6, 2009
  • Catalyst & Chained Why? •Public URLs are your API •Being able to change them is good. •Not breaking them is better. Friday, February 6, 2009
  • Catalyst & Chained Abstraction package MyApp::ControllerBase::Foo; Friday, February 6, 2009
  • Catalyst & Chained: Pass the cool whip Thinner Controllers package MyApp::Controller::Bar; use parent ‘MyApp::ControllerBase::Foo’; sub setup : Chained(‘.’) CaptureArgs(0) { # Setup stash, done! } Friday, February 6, 2009
  • Catalyst & Chained: Pass the cool whip Thinner Controllers package MyApp::Controller::Bar; use parent ‘MyApp::ControllerBase::Foo’; sub setup : Chained(‘.’) CaptureArgs(0) { # Setup stash, done! } Friday, February 6, 2009
  • Catalyst & Chained Common End-Points package MyApp::ControllerBase::Foo; use parent ‘Catalyst::Controller’; sub display : Chained(‘...’) Args(0) { } Friday, February 6, 2009
  • Catalyst & Chained Better Applications Friday, February 6, 2009
  • Catalyst & Chained A Simple Example •Photos •Belong to a ‘person’ •Have tags Friday, February 6, 2009
  • Catalyst & Chained URL Structure •Keep it simple: •/person/$name/photos •/tag/$name/photos Friday, February 6, 2009
  • Catalyst & Chained Controllers •MyApp::Controller::Person •MyApp::Controller::Person::Photos •MyApp::Controller::Tag •MyApp::Controller::Tag::Photos Friday, February 6, 2009
  • Catalyst & Chained Commonalities •MyApp::Controller::Person •MyApp::Controller::Person::Photos •MyApp::Controller::Tag •MyApp::Controller::Tag::Photos Friday, February 6, 2009
  • Catalyst & Chained The Base Class package MyApp::ControllerBase::Photos; use parent ‘Catalyst::Controller’; sub display : Chained(‘setup’) PathPart(‘photos’) Args(0) { } Friday, February 6, 2009
  • Catalyst & Chained The Base Class package MyApp::ControllerBase::Photos; use parent ‘Catalyst::Controller’; sub display : Chained(‘setup’) PathPart(‘photos’) Args(0) { } Friday, February 6, 2009
  • Catalyst & Chained The Base Class package MyApp::ControllerBase::Photos; use parent ‘Catalyst::Controller’; sub display : Chained(‘setup’) PathPart(‘photos’) Args(0) { } Friday, February 6, 2009
  • Catalyst & Chained Person::Photos package MyApp::Controller::Person::Photos; use parent ‘MyApp::ControllerBase::Photos’; sub setup : Chained(‘.’) PathPart(‘’) CaptureArgs(0) { my ( $self, $c ) = @_; $c->stash->{photos} = $c->stash->{person}->photos; } Friday, February 6, 2009
  • Catalyst & Chained Person::Photos package MyApp::Controller::Person::Photos; use parent ‘MyApp::ControllerBase::Photos’; sub setup : Chained(‘.’) PathPart(‘’) CaptureArgs(0) { my ( $self, $c ) = @_; $c->stash->{photos} = $c->stash->{person}->photos; } Friday, February 6, 2009
  • Catalyst & Chained Person::Photos package MyApp::Controller::Person::Photos; use parent ‘MyApp::ControllerBase::Photos’; sub setup : Chained(‘.’) PathPart(‘’) CaptureArgs(0) { my ( $self, $c ) = @_; $c->stash->{photos} = $c->stash->{person}->photos; } Friday, February 6, 2009
  • Catalyst & Chained A Note •Person::Photos only: •cares about itself. •is very thin (just the stash, ma’am). •can actually be abstracted to just configuration Friday, February 6, 2009
  • Catalyst & Chained Tag::Photos •Same as Person::Photos, except: •$c->stash->{tag} instead of $c->stash->{person} •has a different template. Friday, February 6, 2009
  • Catalyst & Chained The Base Class, Version 2 package MyApp::ControllerBase::Photos; use parent ‘Catalyst::Controller’; sub setup : Chained(‘.’) PathPart(‘’) CaptureArgs(0) { my ( $self, $c ) = @_; my $stash = $self->{stash_key}; my $source = $self->{source_key}; $c->stash->{$stash} = $c->stash->{$source}->photos; } sub display ... { # unchanged } Friday, February 6, 2009
  • Catalyst & Chained Config: Person package MyApp::Controller::Person::Photos; use parent ‘MyApp::ControllerBase::Photos’; __PACKAGE__->config( source_key => ‘person’, stash_key => ‘photos’ ); Friday, February 6, 2009
  • Catalyst & Chained Config: Tag package MyApp::Controller::Tag::Photos; use parent ‘MyApp::ControllerBase::Photos’; __PACKAGE__->config( source_key => ‘tag’, stash_key => ‘photos’ ); Friday, February 6, 2009
  • Catalyst & Chained Config: Tag package MyApp::Controller::Tag::Photos; use parent ‘MyApp::ControllerBase::Photos’; __PACKAGE__->config( source_key => ‘tag’, stash_key => ‘photos’ ); Friday, February 6, 2009
  • Catalyst & Chained That’s it •Now, you just work with: •/person/photos/display.tt •/tag/photos/display.tt •Thin controllers, how to get photos determined just from configuration. Friday, February 6, 2009
  • Catalyst & Chained Questions? http://github.com/jshirley/catalystx-example-chained/tree Friday, February 6, 2009