[Jifty-commit] r1377 - in jifty: . trunk/doc/examples/CounterDemo
trunk/doc/examples/CounterDemo/bin
trunk/doc/examples/CounterDemo/doc
trunk/doc/examples/CounterDemo/lib
trunk/doc/examples/CounterDemo/lib/CounterDemo
trunk/doc/examples/CounterDemo/lib/CounterDemo/Action
trunk/doc/examples/CounterDemo/lib/CounterDemo/Model
trunk/doc/examples/CounterDemo/log
trunk/doc/examples/CounterDemo/share
trunk/doc/examples/CounterDemo/share/po
trunk/doc/examples/CounterDemo/share/web
trunk/doc/examples/CounterDemo/share/web/static
trunk/doc/examples/CounterDemo/share/web/templates
trunk/doc/examples/CounterDemo/t trunk/doc/examples/CounterDemo/var
trunk/doc/examples/CounterDemo/var/mason
trunk/doc/examples/CounterDemo/var/mason/cache
trunk/doc/examples/CounterDemo/var/mason/obj
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Jun 28 12:07:46 EDT 2006
Author: nelhage
Date: Wed Jun 28 12:07:45 2006
New Revision: 1377
Added:
jifty/trunk/doc/examples/CounterDemo/
jifty/trunk/doc/examples/CounterDemo/Makefile.PL
jifty/trunk/doc/examples/CounterDemo/bin/
jifty/trunk/doc/examples/CounterDemo/bin/jifty (contents, props changed)
jifty/trunk/doc/examples/CounterDemo/doc/
jifty/trunk/doc/examples/CounterDemo/etc/
jifty/trunk/doc/examples/CounterDemo/etc/config.yml
jifty/trunk/doc/examples/CounterDemo/lib/
jifty/trunk/doc/examples/CounterDemo/lib/CounterDemo/
jifty/trunk/doc/examples/CounterDemo/lib/CounterDemo/Action/
jifty/trunk/doc/examples/CounterDemo/lib/CounterDemo/Model/
jifty/trunk/doc/examples/CounterDemo/log/
jifty/trunk/doc/examples/CounterDemo/share/
jifty/trunk/doc/examples/CounterDemo/share/po/
jifty/trunk/doc/examples/CounterDemo/share/web/
jifty/trunk/doc/examples/CounterDemo/share/web/static/
jifty/trunk/doc/examples/CounterDemo/share/web/templates/
jifty/trunk/doc/examples/CounterDemo/share/web/templates/index.html
jifty/trunk/doc/examples/CounterDemo/t/
jifty/trunk/doc/examples/CounterDemo/t/00-counter-test.t (contents, props changed)
jifty/trunk/doc/examples/CounterDemo/var/
jifty/trunk/doc/examples/CounterDemo/var/mason/
jifty/trunk/doc/examples/CounterDemo/var/mason/cache/
jifty/trunk/doc/examples/CounterDemo/var/mason/obj/
Modified:
jifty/ (props changed)
Log:
r13210 at phanatique: nelhage | 2006-06-27 15:31:42 +0200
Adding a counter demo with continuations
Added: jifty/trunk/doc/examples/CounterDemo/Makefile.PL
==============================================================================
--- (empty file)
+++ jifty/trunk/doc/examples/CounterDemo/Makefile.PL Wed Jun 28 12:07:45 2006
@@ -0,0 +1,6 @@
+use inc::Module::Install;
+name('CounterDemo');
+version('0.01');
+requires('Jifty' => '0.60615');
+
+WriteAll;
Added: jifty/trunk/doc/examples/CounterDemo/bin/jifty
==============================================================================
--- (empty file)
+++ jifty/trunk/doc/examples/CounterDemo/bin/jifty Wed Jun 28 12:07:45 2006
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
+ if 0; # not running under some shell
+use warnings;
+use strict;
+use File::Basename qw(dirname);
+use UNIVERSAL::require;
+
+BEGIN {
+ Jifty::Util->require or die $UNIVERSAL::require::ERROR;
+ my $root = Jifty::Util->app_root;
+ unshift @INC, "$root/lib" if ($root);
+}
+
+use Jifty::Script;
+$SIG{INT} = $SIG{TERM} = sub { warn "Stopped\n"; exit; };
+Jifty::Script->dispatch();
Added: jifty/trunk/doc/examples/CounterDemo/etc/config.yml
==============================================================================
--- (empty file)
+++ jifty/trunk/doc/examples/CounterDemo/etc/config.yml Wed Jun 28 12:07:45 2006
@@ -0,0 +1,36 @@
+---
+framework:
+ AdminMode: 0
+ ApplicationClass: CounterDemo
+ ApplicationName: CounterDemo
+ Database:
+ Database: counterdemo
+ Driver: SQLite
+ Host: localhost
+ Password: ''
+ RecordBaseClass: Jifty::DBI::Record::Cachable
+ User: ''
+ Version: 0.0.1
+ DevelMode: 1
+ L10N:
+ PoDir: share/po
+ LogLevel: INFO
+ Mailer: Sendmail
+ MailerArgs: []
+
+ Plugins: []
+
+ Web:
+ BaseURL: http://localhost
+ DataDir: var/mason
+ Globals: []
+
+ MasonConfig:
+ autoflush: 0
+ default_escape_flags: h
+ error_format: text
+ error_mode: fatal
+ Port: 8888
+ ServeStaticFiles: 1
+ StaticRoot: share/web/static
+ TemplateRoot: share/web/templates
Added: jifty/trunk/doc/examples/CounterDemo/share/web/templates/index.html
==============================================================================
--- (empty file)
+++ jifty/trunk/doc/examples/CounterDemo/share/web/templates/index.html Wed Jun 28 12:07:45 2006
@@ -0,0 +1,24 @@
+<%init>
+my $counter = Jifty->web->request->state_variable('counter');
+my $value = $counter ? $counter->value : 0;
+
+
+my $request;
+
+$request = Jifty::Request->new( path => Jifty->web->request->path );
+$request->add_state_variable( key => 'counter', value => $value + 1 );
+my $up = Jifty::Continuation->new( request => $request );
+
+$request = Jifty::Request->new( path => Jifty->web->request->path );
+$request->add_state_variable( key => 'counter', value => $value - 1 );
+my $down = Jifty::Continuation->new( request => $request );
+</%init>
+
+<&| /_elements/wrapper, title => "Continuations counter demo" &>
+
+<h1> The counter is: <% $value %></h1>
+
+<% Jifty->web->link(call => $down, label => '--') %>
+<% Jifty->web->link(call => $up, label => '++') %>
+
+</&>
Added: jifty/trunk/doc/examples/CounterDemo/t/00-counter-test.t
==============================================================================
--- (empty file)
+++ jifty/trunk/doc/examples/CounterDemo/t/00-counter-test.t Wed Jun 28 12:07:45 2006
@@ -0,0 +1,53 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+=head1 DESCRIPTION
+
+Basic continuation counter test.
+
+=cut
+
+use Jifty::Test tests => 20;
+use Jifty::Test::WWW::Mechanize;
+
+my $server = Jifty::Test->make_server;
+
+my $URL = $server->started_ok();
+
+ok($URL, "Started the test server");
+
+my $mech = Jifty::Test::WWW::Mechanize->new();
+
+$mech->get_ok($URL, "Got the home page");
+
+$mech->content_contains('The counter is: 0', "Counter starts at 0");
+ok($mech->find_link(text => "++"), "Found the increment link");
+
+$mech->follow_link_ok(text => "++");
+$mech->content_contains('The counter is: 1', "Incremented the counter");
+
+$mech->follow_link_ok(text => "++");
+$mech->content_contains('The counter is: 2', "Incremented the counter");
+
+$mech->follow_link_ok(text => "--");
+$mech->content_contains('The counter is: 1', "Decremented the counter");
+
+$mech->follow_link_ok(text => "--");
+$mech->follow_link_ok(text => "--");
+$mech->follow_link_ok(text => "--");
+$mech->follow_link_ok(text => "--");
+
+$mech->content_contains('The counter is: -3', "Decremented the counter 4 times");
+
+$mech->back;
+$mech->back;
+
+$mech->content_contains('The counter is: -1', "Back at -1");
+
+$mech->follow_link_ok(text => "--");
+
+$mech->content_contains('The counter is: -2', "Going back then following links DTRT");
+
+$mech->get($URL);
+$mech->content_contains('The counter is: 0', "Loading the initial page again resets the counter");
More information about the Jifty-commit
mailing list