get '/blogs' => sub { shift->redirect_to('/blogs/tag/personal'); }; get '/blogs/tag/(*tags)' => sub { my $self = shift; # Specified tags to search for: /tag/one/tag/two/tag/three my @tags = grep $_ ne 'tag' => split '/' => $self->param('tags'); my @blogs = $self->db->resultset('Blog')->by_tags(@tags) or return $self->redirect_to('/blogs'); $self->render('blogs/index', blogs => [@blogs],); }; get '/blogs/(:name)' => sub { my $self = shift; my $param = $self->stash('name'); my $blog = $self->db->resultset('Blog')->by_id_or_name($param) or return $self->redirect_to('/blogs'); $self->render('blogs/show', blog => $blog); }; get '/photos' => sub { my $self = shift; $self->render( 'photos/index', sets => [$self->db->resultset('Photoset')->search], photo_count => $self->db->resultset('Photo')->count ); }; get '/photos/:id' => (photoset => '') => sub { my $self = shift; my $id = $self->param('id'); my $set = $self->db->resultset('Photoset')->by_id_or_name($id) or $self->redirect_to("/photos"), return; $self->render(template => 'photos/show_set', set => $set); }; get '/photos/:id' => sub { my $self = shift; my $id = $self->param('id'); my $photo = $self->db->resultset('Photo')->find($id) or $self->redirect_to("/photos"), return; $self->render(template => 'photos/show', photo => $photo); }; app->start; __DATA__ @@ layouts/default.html.ep <!doctype html> <html> <head> <link rel="stylesheet" type="text/css" media="screen" href="/css/main.css" /> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-29402272-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> </head> <body> <div id="header"> <img class="profile" src="/images/bender_promo.png" /> <a class="home" href="/" alt="Home"></a> % if ($self->req->url ne '/') { <div class="fb_status"> <span class="load statii"></span> <span class="time_since"></span> <span class="source"></span> </div> % } <ul class="toc"> <li><a href="/blogs">Blog</a></li> <li><a href="/photos">Photos</a></li> </ul> </div> <div id="main"> <div id="box-top"></div> <div id="content"> <%= content %> </div> # Requested id is a photoset? app->routes->add_condition( photoset => sub { my ($r, $c, $captures, $pattern) = @_; my $id = $captures->{id}; return 1 if $id !~ /^\d+$/ or $id =~ /^\d+$/ and length $id == 17; } ); helper db => sub { return Schema->connect('dbi:SQLite:' . ($ENV{TEST_DB} || 'test.db')); }; get '/' => sub { shift->render('home/index'); }; get '/blogs' => sub { shift->redirect_to('/blogs/tag/personal'); }; get '/blogs/tag/(*tags)' => sub { my $self = shift; # Specified tags to search for: /tag/one/tag/two/tag/three my @tags = grep $_ ne 'tag' => split '/' => $self->param('tags'); my @blogs = $self->db->resultset('Blog')->by_tags(@tags) or return $self->redirect_to('/blogs'); $self->render('blogs/index', blogs => [@blogs],); }; get '/blogs/(:name)' => sub { my $self = shift; my $param = $self->stash('name'); my $blog = $self->db->resultset('Blog')->by_id_or_name($param) or return $self->redirect_to('/blogs'); $self->render('blogs/show', blog => $blog); }; get '/photos' => sub { my $self = shift; $self->render( 'photos/index', sets => [$self->db->resultset('Photoset')->search], photo_count => $self->db->resultset('Photo')->count ); };#!/usr/bin/env perl use Mojolicious::Lite; #!/usr/bin/env perl use Mojolicious::Lite; use lib 'lib'; use Schema; # Requested id is a photoset? app->routes->add_condition( photoset => sub { my ($r, $c, $captures, $pattern) = @_; my $id = $captures->{id}; return 1 if $id !~ /^\d+$/ or $id =~ /^\d+$/ and length $id == 17; } ); my $ua = Mojo::UserAgent->new; my $res = $ua->get('search.twitter.com/search.json?q=mojolicious') ->res->json(‘/results/0/text’); get '/' => sub { shift->render('home/index'); }; get '/blogs' => sub { shift->redirect_to('/blogs/tag/personal'); }; get '/blogs/tag/(*tags)' => sub { my $self = shift; # Specified tags to search for: /tag/one/tag/two/tag/three my @tags = grep $_ ne 'tag' => split '/' => $self->param('tags'); my @blogs = $self->db->resultset('Blog')->by_tags(@tags) or return $self->redirect_to('/blogs'); $self->render('blogs/index', blogs => [@blogs],); }; get '/blogs/(:name)' => sub { my $self = shift; my $param = $self->stash('name'); my $blog = $self->db->resultset('Blog')->by_id_or_name($param) or return $self->redirect_to('/blogs'); $self->render('blogs/show', blog => $blog); }; get '/photos' => sub { my $self = shift; get '/blogs/tag/(*tags)' => sub { my $self = shift; # Specified tags to search for: /tag/one/tag/two/tag/three my @tags = grep $_ ne 'tag' => split '/' => $self->param('tags'); my @blogs = $self->db->resultset('Blog')->by_tags(@tags) or return $self->redirect_to('/blogs'); $self->render('blogs/index', blogs => [@blogs],); }; get '/blogs/(:name)' => sub { my $self = shift; my $param = $self->stash('name'); my $blog = $self->db->resultset('Blog')->by_id_or_name($param) or return $self->redirect_to('/blogs'); $self->render('blogs/show', blog => $blog); }; get '/photos' => sub { my $self = shift; $self->render( 'photos/index', sets => [$self->db->resultset('Photoset')->search], photo_count => $self->db->resultset('Photo')->count ); }; get '/photos/:id' => (photoset => '') => sub { my $self = shift; my $id = $self->param('id'); my $set = $self->db->resultset('Photoset')->by_id_or_name($id) or $self->redirect_to("/photos"), return; $self->render(template => 'photos/show_set', set => $set); }; get '/photos/:id' => sub { my $self = shift; my $id = $self->param('id'); my $photo = $self->db->resultset('Photo')->find($id) or $self->redirect_to("/photos"), return; $self->render(template => 'photos/show', photo => $photo); }; app->start; __DATA__ @@ layouts/default.html.ep <!doctype html> <html> <head> <link rel="stylesheet" type="text/css" media="screen" href="/css/main.css" /> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-29402272-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> </head> <body> <div id="header"> <img class="profile" src="/images/bender_promo.png" /> <a class="home" href="/" alt="Home"></a> % if ($self->req->url ne '/') { <div class="fb_status"> <span class="load statii"></span> <span class="time_since"></span> <span class="source"></span> </div> % } <ul class="toc"> <li><a href="/blogs">Blog</a></li> <li><a href="/photos">Photos</a></li> </ul> </div> <div id="main"> <div id="box-top"></div> <div id="content"> <%= content %> </div> <div id="box-bottom"></div> </div> <div id="footer"> <ul> <li><a href="http://mojolicio.us">Mojolicious</a></li> <li><a href="http://mojocasts.com">Mojocasts</a></li> <li><a href="http://github.com/tempire/mojoexample">Mojo Example</a></li> <li><a href="http://github.com/kraih/mojo">Github</a></li> my $ua = Mojo::UserAgent->new; my $res = $ua->get('search.twitter.com/search.json?q=mojolicious') ->res->json(‘/results/0/text’); use Schema; # Requested id is a photoset? app->routes->add_condition( photoset => sub { my ($r, $c, $captures, $pattern) = @_; my $id = $captures->{id}; return 1 if $id !~ /^\d+$/ or $id =~ /^\d+$/ and length $id == 17; } ); helper db => sub { return Schema->connect('dbi:SQLite:' . ($ENV{TEST_DB} || 'test.db')); }; get '/' => sub { shift->render('home/index'); }; get '/blogs' => sub { shift->redirect_to('/blogs/tag/personal'); }; get '/blogs/tag/(*tags)' => sub { my $self = shift; # Specified tags to search for: /tag/one/tag/two/tag/three my @tags = grep $_ ne 'tag' => split '/' => $self->param('tags'); my @blogs = $self->db->resultset('Blog')->by_tags(@tags) or return $self->redirect_to('/blogs'); $self->render('blogs/index', blogs => [@blogs],); }; get '/blogs/(:name)' => sub { my $self = shift; my $param = $self->stash('name'); my $blog = $self->db->resultset('Blog')->by_id_or_name($param) or return $self->redirect_to('/blogs'); $self->render('blogs/show', blog => $blog); }; get '/photos' => sub { my $self = shift; $self->render( 'photos/index', sets => [$self->db->resultset('Photoset')->search], photo_count => $self->db->resultset('Photo')->count ); };#!/usr/bin/env perl use Mojolicious::Lite; #!/usr/bin/env perl use Mojolicious::Lite; use lib 'lib'; use Schema; # Requested id is a photoset? app->routes->add_condition( photoset => sub { my ($r, $c, $captures, $pattern) = @_; my $id = $captures->{id}; return 1 if $id !~ /^\d+$/ or $id =~ /^\d+$/ and length $id == 17; } ); helper db => sub { return Schema->connect('dbi:SQLite:' . ($ENV{TEST_DB} || 'test.db')); }; get '/' => sub { shift->render('home/index'); }; get '/blogs' => sub { shift->redirect_to('/blogs/tag/personal'); }; get '/blogs/tag/(*tags)' => sub { my $self = shift; # Specified tags to search for: /tag/one/tag/two/tag/three my @tags = grep $_ ne 'tag' => split '/' => $self->param('tags'); my @blogs = $self->db->resultset('Blog')->by_tags(@tags) or return $self->redirect_to('/blogs'); $self->render('blogs/index', blogs => [@blogs],); }; get '/blogs/(:name)' => sub { my $self = shift; my $param = $self->stash('name'); my $blog = $self->db->resultset('Blog')->by_id_or_name($param) or return $self->redirect_to('/blogs'); $self->render('blogs/show', blog => $blog); }; get '/photos' => sub { my $self = shift;