SlideShare ist ein Scribd-Unternehmen logo
1 von 41
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

Weitere ähnliche Inhalte

Andere mochten auch (7)

Assess2012 technology trends
Assess2012 technology trendsAssess2012 technology trends
Assess2012 technology trends
 
Apps mit Flash Catalyst
Apps mit Flash CatalystApps mit Flash Catalyst
Apps mit Flash Catalyst
 
Getting started with Catalyst and extjs
Getting started with Catalyst and extjsGetting started with Catalyst and extjs
Getting started with Catalyst and extjs
 
Dancing Tutorial
Dancing TutorialDancing Tutorial
Dancing Tutorial
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trial
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 

Ähnlich wie Catalyst And Chained

Railswaycon 2009 - Summary
Railswaycon 2009 - SummaryRailswaycon 2009 - Summary
Railswaycon 2009 - Summary
daniel.mattes
 
Advanced App Building - Tips, Tricks & Lessons Learned
Advanced App Building - Tips, Tricks & Lessons LearnedAdvanced App Building - Tips, Tricks & Lessons Learned
Advanced App Building - Tips, Tricks & Lessons Learned
Jay Graves
 
Talking About Fluent Interface
Talking About Fluent InterfaceTalking About Fluent Interface
Talking About Fluent Interface
Koji SHIMADA
 
Portlets
PortletsPortlets
Portlets
ssetem
 

Ähnlich wie Catalyst And Chained (20)

MacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meet
 
All The Little Pieces
All The Little PiecesAll The Little Pieces
All The Little Pieces
 
No Really, It's All About You
No Really, It's All About YouNo Really, It's All About You
No Really, It's All About You
 
Railswaycon 2009 - Summary
Railswaycon 2009 - SummaryRailswaycon 2009 - Summary
Railswaycon 2009 - Summary
 
Oxente on Rails 2009
Oxente on Rails 2009Oxente on Rails 2009
Oxente on Rails 2009
 
Advanced App Building - Tips, Tricks & Lessons Learned
Advanced App Building - Tips, Tricks & Lessons LearnedAdvanced App Building - Tips, Tricks & Lessons Learned
Advanced App Building - Tips, Tricks & Lessons Learned
 
Administrivia: Golden Tips for Making JIRA Hum
Administrivia: Golden Tips for Making JIRA HumAdministrivia: Golden Tips for Making JIRA Hum
Administrivia: Golden Tips for Making JIRA Hum
 
Administrivia: Golden Tips for Making JIRA Hum
Administrivia: Golden Tips for Making JIRA HumAdministrivia: Golden Tips for Making JIRA Hum
Administrivia: Golden Tips for Making JIRA Hum
 
Enterprise Security mit Spring Security
Enterprise Security mit Spring SecurityEnterprise Security mit Spring Security
Enterprise Security mit Spring Security
 
Improving Drupal's Page Loading Performance
Improving Drupal's Page Loading PerformanceImproving Drupal's Page Loading Performance
Improving Drupal's Page Loading Performance
 
Joomla Template Development
Joomla Template DevelopmentJoomla Template Development
Joomla Template Development
 
Web Standards and Accessibility
Web Standards and AccessibilityWeb Standards and Accessibility
Web Standards and Accessibility
 
Apache Solr Changes the Way You Build Sites
Apache Solr Changes the Way You Build SitesApache Solr Changes the Way You Build Sites
Apache Solr Changes the Way You Build Sites
 
Ryan Campbell - OpenFlux and Flex 4
Ryan Campbell - OpenFlux and Flex 4Ryan Campbell - OpenFlux and Flex 4
Ryan Campbell - OpenFlux and Flex 4
 
Bay Area Drupal Camp Efficiency
Bay Area Drupal Camp EfficiencyBay Area Drupal Camp Efficiency
Bay Area Drupal Camp Efficiency
 
Intro To Git
Intro To GitIntro To Git
Intro To Git
 
Talking About Fluent Interface
Talking About Fluent InterfaceTalking About Fluent Interface
Talking About Fluent Interface
 
Portlets
PortletsPortlets
Portlets
 
Creating Practical Security Test-Cases for Web Applications
Creating Practical Security Test-Cases for Web ApplicationsCreating Practical Security Test-Cases for Web Applications
Creating Practical Security Test-Cases for Web Applications
 
Deploying And Monitoring Rails
Deploying And Monitoring RailsDeploying And Monitoring Rails
Deploying And Monitoring Rails
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

Catalyst And Chained

  • 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

Hinweis der Redaktion