HTML::Mason by example

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

  • + chorny chorny 3 years ago
    IMHO Mason can be considered OOP for templates

Post a comment
Embed Video
Edit your comment Cancel

2 Favorites & 2 Groups

HTML::Mason by example - Presentation Transcript

  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 \"\\.html$\"> 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 = \"World\"; Hello, <% $planet %>! Saturday 27 October 2007 11
  12. output Hello, World! Saturday 27 October 2007 12
  13. Greetings, <% (\"Earthlings\", \"Martians\")[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=\"#CCFFCC\"> Saturday 27 October 2007 17
  18. footer.mas <center><a href=\"/\">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 => \"Wally World Home\" &> 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=\"#CCFFCC\"> <center><h1><% $head %></h1></center> Saturday 27 October 2007 21
  22. autohandler <html> <head> <title><% $m->base_comp->attr('head') %></title> </head> <body bgcolor=\"#CCFFCC\"> <center> <h1><% $m->base_comp->attr('head') %></h1> </center> % $m->call_next; <center><a href=\"/\">Home</a></center> </body></html> Saturday 27 October 2007 22
  23. mainpage.html <%attr> head => \"Wally World Home\" </%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
  28. http://masonhq.com/ Saturday 27 October 2007 28
  29. http://masonbook.com/ Saturday 27 October 2007 29
  30. thank you Saturday 27 October 2007 30

+ chrisvchrisv, 3 years ago

custom

3224 views, 2 favs, 2 embeds more stats

Mason is a powerful, robust and proven templating s more

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 3224
    • 3221 on SlideShare
    • 3 from embeds
  • Comments 1
  • Favorites 2
  • Downloads 70
Most viewed embeds
  • 2 views on http://bipmoldo.bipmoldova.com
  • 1 views on http://localhost

more

All embeds
  • 2 views on http://bipmoldo.bipmoldova.com
  • 1 views on http://localhost

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories

Groups / Events