SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie HTML::Mason by example

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
 

Ähnlich wie HTML::Mason by example (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
 

Kürzlich hochgeladen

Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 

Kürzlich hochgeladen (20)

Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 

HTML::Mason by example

  • 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