Your SlideShare is downloading. ×
0
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Catalyst And Chained
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Catalyst And Chained

3,776

Published on

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.

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,776
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
48
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide









































  • Transcript

    • 1. Catalyst & Chained MVC Bondage Friday, February 6, 2009
    • 2. 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
    • 3. Catalyst & Chained What is Catalyst? Friday, February 6, 2009
    • 4. Catalyst & Chained What Catalyst Is Not. Friday, February 6, 2009
    • 5. Catalyst & Chained What Catalyst Is Not •An experiment or prototype. •A toy. •Opinionated. •An “all in one” package. •Complicated. Friday, February 6, 2009
    • 6. Catalyst & Chained What Catalyst Is •Simple Framework. •Trusts the developer. •Buckets. •Easily extensible. Friday, February 6, 2009
    • 7. Catalyst & Chained The Basics •MVC Oriented. •Promotes good code design. •Use all of CPAN, easily. •Built-in server. Friday, February 6, 2009
    • 8. Catalyst & Chained Dispatching •Getting from here to there •/public/url => /private/action •Types: •Chained •Local •Regular Expressions Friday, February 6, 2009
    • 9. Catalyst & Chained What is Chained? Friday, February 6, 2009
    • 10. Catalyst & Chained Chained in 4 Sentences •Defined execution path •“Route” of methods to take •Configurable URLs •Spans Multiple Controllers Friday, February 6, 2009
    • 11. Catalyst & Chained In Code: sub base { } sub after_base { } sub after_after_base { } Friday, February 6, 2009
    • 12. 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
    • 13. 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
    • 14. 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
    • 15. Catalyst & Chained Benefits Friday, February 6, 2009
    • 16. 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
    • 17. Catalyst & Chained: Your own personal Voltron Configurable Paths __PACKAGE__->config( action => { ‘action_name’ => { Chained => ‘/’, PathPart(‘public’) } } ); # Public URL: /public Friday, February 6, 2009
    • 18. Catalyst & Chained Why? •Public URLs are your API •Being able to change them is good. •Not breaking them is better. Friday, February 6, 2009
    • 19. Catalyst & Chained Abstraction package MyApp::ControllerBase::Foo; Friday, February 6, 2009
    • 20. 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
    • 21. 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
    • 22. Catalyst & Chained Common End-Points package MyApp::ControllerBase::Foo; use parent ‘Catalyst::Controller’; sub display : Chained(‘...’) Args(0) { } Friday, February 6, 2009
    • 23. Catalyst & Chained Better Applications Friday, February 6, 2009
    • 24. Catalyst & Chained A Simple Example •Photos •Belong to a ‘person’ •Have tags Friday, February 6, 2009
    • 25. Catalyst & Chained URL Structure •Keep it simple: •/person/$name/photos •/tag/$name/photos Friday, February 6, 2009
    • 26. Catalyst & Chained Controllers •MyApp::Controller::Person •MyApp::Controller::Person::Photos •MyApp::Controller::Tag •MyApp::Controller::Tag::Photos Friday, February 6, 2009
    • 27. Catalyst & Chained Commonalities •MyApp::Controller::Person •MyApp::Controller::Person::Photos •MyApp::Controller::Tag •MyApp::Controller::Tag::Photos Friday, February 6, 2009
    • 28. 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
    • 29. 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
    • 30. 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
    • 31. 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
    • 32. 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
    • 33. 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
    • 34. 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
    • 35. 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
    • 36. 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
    • 37. 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
    • 38. 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
    • 39. 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
    • 40. 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
    • 41. Catalyst & Chained Questions? http://github.com/jshirley/catalystx-example-chained/tree Friday, February 6, 2009

    ×