Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: changing title of a webpage dynamically ( Mojolicious::Lite Time::Piece )

by Anonymous Monk
on Jun 07, 2013 at 08:36 UTC ( #1037627=note: print w/replies, xml ) Need Help??


in reply to changing title of a webpage dynamically

Using Mojolicious::Lite and its templating system

#!/usr/bin/perl -- use strict; use warnings; use Time::Piece; use Time::Seconds(); use Mojolicious::Lite; ## flips on strict/warnings sub date_time_mojo { my $self = shift; my $dir = $self->param('dir'); my $today = $self->param('today'); my $thismonth = $self->param('thismonth'); my $thisyear = $self->param('thisyear'); my $time ; if( $dir and $today and $thismonth ){ $time = Time::Piece->strptime("$today $thismonth $thisyear", ' +%d %m %Y'); if( lc $dir eq 'yesterday'){ $time -= Time::Seconds::ONE_DAY() ; } else { $time += Time::Seconds::ONE_DAY() ; } } else { $time = gmtime; } $self->render( t => $time, title => $time->ymd, ); } get '/' => \&date_time_mojo => 'index';; app->start; __DATA__ @@ index.html.ep % layout 'green'; %= content content => begin <%== $t->ymd %> <form name="input" method="GET"> <input type="hidden" name="today" value="<%== $t->mday %>"> <input type="hidden" name="thismonth" value="<%== $t->mon %>"> <input type="hidden" name="thisyear" value="<%== $t->year %>"> <input type="submit" name="dir" value="Yesterday"></td> <input type="submit" name="dir" value="Tomorrow"></td> </form> % end @@ layouts/green.html.ep <!DOCTYPE html> <html> <head><title><%== title %></title></head> <body bgcolor='lightgreen'><%= content %></body> </html>

Here is how you can test this from cli for today

$ perl fudge get / [Fri Jun 7 01:31:06 2013] [debug] Your secret passphrase needs to be +changed!!! [Fri Jun 7 01:31:06 2013] [debug] GET / (Mojolicious (Perl)). [Fri Jun 7 01:31:06 2013] [debug] Routing to a callback. [Fri Jun 7 01:31:06 2013] [debug] Rendering template "index.html.ep" +from DATA section. [Fri Jun 7 01:31:06 2013] [debug] Rendering template "layouts/green.h +tml.ep" from DATA section. [Fri Jun 7 01:31:06 2013] [debug] 200 OK (0.055773s, 17.930/s). <!DOCTYPE html> <html> <head><title>2013-06-07</title></head> <body bgcolor='lightgreen'> 2013-06-07 <form name="input" method="GET"> <input type="hidden" name="today" value="7"> <input type="hidden" name="thismonth" value="6"> <input type="hidden" name="thisyear" value="2013"> <input type="submit" name="dir" value="Yesterday"></td> <input type="submit" name="dir" value="Tomorrow"></td> </form> </body> </html>

Here is how you can test this from cli for tomorrow

$ perl fudge get /?today=7;thismonth=6;thisyear=2013;dir=Tomorrow [Fri Jun 7 01:32:20 2013] [debug] Your secret passphrase needs to be +changed!!! [Fri Jun 7 01:32:20 2013] [debug] GET / (Mojolicious (Perl)). [Fri Jun 7 01:32:20 2013] [debug] Routing to a callback. [Fri Jun 7 01:32:20 2013] [debug] Rendering template "index.html.ep" +from DATA section. [Fri Jun 7 01:32:20 2013] [debug] Rendering template "layouts/green.h +tml.ep" from DATA section. [Fri Jun 7 01:32:20 2013] [debug] 200 OK (0.058046s, 17.228/s). <!DOCTYPE html> <html> <head><title>2013-06-08</title></head> <body bgcolor='lightgreen'> 2013-06-08 <form name="input" method="GET"> <input type="hidden" name="today" value="8"> <input type="hidden" name="thismonth" value="6"> <input type="hidden" name="thisyear" value="2013"> <input type="submit" name="dir" value="Yesterday"></td> <input type="submit" name="dir" value="Tomorrow"></td> </form> </body> </html>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1037627]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2022-01-20 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (56 votes). Check out past polls.

    Notices?