Your first website in under a minute with Dancer
Upcoming SlideShare
Loading in...5
×
 

Your first website in under a minute with Dancer

on

  • 3,412 views

Learn how to write your first website using Perl and Dancer in under a minute!

Learn how to write your first website using Perl and Dancer in under a minute!

This is a lightning talk given at a Tel Aviv Perl Mongers (TA.pm) group meeting.

Statistics

Views

Total Views
3,412
Views on SlideShare
3,411
Embed Views
1

Actions

Likes
2
Downloads
16
Comments
0

1 Embed 1

http://orhowilearnedtolovetheperl.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Your first website in under a minute with Dancer Your first website in under a minute with Dancer Presentation Transcript

  • Lets create a website!
  • Lets find an interesting module● Go to CPAN● Search for something funny in Text::● We found Text::UpsideDown● It turns text upside down!● OMGZ0x0ztrzzzz11!
  • Text::UpsideDown use Text::UpsideDown; my $text   = “Hello world!”; my $updown = upside_down($text);● Okay, thats pretty simple
  • Installing Dancer
  • Installing Dancer
  • Creating the skeleton● Dancer installs an app called “dancer”● Run it to create a directory structure● Pretty default design for free!
  • Adding code● Edit main path in lib/UpsideDown.pm # default path get / => sub {   # code to run when someone goes   # to the main page };
  • Adding code● Suppose we get user text with a parameter● Use Dancers “params” to reach it● If its called “text”, all we have to do is... my $text = params­>{text};● Then to turn it upside down... my $updown = upside_down($text);
  • What do we have so far?● Someone reaches main page● We get text and turn it upside down use Text::UpsideDown; get / => sub {     my $text   = params­>{text};     my $updown = upside_down($text);     ... };
  • Rendering it● Render template “view/index.tt”● Send it the original text and the upside down template index => {     text       => $text,     upsidedown => $updown, };
  • Putting it all togetheruse Text::UpsideDown;get / => sub {  my $text = params­>{text};  my $updown = upside_down($text);  template index => {    text       => $text,    upsidedown => $updown,  };};
  • Now the template● Edit index.tt file● Add a form to send text● Add a text input to write the text● Display the upside down text● Provide a button to submit more text● …● Profit!
  • Creating a form<form method=”post”> <!-- stuff goes here --></form>
  • Adding a text input box<form method=”post”><input type=”text” name=”text” value=”<% text | html %>” /></form>
  • Adding upside down text<form method=”post”><input type=”text” name=”text” value=”<% text | html %>” /><code><% upsidedown | html %></code></form>
  • Add button to submit form<form method=”post”><input type=”text” name=”text” value=”<% text | html %>” /><code><% upsidedown | html %></code><input type=”submit” value=”Upside Down!” /></form>
  • Hit it!
  • upsidedown.casa.darkpan.com
  • Dancer available @ http://perldancer.org Credit: Marco Fontani (http://darkpan.com)