Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Glen Hinkle
file 41 lines (29 sloc) 0.901 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
package MojoFull;
use Mojo::Base 'Mojolicious';
use Schema;

has schema => sub {
  return Schema->connect('dbi:SQLite:' . ($ENV{TEST_DB} || 'test.db'));
};

# This method will run once at server start
sub startup {
  my $self = shift;

  $self->helper(db => sub { $self->app->schema });

  # Routes
  my $r = $self->routes;

  $r->add_condition(

    # Requested id is a photoset?
    photoset => sub {
      my ($r, $c, $captures, $pattern) = @_;

      my $id = $captures->{id};
      return 1 if $id !~ /^\d+$/ or $id =~ /^\d+$/ and length $id == 17;
    }
  );

  $r->get('/')->to('home#index');

  $r->get('/photos')->to('photos#index');
  $r->get('/photos/:id')->over('photoset')->to('photos#show_set');
  $r->get('/photos/:id')->to('photos#show');

  $r->get('/blogs')->to('blogs#index');
  $r->get('/blogs/(:name)')->to('blogs#show');
  $r->get('/blogs/tag/(*tags)')->to('blogs#index');
}

1;
Something went wrong with that request. Please try again.