Revision 231

Date:
2008/11/01 13:20:25
Author:
dpavlin
Revision Log:
Mojolicous skeleton

mojolicious generate app Frey::Mojo
Files:

Legend:

 
Added
 
Removed
 
Modified
  • branches/mojo/bin/frey

     
    1 #!/usr/bin/perl
    2
    3 # Copyright (C) 2008, Sebastian Riedel.
    4
    5 use strict;
    6 use warnings;
    7
    8 use FindBin;
    9
    10 use lib "$FindBin::Bin/lib";
    11 use lib "$FindBin::Bin/../lib";
    12 use lib "$FindBin::Bin/../../lib";
    13
    14 $ENV{MOJO_APP} = 'Frey::Mojo';
    15
    16 # Check if Mojo is installed
    17 eval 'use Mojolicious::Scripts';
    18 if ($@) {
    19 print <<EOF;
    20 It looks like you don't have the Mojo Framework installed.
    21 Please visit http://getmojo.kraih.com for detailed installation instructions.
    22
    23 EOF
    24 exit;
    25 }
    26
    27 # Start the script system
    28 my $scripts = Mojolicious::Scripts->new;
    29 $scripts->run(@ARGV);
  • branches/mojo/lib/Frey/Mojo.pm

     
    1 package Frey::Mojo;
    2
    3 use strict;
    4 use warnings;
    5
    6 use base 'Mojolicious';
    7
    8 # This method will run for each request
    9 sub dispatch {
    10 my ($self, $c) = @_;
    11
    12 # Try to find a static file
    13 $self->static->dispatch($c);
    14
    15 # Use routes if we don't have a response code yet
    16 $self->routes->dispatch($c) unless $c->res->code;
    17
    18 # Nothing found
    19 unless ($c->res->code) {
    20 $self->static->serve($c, '/404.html');
    21 $c->res->code(404);
    22 }
    23 }
    24
    25 # This method will run once at server start
    26 sub startup {
    27 my $self = shift;
    28
    29 # The routes
    30 my $r = $self->routes;
    31
    32 # Default route
    33 $r->route('/:controller/:action/:id')
    34 ->to(controller => 'example', action => 'welcome', id => 1);
    35 }
    36
    37 1;
  • branches/mojo/lib/Frey/Mojo/Example.pm

     
    1 package Frey::Mojo::Example;
    2
    3 use strict;
    4 use warnings;
    5
    6 use base 'Mojolicious::Controller';
    7
    8 # This is a templateless action
    9 sub test {
    10 my ($self, $c) = @_;
    11
    12 # Response object
    13 my $res = $c->res;
    14
    15 # Code
    16 $res->code(200);
    17
    18 # Headers
    19 $res->headers->content_type('text/html');
    20
    21 # Content
    22 my $url = $c->url_for;
    23 $url->path->parse('/index.html');
    24 $res->body(qq/<a href="$url">Forward to a static document.<\/a>/);
    25 }
    26
    27 # This action will render a template
    28 sub welcome {
    29 my ($self, $c) = @_;
    30
    31 # Render the template
    32 $c->render;
    33 }
    34
    35 1;
  • branches/mojo/Makefile.PL

     
    13 13 requires 'Fey';
    14 14 requires 'Fey::ORM';
    15 15 requires 'Fey::Loader';
    16
    16 17 requires 'Continuity';
    17 18 #requires 'Continuity::REPL';
    18 19 requires 'Coro::Generator';
    20
    21 requires 'Mojo';
    22
    19 23 requires 'Time::HiRes';
    20 24 requires 'Storable';
    21 25 requires 'Data::Page';
  • branches/mojo/public/404.html

     
    1 Document not found.
  • branches/mojo/public/index.html

     
    1 This is a static document at public/index.html,
    2 <a href="/">click here</a> to get back to the start.
  • branches/mojo/templates/example/welcome.phtml

     
    1 % my $c = shift;
    2
    3 <h2>Welcome to the Mojolicious Web Framework!</h2>
    4
    5 This page was generated from a template at templates/example/test.phtml,
    6 <a href="<%= $c->url_for(action => 'test') %>">click here</a>
    7 to move forward to a templateless action.