/[Frey]/trunk/lib/Frey/Server.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 /trunk/lib/Frey/Server.pm

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

revision 25 by dpavlin, Sun Jun 29 17:27:45 2008 UTC revision 53 by dpavlin, Sat Jul 5 15:19:55 2008 UTC
# Line 4  use strict; Line 4  use strict;
4  use warnings;  use warnings;
5    
6  use Continuity;  use Continuity;
7  use Continuity::REPL;  #use Continuity::REPL;
8    use Continuity::Widget::DomNode;
9  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
10    
11  use base 'Frey';  use base 'Frey';
12  use Frey::HTML;  use Frey::HTML;
13    use Frey::ObjectBrowser;
14    
15  my @messages;    # Global (shared) list of messages  my @messages;    # Global (shared) list of messages
16  my $got_message; # Flag to indicate that there is a new message to display  my $got_message; # Flag to indicate that there is a new message to display
17    
18  use vars qw( $repl $server );  use vars qw( $repl $server );
19    
20  sub run {  #$repl = Continuity::REPL->new;
21          $repl = Continuity::REPL->new;  $server = Continuity->new(
22          $server = Continuity->new(          port => 16001,
23            port => 16001,          path_session => 1,
24            path_session => 1,          cookie_session => 'sid',
25            cookie_session => 'sid',          callback => \&main,
26            callback => \&main,          debug_level => 1,
27          );          staticp => sub { $_[0]->url =~ m/\.(jpg|jpeg|gif|png|css|ico|js|html?)$/ },
28          $server->debug_level( 2 );  );
29    
30    sub run {
31          $server->loop;          $server->loop;
32  }  }
33    
# Line 32  sub run { Line 35  sub run {
35  # pushstream, a sent message, or a request for the main HTML. We delegate each  # pushstream, a sent message, or a request for the main HTML. We delegate each
36  # of these cases, none of which will return (they all loop forever).  # of these cases, none of which will return (they all loop forever).
37  sub main {  sub main {
38    my ($req) = @_;          my ($req) = @_;
39        
40    my $path = $req->request->url->path;          my $path = $req->request->url->path;
41    warn "REQUEST: $path\n";          warn "REQUEST: $path\n";
42    
43          warn $req->request->header('User_Agent');          warn $req->request->header('User_Agent');
44  #warn dump( $req );  #warn dump( $req );
45    
46    # If this is a request for the pushtream, then give them that          if ( $path =~ m!/~/([^/]+)(?:/([^/]*))?! ) {
47    if($path =~ /pushstream/) {                  my $f = Frey::Introspect->new( package => $1 );
48          pushstream($req);                  $f->html( $req );
49    }          }
50    
51            # If this is a request for the pushtream, then give them that
52            if($path =~ /pushstream/) {
53                    pushstream($req);
54            }
55        
56    # If they are sending us a message, we give them a thread for that too          # If they are sending us a message, we give them a thread for that too
57    if($path =~ /sendmessage/) {          if($path =~ /sendmessage/) {
58          send_message($req);                  send_message($req);
59    }          }
60    
61    # Otherwise, lets give them page          if($path =~ m!^/ob!) {
62    send_page($req);                  Frey::ObjectBrowser->new( req => $req )->html;
63            }
64    
65            # Otherwise, lets give them page
66            send_page($req);
67  }  }
68    
69  # Here we accept a connection to the browser, and keep it open. Meanwhile we  # Here we accept a connection to the browser, and keep it open. Meanwhile we
# Line 100  sub send_page { Line 112  sub send_page {
112                  warn "param = ",dump($req->param);                  warn "param = ",dump($req->param);
113                  my $path = $req->request->url->path;                  my $path = $req->request->url->path;
114    
115                    my $html;
116    
117                  if ( $path =~ m/::/ ) {                  if ( $path =~ m/::/ ) {
118                          my ( undef, $module, $method ) = split(m!/!, $path, 3);                          my ( undef, $module, $method ) = split(m!/!, $path, 3);
119    
120                          if ( ! defined( $templates->{$module} ) ) {                          if ( ! defined( $templates->{$module} ) ) {
121                                  $req->conn->send_status_line( 404, "$module" );                                  $req->conn->send_status_line( 404, "$module" );
122                                  $req->print("Package $module not found");                                  $html = "Package $module not found";
123                            } elsif ( ! $method ) {
124                                    $html = Frey::HTML->page( 'package-templates', $req, $module );
125                          } elsif ( grep(/^\Q$method\E$/, @{ $templates->{$module} }) ) {                          } elsif ( grep(/^\Q$method\E$/, @{ $templates->{$module} }) ) {
126                                  $req->print( Frey::HTML->page( $method, $req ) );                                  $html = Frey::HTML->page( $method, $req );
127                          } else {                          } else {
128                                  $req->conn->send_status_line( 404, "$module $method" );                                  $req->conn->send_status_line( 404, "$module $method" );
129                                  $req->print("Package $module doesn't have $method");                                  $html = "Package $module doesn't have $method";
130                          }                          }
131                  } else {                  } else {
132                          my $html = Frey::HTML->page( 'status' );                          warn "fallback to status page\n";
133                          $req->print( $html );                          $html = Frey::HTML->page( 'status' );
                         warn ">> ",length( $html ), " bytes\n";  
134                  }                  }
135    
136                    $req->print( $html );
137                    warn ">> ",length( $html ), " bytes\n";
138                  $req->next;                  $req->next;
                 Module::Refresh->refresh;  
139          }          }
140  }  }
141    

Legend:
Removed from v.25  
changed lines
  Added in v.53

  ViewVC Help
Powered by ViewVC 1.1.26