MobaSiF::Template Introduction

3,448 views
3,368 views

Published on

MobaSiF::Template introduction on YAPC::Asia 2009 at 2009.09.10

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,448
On SlideShare
0
From Embeds
0
Number of Embeds
453
Actions
Shares
0
Downloads
14
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

MobaSiF::Template Introduction

  1. 1. MobaSiF::Template DeNA - Tadashi Matsuda - bobpp bobpp+yapc@bobpp.jp YAPC::Asia 2009 - 2009.09.10
  2. 2. • • MobaSiF::Template / • • •
  3. 3. • ( ) • bobpp ( ) • http://bobpp.jp/ •( ) • (http://mbok.jp)
  4. 4. YAPC! • YAPC • •
  5. 5. Check this! •Twitter: BoBpp •
  6. 6. MobaSiF
  7. 7. Moba* Simple Framework
  8. 8. Moba* • • 2003 • •5 PV/day • and more...
  9. 9. Moba* Simple Framework
  10. 10. Mobile Simple Framework
  11. 11. YAPC::Asia 2008
  12. 12. MobaSiF::Template
  13. 13. MTemplate • MobaSiF::Template • MobaSiF •
  14. 14. MobaSiF::Template • (MobaSiF::*) • github • CPAN • •
  15. 15. • • MobaSiF::Template • • MobaSiF::Template::Compiler •
  16. 16. HTML Template (*.html)
  17. 17. HTML Template (*.html) MobaSiF::Template::PreCompiler MobaSiF:::Template::Compiler precompile compile Include Template (*.txt/html)
  18. 18. HTML Compiled Template Template (*.html) (*.bin) MobaSiF::Template::PreCompiler MobaSiF:::Template::Compiler precompile compile Include Template (*.txt/html)
  19. 19. HTML Compiled Template Template (*.html) (*.bin) MobaSiF::Template::PreCompiler MobaSiF:::Template::Compiler MobaSiF::Template precompile compile insert / render Include Output Template (*.html) (*.txt/html)
  20. 20. HTML HTML Compiled HTML HTML Template Template Template Template Template (*.html) (*.html) (*.bin) (*.html) (*.html) MobaSiF::Template::PreCompiler MobaSiF:::Template::Compiler MobaSiF::Template precompile compile insert / render Include Output Template Compile Command (*.html) (*.txt/html)
  21. 21. • • • • • • URL Encode •
  22. 22. $ cpan cpan> install MobaSiF::Template
  23. 23. < : > <!-- Escape --> $=h:escape_string$ <!-- Escape (bypass) --> $=b:not_escape_data$ <!-- URL Encode --> $=e:url_encode_string$
  24. 24. < : > $ if (val > 10) { $ val 10 $ } elsif (val > 5) { $ val 5 $ } else { $ val 5 $}$
  25. 25. < : > $ loop (list) { $ $=h:id$ / $=h:key$ / $=h:value$ $}$
  26. 26. < > use MobaSiF::Template::Compiler; MobaSiF::Template::Compiler::compile( “/path/to/template_file.html”, “/path/to/compiled_binary_file.bin” );
  27. 27. < > use MobaSiF::Template; my $param = +{ hoge => 1, fuga => [ +{ id => 1, value => ‘A’ }, +{ id => 2, value => ‘B’ }, ] }; print MobaSiF::Template::insert( “/path/to/compiled_binary_file.bin”, $param);
  28. 28. use MobaSiF::Template; my $param = +{...}; $MobaSiF::Template::DEVELOP = 1; print MobaSiF::Template::render( “/path/to/template_file.html”, “/path/to/compiled_binary_file.bin”, $param);
  29. 29. use MobaSiF::Template; 0 my $param = +{...}; $MobaSiF::Template::DEVELOP = 1; print MobaSiF::Template::render( “/path/to/template_file.html”, “/path/to/compiled_binary_file.bin”, $param);
  30. 30. use MobaSiF::Template; 1 down 0 my $param = +{...}; $MobaSiF::Template::DEVELOP = 1; print MobaSiF::Template::render( “/path/to/template_file.html”, “/path/to/compiled_binary_file.bin”, $param);
  31. 31. Benchmark! <Rivals> • Template Toolkit • Tenjin • HTML::Template::Pro • MobaSiF::Template
  32. 32. Benchmark • / • 10,000 qps
  33. 33. Machine • MacBook • OS X 10.5 Leopard • perl v.5.8.9 • 2.4GHz Core2 Duo • 4GB Memory
  34. 34. Result. Benchmark#1
  35. 35. Result. Benchmark#1 0 5000.00 10000.00 15000.00 20000.00 Template Toolkit 585.8 Tenjin 2421.3 HTML::Template::Pro 6451.6 MobaSiF::Template 17543.9
  36. 36. binary template / XS
  37. 37. binary template • (option)... • • XS
  38. 38. XS • mmap •
  39. 39. NULL
  40. 40. PLAIN REPLACE IF/ELSE LOOP / etc. NULL
  41. 41. • • View(Template) =
  42. 42. • Pre-Compiler • Mobile Pre-Compiler • compile files command • tests! •
  43. 43. • •
  44. 44. CPAN / github • http://search.cpan.org/~bobpp/MobaSiF- Template/ • http://github.com/bobpp/perl-MobaSiF- Template/

×