/[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 37 by dpavlin, Mon Jun 30 20:02:06 2008 UTC revision 38 by dpavlin, Mon Jun 30 20:02:08 2008 UTC
# Line 21  $server = Continuity->new( Line 21  $server = Continuity->new(
21          path_session => 1,          path_session => 1,
22          cookie_session => 'sid',          cookie_session => 'sid',
23          callback => \&main,          callback => \&main,
24            debug_level => 3,
25  );  );
 $server->debug_level( 2 );  
26    
27  sub run {  sub run {
28          $server->loop;          $server->loop;
29  }  }
30    
 my @callbacks;  
 my $callback_count;  
   
 sub gen_link {  
         my ($text, $code) = @_;  
         $callbacks[$callback_count] = $code;  
         my $out = qq{<a href="?cb=$callback_count">$text</a>};  
         $callback_count++;  
         return $out;  
 }  
   
 sub process_links {  
         my $request = shift;  
         my $cb = $request->param('cb');  
         if (exists $callbacks[$cb]) {  
                 $callbacks[$cb]->($request);  
 #               delete $callbacks[$cb];  
         }  
 }  
   
31  # This is the main entrypoint. We are looking for one of three things -- a  # This is the main entrypoint. We are looking for one of three things -- a
32  # 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
33  # of these cases, none of which will return (they all loop forever).  # of these cases, none of which will return (they all loop forever).
# Line 70  sub main { Line 50  sub main {
50                  send_message($req);                  send_message($req);
51          }          }
52    
         if ( $path =~ m/test/ ) {  
                 use Data::Dumper;  
                 $Data::Dumper::Deparse = 1;  
   
                 my $x = 0;  
                 my $continue = 1;  
                 my $link1 = gen_link('+' => sub { $x++ });  
                 my $link2 = gen_link('-' => sub { $x-- });  
                 my $out = gen_link('X' => sub { $continue = 0 });  
                 while ( $continue ) {  
                         warn "## x = $x ",dump( $req->params );  
                         $req->print("\$x is now: $x");  
                         $req->print($link1, ' ', $link2, ' ', $out);  
                         $req->print('<pre>'.Dumper( @callbacks ).'</pre>');  
                         $req->next;  
                         process_links($req);  
                 }  
         }  
   
53          # Otherwise, lets give them page          # Otherwise, lets give them page
54          send_page($req);          send_page($req);
55  }  }

Legend:
Removed from v.37  
changed lines
  Added in v.38

  ViewVC Help
Powered by ViewVC 1.1.26