/[Frey]/branches/zimbardo/lib/Frey/Mojo.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /branches/zimbardo/lib/Frey/Mojo.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 633 by dpavlin, Sun Nov 30 01:46:13 2008 UTC revision 1046 by dpavlin, Wed Apr 22 22:01:06 2009 UTC
# Line 7  use base 'Mojo'; Line 7  use base 'Mojo';
7    
8  use MojoX::Dispatcher::Static;  use MojoX::Dispatcher::Static;
9    
10    use lib 'lib';
11  use Frey::Server;  use Frey::Server;
12    use Frey::CouchAPI;
13    
14  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
15    
# Line 25  sub new { Line 27  sub new {
27      $self->log->level('error');      $self->log->level('error');
28      $self->log->path(undef);      $self->log->path(undef);
29    
30          warn "# home ", $self->home;  #       warn "# home ", $self->home;
31    
32          $self->static->root( './' );          $self->static->root( './' );
33    
34      return $self;      return $self;
35  }  }
36    
37    
38  sub handler {  sub handler {
39          my ($self, $tx) = @_;          my ($self, $tx) = @_;
40    
41            # XXX fake app so static dispatcher won't die on us
42            {
43                    package Fake::App;
44                    use base 'Mojo::Transaction';
45                    sub app {
46                            my $self = shift;
47    #                       warn "## $self app ", @_;
48                            $self;
49                    }
50                    sub log {
51                            my $self = shift;
52    #                       warn "## $self log ",@_;
53                            return $self;
54                    }
55                    sub debug {
56                            my $self = shift;
57                            warn "## ",@_, $/;
58                            return $self;
59                    }
60            }
61            bless $tx, 'Fake::App';
62    
63            # rewrite URL
64            Frey::CouchAPI->rewrite_urls( $tx );
65    
66          if ( $self->static->dispatch($tx) ) {          if ( $self->static->dispatch($tx) ) {
67                  warn "# static ",dump( $tx );  #               warn "# static ",dump( $tx );
68                  return $tx;                  return $tx;
69          }          }
70    
# Line 48  sub handler { Line 76  sub handler {
76          };          };
77    
78          my $url = $tx->req->url->to_string;          my $url = $tx->req->url->to_string;
79          my $params = $tx->req->params;          my $params = $tx->req->params->to_hash;
80    
81            my $referer = $tx->req->content->headers->header('Referer');
82            my $ajax = $tx->req->content->headers->header('X-Requested-With');
83            warn "# referer $referer\n";
84            warn "# headers = ", dump( $tx->req->content->headers );
85    
86          warn "# url $url params ",dump($params);          if ( $referer =~ m{/_utils} || $ajax =~ m{XMLHttpRequest}i ) {
87                    return Frey::CouchAPI->dispatch( $tx );
88            }
89    
90            warn "# url $url from $referer params ",dump($params);
91    
92            my $request = $server->request( $url, $params ); # fetch body
93    
94          $server->request( $url, $params ); # fetch body          warn "# request ", dump( $request );
95    
96            foreach ( 'content_type', 'code' ) {
97                    die "missing $_" unless defined $request->{$_};
98            }
99    
100  =for developer  =for developer
101    
# Line 66  sub handler { Line 109  sub handler {
109    
110  =cut  =cut
111    
112          $tx->res->code(200);          $tx->res->code( $request->{code} );
113          $tx->res->headers->content_type('text/html');          $tx->res->headers->content_type( $request->{content_type} );
114          $tx->res->body( $body );          $tx->res->body( $body );
115    
116          warn dump( $tx->res->headers );          warn dump( $tx->res->headers );

Legend:
Removed from v.633  
changed lines
  Added in v.1046

  ViewVC Help
Powered by ViewVC 1.1.26