SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
Getting Your Teeth Into Plack:
  A short introduction to the 
next generation of web service.




        Steven Lembark
     Workhorse Computing
No! This is not a Listerine ad!
●   Sorry, no jingle in the background.
●   Plack is an interface for web request handlers.
●   It simplifies the interface to a usable level.
●   Permits more portable code.
●   Allows you to focus on your content handler, not
    the API specs.
In the beginning...
●   Was CGI:
    –   It was simple enough to implement.
    –   Proved platform and language agnostic.
    –   Lived outside of the server, with simple variables and
        print statements moving the data in and out of back-end
        code.
    –   Became the standard for most work on the web.
CGI has problems. 
●   It was designed for shell-ish environments.
    –   Each iteration of the site required re-launching the CGI
        “script” as a separate process.
    –   This caused too much overhead to re-process the source
        code for every request.
    –   Let alone the overhead of creating new processes,
        especially on non-*NIX systems.
●   Fixes involved avoiding the re-processing and
    dodging CGI altogether.
Inside the beast: mod_foobar
●   The alternative was ditching all of CGI.
●   Code moved inside the server itself.
    –   Apache created the mod_<thingy> interfaces.
    –   This allowed the code a low-level view of the request
        and server state to process its requests.
    –   For example: mod_perl.
●   And things seemed good, for a while...
Be careful what you ask for!
●   We have probably all dealt with mod_perl by now:
    –   Once you are inside the beast, you have to deal with it.
    –   All of it.
●   Do you really enjoy dealing with circular
    documentation, fragmentation of objects, details of
    the HTTP lifecycle within Apache? Then have fun!
●   mod_perl code is also largely non-portable.
    –   Even upgrading Apache can cause major headaches.
The search for a better way
●   Hardware and O/S performance have improved
    since 80486's were “modern”.
●   We've also learned a few things about how to
    design objects.
●   This led to multiple approaches for layers between
    apache internals and the request handler code.
●   All of them encapsulate specifics of the server.
    –   Avoid all of us re-inventing the interface wheel.
More than one way to do it...
●   Catalyst is one approach.
●   Python & Ruby took another approach with WSGI
    & Rack.
●   Tatsuhiko Miyagawa developed Perl Web Server
    Gateway Interface (PSGI) and Plack.
    –   Note that PSGI is not Plack.
Example: PSGI
                              my $app
                              = sub
●   Environment arrives as    {
    an argument.                  my $env = shift;
                                  return
●   Return                        [
                                      200,
    [status, header, body ]           [
                                         'Content­Type', 
                                         'text/plain'
    to caller for response.           ],
                                      [
●   Note these are                        'HelloWorld'
    arrayrefs, not hashes.            ],
                                  ]
                              };
A few nice things
●   The encapsulated source “$env” is limited to the
    current request.
    –   Less likely to get polluted or contain extraneous values
        than %ENV in CGI.
    –   Return values are server and language agnostic.
Meanwhile, back at the server...
●   Plack::Handler provides the interface from PSGI to
    the server internals.
    –   This includes modules for Apache, FCGI, Starman
        (Unicorn.rb).
●   There are also stand-alone Perly servers
    –   Twiggy Non-blocking, AnyEvent.
    –   Dancer Tries to simplify things.
    –   Starlet   Simpler server.
    –   plackup Just runs your code – comes with plack.
What does this mean to you?
●   Ever try to debug mod_perl code with printf?
●   What if your server were pure perl, executable with
    “perl -d ...”?
    –   You could fondle the structures interactively.
    –   Hardwire breakpoints.
    –   Fix things a whole lot faster...
●   perl -d plackup /path/to/your/module;
Example: Dancer
●   Callbacks added by location.
                                   #!/bin/env perl
●   Return the content with
    options for headers.           use Dancer;
●   That's about all you need.     get '/' =>
                                   sub
                                   {
                                      'Hello World'
                                   };

                                   dance;
Catalyst can also handle PSGI
use My::Catalyst::App;

My::Catalyst::App­>
setup_engine( 'PSGI' );

my $app = sub
{
   My::Catalyst::App­>run( @_ )
};
What Plack gets you
●   Plack::Handler      What your app sees.
●   plackup             Command-line startup.
●   Plack::Loader         Autoload plack servers
●   Plack::Middleware   PSGI Middleware
●   Plack::Builder      OO Layer under middleware
●   Plack::Apps
●   Plack::Test
Simplest case: plackup
# read your app from app.psgi file

  plackup

# choose .psgi file from ARGV[0] (or with ­a option)
  plackup hello.psgi

# switch server implementation with ­­server (or 
­s)
  plackup ­­server HTTP::Server::Simple ­­port 9090 

  ­­host 127.0.0.1 test.psgi

# use UNIX socket to run FCGI daemon
  plackup ­s FCGI ­­listen /tmp/fcgi.sock myapp.psgi

# launch FCGI external server on port 9090
  plackup ­s FCGI ­­port 9090
Having it both ways: #! or plackup
                           if( caller )
                           {
●   Debugging or               # plackup, twiggy, etc.
    testing are simpler        $server
    from code run via      }
                           else
    perl -d.               {
                               # standalone application
●   PSGI servers are
    better for real use.       require Plack::Runner;

●   Have both:                 my $run = Plack::Runner­>new;

    Without a caller           $run­>parse_options( @ARGV );
    this runs itself.          $run­>run( $server );
                           }
Server code is simple
●   With only $env to worry about, extracting the
    request is easy.
●   Standard errors can be canned.
●   Even the headers are largely re-usable.
●   Switches on $env offer simple handler branching.
my $server
= sub
{
$DB::single = 1;

   my $env     = shift;
    
   given( $env )
   {
      when( 'fasta' )
      {
         return
        [
            # hand back javascript for viewing W­curve
           200,
           $canned_hdrz{ js },
           $wc­>read_seq( $env­>{ fasta } )­>format
        ]
      }

         ...
         return [ 200, [], ['Unhandled Request'] ]
     }
};
Summary
●   PSGI & Plack bring back the simplicity and
    portability of CGI.
    –   Flexible enough to support a variety of frameworks
        above it.
    –   Portable enough to run on any server.
●   Check the references for lots of examples.
References
 The main Plack site:

 http://plackperl.org/

Tatsuhiko Miyagawa has good documentation for Plack along with the modules:

http://search.cpan.org/~miyagawa/
Leo Lapworth has multiple Slideshare items about Plack:

http://www.slideshare.net/ranguard/plack­basics­for­
perl­websites­yapceu­2011

Article: Catalyst 5.9: (Less Code, More Plack!)

http://jjnapiorkowski.typepad.com/modern­
perl/2011/08/catalyst­59­less­code­more­plack.html

Contenu connexe

Tendances

Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Workhorse Computing
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationWorkhorse Computing
 
PHP traits, treat or threat?
PHP traits, treat or threat?PHP traits, treat or threat?
PHP traits, treat or threat?Nick Belhomme
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101hendrikvb
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsMark Baker
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlordsheumann
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLsAugusto Pascutti
 
A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webWallace Reis
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHPNick Belhomme
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojobpmedley
 
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPIPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPGuilherme Blanco
 
Php 7 hhvm and co
Php 7 hhvm and coPhp 7 hhvm and co
Php 7 hhvm and coPierre Joye
 
Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Puppet
 

Tendances (20)

Metadata-driven Testing
Metadata-driven TestingMetadata-driven Testing
Metadata-driven Testing
 
Getting testy with Perl
Getting testy with PerlGetting testy with Perl
Getting testy with Perl
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 
Memory Manglement in Raku
Memory Manglement in RakuMemory Manglement in Raku
Memory Manglement in Raku
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
 
Effective Benchmarks
Effective BenchmarksEffective Benchmarks
Effective Benchmarks
 
PHP traits, treat or threat?
PHP traits, treat or threat?PHP traits, treat or threat?
PHP traits, treat or threat?
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
 
A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento web
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHP
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
 
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPIPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
 
Php 7 hhvm and co
Php 7 hhvm and coPhp 7 hhvm and co
Php 7 hhvm and co
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...
 

Similaire à Get your teeth into Plack

Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversTatsuhiko Miyagawa
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principlesPerl Careers
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with PuppetKris Buytaert
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpmsom_nangia
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpmwilburlo
 
(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systemssosorry
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby TeamArto Artnik
 
Start tracking your ruby infrastructure
Start tracking your ruby infrastructureStart tracking your ruby infrastructure
Start tracking your ruby infrastructureSergiy Kukunin
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with PuppetKris Buytaert
 
Plack basics for Perl websites - YAPC::EU 2011
Plack basics for Perl websites - YAPC::EU 2011Plack basics for Perl websites - YAPC::EU 2011
Plack basics for Perl websites - YAPC::EU 2011leo lapworth
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotClouddaoswald
 
[HKOSCON][20200613][ Ansible: From VM to Kubernetes]
[HKOSCON][20200613][ Ansible: From VM to Kubernetes][HKOSCON][20200613][ Ansible: From VM to Kubernetes]
[HKOSCON][20200613][ Ansible: From VM to Kubernetes]Wong Hoi Sing Edison
 

Similaire à Get your teeth into Plack (20)

PSGI/Plack OSDC.TW
PSGI/Plack OSDC.TWPSGI/Plack OSDC.TW
PSGI/Plack OSDC.TW
 
Plack at YAPC::NA 2010
Plack at YAPC::NA 2010Plack at YAPC::NA 2010
Plack at YAPC::NA 2010
 
Plack - LPW 2009
Plack - LPW 2009Plack - LPW 2009
Plack - LPW 2009
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
Plack at OSCON 2010
Plack at OSCON 2010Plack at OSCON 2010
Plack at OSCON 2010
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
 
Nodejs
NodejsNodejs
Nodejs
 
(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems
 
NodeJS
NodeJSNodeJS
NodeJS
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
Start tracking your ruby infrastructure
Start tracking your ruby infrastructureStart tracking your ruby infrastructure
Start tracking your ruby infrastructure
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with Puppet
 
Plack basics for Perl websites - YAPC::EU 2011
Plack basics for Perl websites - YAPC::EU 2011Plack basics for Perl websites - YAPC::EU 2011
Plack basics for Perl websites - YAPC::EU 2011
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotCloud
 
Beyond Puppet
Beyond PuppetBeyond Puppet
Beyond Puppet
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 
[HKOSCON][20200613][ Ansible: From VM to Kubernetes]
[HKOSCON][20200613][ Ansible: From VM to Kubernetes][HKOSCON][20200613][ Ansible: From VM to Kubernetes]
[HKOSCON][20200613][ Ansible: From VM to Kubernetes]
 

Plus de Workhorse Computing

Wheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWorkhorse Computing
 
Paranormal statistics: Counting What Doesn't Add Up
Paranormal statistics: Counting What Doesn't Add UpParanormal statistics: Counting What Doesn't Add Up
Paranormal statistics: Counting What Doesn't Add UpWorkhorse Computing
 
Generating & Querying Calendar Tables in Posgresql
Generating & Querying Calendar Tables in PosgresqlGenerating & Querying Calendar Tables in Posgresql
Generating & Querying Calendar Tables in PosgresqlWorkhorse Computing
 
The W-curve and its application.
The W-curve and its application.The W-curve and its application.
The W-curve and its application.Workhorse Computing
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Workhorse Computing
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Workhorse Computing
 
Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Workhorse Computing
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Workhorse Computing
 
Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium Workhorse Computing
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Workhorse Computing
 

Plus de Workhorse Computing (18)

Wheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility Modules
 
mro-every.pdf
mro-every.pdfmro-every.pdf
mro-every.pdf
 
Paranormal statistics: Counting What Doesn't Add Up
Paranormal statistics: Counting What Doesn't Add UpParanormal statistics: Counting What Doesn't Add Up
Paranormal statistics: Counting What Doesn't Add Up
 
Generating & Querying Calendar Tables in Posgresql
Generating & Querying Calendar Tables in PosgresqlGenerating & Querying Calendar Tables in Posgresql
Generating & Querying Calendar Tables in Posgresql
 
The W-curve and its application.
The W-curve and its application.The W-curve and its application.
The W-curve and its application.
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
 
Neatly folding-a-tree
Neatly folding-a-treeNeatly folding-a-tree
Neatly folding-a-tree
 
Light my-fuse
Light my-fuseLight my-fuse
Light my-fuse
 
Paranormal stats
Paranormal statsParanormal stats
Paranormal stats
 
Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.
 
Putting some "logic" in LVM.
Putting some "logic" in LVM.Putting some "logic" in LVM.
Putting some "logic" in LVM.
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.
 
Selenium sandwich-2
Selenium sandwich-2Selenium sandwich-2
Selenium sandwich-2
 
Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium
 
Docker perl build
Docker perl buildDocker perl build
Docker perl build
 
Designing net-aws-glacier
Designing net-aws-glacierDesigning net-aws-glacier
Designing net-aws-glacier
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6
 

Dernier

Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Dernier (20)

Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

Get your teeth into Plack

  • 2. No! This is not a Listerine ad! ● Sorry, no jingle in the background. ● Plack is an interface for web request handlers. ● It simplifies the interface to a usable level. ● Permits more portable code. ● Allows you to focus on your content handler, not the API specs.
  • 3. In the beginning... ● Was CGI: – It was simple enough to implement. – Proved platform and language agnostic. – Lived outside of the server, with simple variables and print statements moving the data in and out of back-end code. – Became the standard for most work on the web.
  • 4. CGI has problems.  ● It was designed for shell-ish environments. – Each iteration of the site required re-launching the CGI “script” as a separate process. – This caused too much overhead to re-process the source code for every request. – Let alone the overhead of creating new processes, especially on non-*NIX systems. ● Fixes involved avoiding the re-processing and dodging CGI altogether.
  • 5. Inside the beast: mod_foobar ● The alternative was ditching all of CGI. ● Code moved inside the server itself. – Apache created the mod_<thingy> interfaces. – This allowed the code a low-level view of the request and server state to process its requests. – For example: mod_perl. ● And things seemed good, for a while...
  • 6. Be careful what you ask for! ● We have probably all dealt with mod_perl by now: – Once you are inside the beast, you have to deal with it. – All of it. ● Do you really enjoy dealing with circular documentation, fragmentation of objects, details of the HTTP lifecycle within Apache? Then have fun! ● mod_perl code is also largely non-portable. – Even upgrading Apache can cause major headaches.
  • 7. The search for a better way ● Hardware and O/S performance have improved since 80486's were “modern”. ● We've also learned a few things about how to design objects. ● This led to multiple approaches for layers between apache internals and the request handler code. ● All of them encapsulate specifics of the server. – Avoid all of us re-inventing the interface wheel.
  • 8. More than one way to do it... ● Catalyst is one approach. ● Python & Ruby took another approach with WSGI & Rack. ● Tatsuhiko Miyagawa developed Perl Web Server Gateway Interface (PSGI) and Plack. – Note that PSGI is not Plack.
  • 9. Example: PSGI my $app = sub ● Environment arrives as { an argument.     my $env = shift;     return ● Return     [         200, [status, header, body ]         [          'Content­Type',  'text/plain' to caller for response.         ],         [ ● Note these are             'HelloWorld' arrayrefs, not hashes.         ],     ] };
  • 10. A few nice things ● The encapsulated source “$env” is limited to the current request. – Less likely to get polluted or contain extraneous values than %ENV in CGI. – Return values are server and language agnostic.
  • 11. Meanwhile, back at the server... ● Plack::Handler provides the interface from PSGI to the server internals. – This includes modules for Apache, FCGI, Starman (Unicorn.rb). ● There are also stand-alone Perly servers – Twiggy Non-blocking, AnyEvent. – Dancer Tries to simplify things. – Starlet Simpler server. – plackup Just runs your code – comes with plack.
  • 12. What does this mean to you? ● Ever try to debug mod_perl code with printf? ● What if your server were pure perl, executable with “perl -d ...”? – You could fondle the structures interactively. – Hardwire breakpoints. – Fix things a whole lot faster... ● perl -d plackup /path/to/your/module;
  • 13. Example: Dancer ● Callbacks added by location. #!/bin/env perl ● Return the content with options for headers. use Dancer; ● That's about all you need. get '/' => sub { 'Hello World' }; dance;
  • 15. What Plack gets you ● Plack::Handler What your app sees. ● plackup Command-line startup. ● Plack::Loader Autoload plack servers ● Plack::Middleware PSGI Middleware ● Plack::Builder OO Layer under middleware ● Plack::Apps ● Plack::Test
  • 17. Having it both ways: #! or plackup if( caller ) { ● Debugging or     # plackup, twiggy, etc. testing are simpler     $server from code run via } else perl -d. {     # standalone application ● PSGI servers are better for real use.     require Plack::Runner; ● Have both:     my $run = Plack::Runner­>new; Without a caller     $run­>parse_options( @ARGV ); this runs itself.     $run­>run( $server ); }
  • 18. Server code is simple ● With only $env to worry about, extracting the request is easy. ● Standard errors can be canned. ● Even the headers are largely re-usable. ● Switches on $env offer simple handler branching.
  • 19. my $server = sub { $DB::single = 1; my $env     = shift;   given( $env ) { when( 'fasta' ) { return         [ # hand back javascript for viewing W­curve            200,            $canned_hdrz{ js },            $wc­>read_seq( $env­>{ fasta } )­>format         ] } ... return [ 200, [], ['Unhandled Request'] ] } };
  • 20. Summary ● PSGI & Plack bring back the simplicity and portability of CGI. – Flexible enough to support a variety of frameworks above it. – Portable enough to run on any server. ● Check the references for lots of examples.
  • 21. References The main Plack site: http://plackperl.org/ Tatsuhiko Miyagawa has good documentation for Plack along with the modules: http://search.cpan.org/~miyagawa/ Leo Lapworth has multiple Slideshare items about Plack: http://www.slideshare.net/ranguard/plack­basics­for­ perl­websites­yapceu­2011 Article: Catalyst 5.9: (Less Code, More Plack!) http://jjnapiorkowski.typepad.com/modern­ perl/2011/08/catalyst­59­less­code­more­plack.html