SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

Destacado

Assess2012 technology trends
Assess2012 technology trendsAssess2012 technology trends
Assess2012 technology trendsiansyst
 
Getting started with Catalyst and extjs
Getting started with Catalyst and extjsGetting started with Catalyst and extjs
Getting started with Catalyst and extjsPeter Edwards
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trialbrian d foy
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinosbrian d foy
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 

Destacado (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
 

Similar a Catalyst And Chained

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 meetMatt Aimonetti
 
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 YouChris Cornutt
 
Railswaycon 2009 - Summary
Railswaycon 2009 - SummaryRailswaycon 2009 - Summary
Railswaycon 2009 - Summarydaniel.mattes
 
Oxente on Rails 2009
Oxente on Rails 2009Oxente on Rails 2009
Oxente on Rails 2009Fabio Akita
 
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 LearnedJay Graves
 
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 HumAtlassian
 
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 HumAtlassian
 
Enterprise Security mit Spring Security
Enterprise Security mit Spring SecurityEnterprise Security mit Spring Security
Enterprise Security mit Spring SecurityMike Wiesner
 
Improving Drupal's Page Loading Performance
Improving Drupal's Page Loading PerformanceImproving Drupal's Page Loading Performance
Improving Drupal's Page Loading PerformanceWim Leers
 
Joomla Template Development
Joomla Template DevelopmentJoomla Template Development
Joomla Template DevelopmentLinda Coonen
 
Web Standards and Accessibility
Web Standards and AccessibilityWeb Standards and Accessibility
Web Standards and AccessibilityNick DeNardis
 
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 SitesPeter
 
Ryan Campbell - OpenFlux and Flex 4
Ryan Campbell - OpenFlux and Flex 4Ryan Campbell - OpenFlux and Flex 4
Ryan Campbell - OpenFlux and Flex 4360|Conferences
 
Bay Area Drupal Camp Efficiency
Bay Area Drupal Camp EfficiencyBay Area Drupal Camp Efficiency
Bay Area Drupal Camp Efficiencysmattoon
 
Talking About Fluent Interface
Talking About Fluent InterfaceTalking About Fluent Interface
Talking About Fluent InterfaceKoji SHIMADA
 
Portlets
PortletsPortlets
Portletsssetem
 
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 ApplicationsRafal Los
 
Deploying And Monitoring Rails
Deploying And Monitoring RailsDeploying And Monitoring Rails
Deploying And Monitoring RailsJonathan Weiss
 

Similar a 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
 

Último

Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
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 RobisonAnna Loughnan Colquhoun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
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 challengesrafiqahmad00786416
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
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 Processorsdebabhi2
 
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 CVKhem
 
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...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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 SavingEdi Saputra
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Último (20)

Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
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
 
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 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...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

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

Notas del editor