SlideShare une entreprise Scribd logo
1  sur  30
Télécharger pour lire hors ligne
HTML::Mason
                            by example
                                BPW2007
                              chrisv.cpan.org




Saturday 27 October 2007                        1
embed perl in text
                            (and then some)


Saturday 27 October 2007                        2
“alternatives”
                    • Text::Template & HTML::Template
                    • Template Toolkit
                    • Apache::ASP
                    • Embperl
                    • PHP
                    • ASP (ActiveState ActivePerl)
Saturday 27 October 2007                                3
building large
                           dynamic websites


Saturday 27 October 2007                      4
• Amazon
                           • IMDB
                           • del.icio.us
                           • DynDNS
                           • jobs.perl.org
                           • RT
Saturday 27 October 2007                     5
Apache + mod_perl
                    Apache2 + mod_perl2


Saturday 27 October 2007                  6
httpd.conf
                              #PerlModule Apache2::Compat
                           PerlModule HTML::Mason::ApacheHandler
                           <LocationMatch quot;.html$quot;>
                               SetHandler perl-script
                               PerlHandler HTML::Mason::ApacheHandler
                           </LocationMatch>




Saturday 27 October 2007                                                7
preload perl modules
                               startup.pl




Saturday 27 October 2007                      8
Apache integration
                               (objects)


Saturday 27 October 2007                        9
by example



Saturday 27 October 2007                10
sample “component”
                             % my $planet = quot;Worldquot;;
                             Hello, <% $planet %>!




Saturday 27 October 2007                               11
output

                           Hello, World!




Saturday 27 October 2007                   12
Greetings, <% (quot;Earthlingsquot;, quot;Martiansquot;)[rand 2] %>




Saturday 27 October 2007                                                    13
in-line perl sections
                                  <%perl>
                                my $noun = 'World';
                                my @time = localtime;
                               </%perl>
                               Hello <% $noun %>,
                               % if ( $time[2] < 12 ) {
                               good morning.
                               % } else {
                               good afternoon.
                               % }




Saturday 27 October 2007                                  14
Mason pushes the
                  boundaries of the term
                   “Templating System”


Saturday 27 October 2007                   15
“components”:
                           modular design
                              elements


Saturday 27 October 2007                    16
header.mas
                             <html>
                           <head>
                           <title>Welcome to Wally World!</title>
                           </head>
                           <body bgcolor=quot;#CCFFCCquot;>




Saturday 27 October 2007                                            17
footer.mas
                             <center><a href=quot;/quot;>Home</
                             a>
                           </center>
                           </body></html>




Saturday 27 October 2007                                  18
mainpage.html
                             <& header.mas &>

                           this is body text...

                           <& footer.mas &>




Saturday 27 October 2007                          19
mainpage.html
                      <& header.mas, head => quot;Wally World Homequot;
                      &>

                this is body text...

                <& footer.mas &>




Saturday 27 October 2007                                          20
header.mas
                     <%args>
                   $head
                   </%args>
                   <html>
                   <head>
                   <title><% $head %></title>
                   </head>
                   <body bgcolor=quot;#CCFFCCquot;>
                   <center><h1><% $head %></h1></center>




Saturday 27 October 2007                                   21
autohandler
                    <html>
                 <head>
                   <title><% $m->base_comp->attr('head') %></title>
                 </head>
                 <body bgcolor=quot;#CCFFCCquot;>
                 <center>
                 <h1><% $m->base_comp->attr('head') %></h1>
                 </center>
                 % $m->call_next;
                 <center><a href=quot;/quot;>Home</a></center>
                 </body></html>




Saturday 27 October 2007                                              22
mainpage.html
                    <%attr>
                     head => quot;Wally World Homequot;
                  </%attr>
                  this is body text...




Saturday 27 October 2007                          23
dhandlers
              e.g. http://myserver/newsfeeds/LocalNews/Story1



              /newsfeeds/LocalNews/Story1     => no such thing
              /newsfeeds/LocalNews/dhandler   => no such thing
              /newsfeeds/dhandler             => found! (search ends)
              /dhandler


              (The found dhandler would read “LocalNews/Story1”
              from $m->dhandler_arg and use it as a retrieval key
              into a database of stories)




Saturday 27 October 2007                                                24
components ~ subs
                   <%init>
                    my $ua = $r->header_in('User-Agent');
                    return ($ua =~ /Mozilla/i && $ua !~ /MSIE/i) ? 1 : 0;
                </%init>




Saturday 27 October 2007                                                    25
dhandlers vs autohandlers
                    •      use an autohandler when you have a set
                           of components to handle your pages and
                           you want to augment them with a
                           template/filter

                    •      use a dhandler when you want to create a
                           set of “virtual URLs” that don't correspond
                           to any actual components, or to provide
                           default behavior for a directory




Saturday 27 October 2007                                                 26
Mason Request Objects
                      Two global per-request objects are available to all components: $r
                      (provides a Perl API to current Apache request) and $m (provides a
                      Perl API to current Mason request)

                $r->uri                    # the HTTP request URI
                $r->content_type           # set or retrieve content-type

                $m->caller()        # returns the calling component
                $m->dhandler_arg() # returns url parts
                $m->redirect(URL, [HTTP status])




Saturday 27 October 2007                                                                   27
http://masonhq.com/



Saturday 27 October 2007                         28
http://masonbook.com/



Saturday 27 October 2007                  29
thank you



Saturday 27 October 2007               30

Contenu connexe

Tendances

History of jQuery
History of jQueryHistory of jQuery
History of jQueryjeresig
 
Testing Web Applications with GEB
Testing Web Applications with GEBTesting Web Applications with GEB
Testing Web Applications with GEBHoward Lewis Ship
 
Flex User Group - Skinning Presentation
Flex User Group - Skinning PresentationFlex User Group - Skinning Presentation
Flex User Group - Skinning Presentationjmwhittaker
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database JonesJohn David Duncan
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to NodejsGabriele Lana
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2zfconfua
 
Scala Frustrations
Scala FrustrationsScala Frustrations
Scala Frustrationstakezoe
 
Dance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkDance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkMichael Peacock
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统yiditushe
 
Data models in Angular 1 & 2
Data models in Angular 1 & 2Data models in Angular 1 & 2
Data models in Angular 1 & 2Adam Klein
 
AngularJS Tips&Tricks
AngularJS Tips&TricksAngularJS Tips&Tricks
AngularJS Tips&TricksPetr Bela
 
Ruby sittin' on the Couch
Ruby sittin' on the CouchRuby sittin' on the Couch
Ruby sittin' on the Couchlangalex
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuerydeimos
 
Joe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwrdeimos
 

Tendances (20)

History of jQuery
History of jQueryHistory of jQuery
History of jQuery
 
Testing Web Applications with GEB
Testing Web Applications with GEBTesting Web Applications with GEB
Testing Web Applications with GEB
 
Flex User Group - Skinning Presentation
Flex User Group - Skinning PresentationFlex User Group - Skinning Presentation
Flex User Group - Skinning Presentation
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2
 
Scala Frustrations
Scala FrustrationsScala Frustrations
Scala Frustrations
 
Dance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkDance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech Talk
 
Drupal, meet Assetic
Drupal, meet AsseticDrupal, meet Assetic
Drupal, meet Assetic
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统
 
Data models in Angular 1 & 2
Data models in Angular 1 & 2Data models in Angular 1 & 2
Data models in Angular 1 & 2
 
AngularJS Tips&Tricks
AngularJS Tips&TricksAngularJS Tips&Tricks
AngularJS Tips&Tricks
 
What is nodejs
What is nodejsWhat is nodejs
What is nodejs
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 
Play á la Rails
Play á la RailsPlay á la Rails
Play á la Rails
 
Ruby sittin' on the Couch
Ruby sittin' on the CouchRuby sittin' on the Couch
Ruby sittin' on the Couch
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuery
 
Joe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwr
 

Similaire à HTML::Mason by Example: Embed Perl in Text and Build Large Dynamic Websites

Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Kris Wallsmith
 
SilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript RefactoringSilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript RefactoringIngo Schommer
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmdiKlaus
 
070929 Ruby勉強会#5 Rails開発ツールガイド
070929 Ruby勉強会#5 Rails開発ツールガイド070929 Ruby勉強会#5 Rails開発ツールガイド
070929 Ruby勉強会#5 Rails開発ツールガイドTomoki Maeda
 
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFabio Akita
 
Introducing ruby on rails
Introducing ruby on railsIntroducing ruby on rails
Introducing ruby on railsPriceen
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redisjimbojsb
 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQueryRemy Sharp
 
20190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React201920190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React2019Makoto Mori
 
Open Source Saturday - How can I contribute to Ruby on Rails?
Open Source Saturday - How can I contribute to Ruby on Rails?Open Source Saturday - How can I contribute to Ruby on Rails?
Open Source Saturday - How can I contribute to Ruby on Rails?Pravin Mishra
 
Pitfalls to Avoid for Cascade Server Newbies by Lisa Hall
Pitfalls to Avoid for Cascade Server Newbies by Lisa HallPitfalls to Avoid for Cascade Server Newbies by Lisa Hall
Pitfalls to Avoid for Cascade Server Newbies by Lisa Hallhannonhill
 
Pourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirentPourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirentNicolas Ledez
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - IntroductionVagmi Mudumbai
 
Node.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseAaron Silverman
 
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyConsegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyFabio Akita
 
Deploying a simple Rails application with AWS Elastic Beanstalk
Deploying a simple Rails application with AWS Elastic BeanstalkDeploying a simple Rails application with AWS Elastic Beanstalk
Deploying a simple Rails application with AWS Elastic BeanstalkJulien SIMON
 
Cloud, Cache, and Configs
Cloud, Cache, and ConfigsCloud, Cache, and Configs
Cloud, Cache, and ConfigsScott Taylor
 
Performance & Responsive Web Design
Performance & Responsive Web DesignPerformance & Responsive Web Design
Performance & Responsive Web DesignZach Leatherman
 

Similaire à HTML::Mason by Example: Embed Perl in Text and Build Large Dynamic Websites (20)

Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
 
Assetic (Zendcon)
Assetic (Zendcon)Assetic (Zendcon)
Assetic (Zendcon)
 
SilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript RefactoringSilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript Refactoring
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmd
 
070929 Ruby勉強会#5 Rails開発ツールガイド
070929 Ruby勉強会#5 Rails開発ツールガイド070929 Ruby勉強会#5 Rails開発ツールガイド
070929 Ruby勉強会#5 Rails開発ツールガイド
 
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
 
Introducing ruby on rails
Introducing ruby on railsIntroducing ruby on rails
Introducing ruby on rails
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQuery
 
20190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React201920190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React2019
 
Open Source Saturday - How can I contribute to Ruby on Rails?
Open Source Saturday - How can I contribute to Ruby on Rails?Open Source Saturday - How can I contribute to Ruby on Rails?
Open Source Saturday - How can I contribute to Ruby on Rails?
 
Pitfalls to Avoid for Cascade Server Newbies by Lisa Hall
Pitfalls to Avoid for Cascade Server Newbies by Lisa HallPitfalls to Avoid for Cascade Server Newbies by Lisa Hall
Pitfalls to Avoid for Cascade Server Newbies by Lisa Hall
 
Pourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirentPourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirent
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 
Node.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash Course
 
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyConsegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
 
Deploying a simple Rails application with AWS Elastic Beanstalk
Deploying a simple Rails application with AWS Elastic BeanstalkDeploying a simple Rails application with AWS Elastic Beanstalk
Deploying a simple Rails application with AWS Elastic Beanstalk
 
Cloud, Cache, and Configs
Cloud, Cache, and ConfigsCloud, Cache, and Configs
Cloud, Cache, and Configs
 
Performance & Responsive Web Design
Performance & Responsive Web DesignPerformance & Responsive Web Design
Performance & Responsive Web Design
 

Dernier

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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Dernier (20)

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
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

HTML::Mason by Example: Embed Perl in Text and Build Large Dynamic Websites

  • 1. HTML::Mason by example BPW2007 chrisv.cpan.org Saturday 27 October 2007 1
  • 2. embed perl in text (and then some) Saturday 27 October 2007 2
  • 3. “alternatives” • Text::Template & HTML::Template • Template Toolkit • Apache::ASP • Embperl • PHP • ASP (ActiveState ActivePerl) Saturday 27 October 2007 3
  • 4. building large dynamic websites Saturday 27 October 2007 4
  • 5. • Amazon • IMDB • del.icio.us • DynDNS • jobs.perl.org • RT Saturday 27 October 2007 5
  • 6. Apache + mod_perl Apache2 + mod_perl2 Saturday 27 October 2007 6
  • 7. httpd.conf #PerlModule Apache2::Compat PerlModule HTML::Mason::ApacheHandler <LocationMatch quot;.html$quot;> SetHandler perl-script PerlHandler HTML::Mason::ApacheHandler </LocationMatch> Saturday 27 October 2007 7
  • 8. preload perl modules startup.pl Saturday 27 October 2007 8
  • 9. Apache integration (objects) Saturday 27 October 2007 9
  • 10. by example Saturday 27 October 2007 10
  • 11. sample “component” % my $planet = quot;Worldquot;; Hello, <% $planet %>! Saturday 27 October 2007 11
  • 12. output Hello, World! Saturday 27 October 2007 12
  • 13. Greetings, <% (quot;Earthlingsquot;, quot;Martiansquot;)[rand 2] %> Saturday 27 October 2007 13
  • 14. in-line perl sections <%perl> my $noun = 'World'; my @time = localtime; </%perl> Hello <% $noun %>, % if ( $time[2] < 12 ) { good morning. % } else { good afternoon. % } Saturday 27 October 2007 14
  • 15. Mason pushes the boundaries of the term “Templating System” Saturday 27 October 2007 15
  • 16. “components”: modular design elements Saturday 27 October 2007 16
  • 17. header.mas <html> <head> <title>Welcome to Wally World!</title> </head> <body bgcolor=quot;#CCFFCCquot;> Saturday 27 October 2007 17
  • 18. footer.mas <center><a href=quot;/quot;>Home</ a> </center> </body></html> Saturday 27 October 2007 18
  • 19. mainpage.html <& header.mas &> this is body text... <& footer.mas &> Saturday 27 October 2007 19
  • 20. mainpage.html <& header.mas, head => quot;Wally World Homequot; &> this is body text... <& footer.mas &> Saturday 27 October 2007 20
  • 21. header.mas <%args> $head </%args> <html> <head> <title><% $head %></title> </head> <body bgcolor=quot;#CCFFCCquot;> <center><h1><% $head %></h1></center> Saturday 27 October 2007 21
  • 22. autohandler <html> <head> <title><% $m->base_comp->attr('head') %></title> </head> <body bgcolor=quot;#CCFFCCquot;> <center> <h1><% $m->base_comp->attr('head') %></h1> </center> % $m->call_next; <center><a href=quot;/quot;>Home</a></center> </body></html> Saturday 27 October 2007 22
  • 23. mainpage.html <%attr> head => quot;Wally World Homequot; </%attr> this is body text... Saturday 27 October 2007 23
  • 24. dhandlers e.g. http://myserver/newsfeeds/LocalNews/Story1 /newsfeeds/LocalNews/Story1 => no such thing /newsfeeds/LocalNews/dhandler => no such thing /newsfeeds/dhandler => found! (search ends) /dhandler (The found dhandler would read “LocalNews/Story1” from $m->dhandler_arg and use it as a retrieval key into a database of stories) Saturday 27 October 2007 24
  • 25. components ~ subs <%init> my $ua = $r->header_in('User-Agent'); return ($ua =~ /Mozilla/i && $ua !~ /MSIE/i) ? 1 : 0; </%init> Saturday 27 October 2007 25
  • 26. dhandlers vs autohandlers • use an autohandler when you have a set of components to handle your pages and you want to augment them with a template/filter • use a dhandler when you want to create a set of “virtual URLs” that don't correspond to any actual components, or to provide default behavior for a directory Saturday 27 October 2007 26
  • 27. Mason Request Objects Two global per-request objects are available to all components: $r (provides a Perl API to current Apache request) and $m (provides a Perl API to current Mason request) $r->uri # the HTTP request URI $r->content_type # set or retrieve content-type $m->caller() # returns the calling component $m->dhandler_arg() # returns url parts $m->redirect(URL, [HTTP status]) Saturday 27 October 2007 27
  • 30. thank you Saturday 27 October 2007 30