[Jifty-commit] r2518 - in jifty/trunk: . lib/Jifty
t/TestApp/lib/TestApp t/TestApp/share/web/templates
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Jan 17 20:10:42 EST 2007
Author: jesse
Date: Wed Jan 17 20:10:40 2007
New Revision: 2518
Added:
jifty/trunk/t/TestApp/t/02-dispatch-show-rule-in-wrong-ruleset.t
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Dispatcher.pm
jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm
jifty/trunk/t/TestApp/share/web/templates/index.html
Log:
r21071 at hualien: jesse | 2007-01-17 20:10:12 -0500
* Warnings when a developer puts a "show" into a "before" or "after" dispatcher rule.
Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm (original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm Wed Jan 17 20:10:40 2007
@@ -302,6 +302,8 @@
sub plugin ($) { return { plugin => @_ } }
+our $CURRENT_STAGE;
+
=head2 import
Jifty::Dispatcher is an L<Exporter>, that is, part of its role is to
@@ -481,6 +483,9 @@
sub _handle_stage {
my ($self, $stage, @rules) = @_;
+ # Set the current stage so that rules can make smarter choices;
+ local $CURRENT_STAGE = $stage;
+
eval { $self->_handle_rules( [ $self->rules($stage), @rules ] ); };
if ( my $err = $@ ) {
$self->log->warn( ref($err) . " " . "'$err'" )
@@ -749,6 +754,11 @@
# Fix up the path
$path = shift if (@_);
$path ||= $self->{path};
+
+ unless ($CURRENT_STAGE eq 'RUN') {
+ die "You can't call a 'show' rule in a 'before' or 'after' block in the dispatcher. Not showing path $path";
+ }
+
$self->log->debug("Showing path $path");
# If we've got a working directory (from an "under" rule) and we have
Modified: jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm
==============================================================================
--- jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm (original)
+++ jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm Wed Jan 17 20:10:40 2007
@@ -57,4 +57,10 @@
show '/index.html';
};
+
+
+before '/before_stage_show' => run { show '/index.html'; };
+on '/on_stage_show' => run { show '/index.html'; };
+after '/after_stage_show' => run { show '/index.html'; };
+
1;
Modified: jifty/trunk/t/TestApp/share/web/templates/index.html
==============================================================================
--- jifty/trunk/t/TestApp/share/web/templates/index.html (original)
+++ jifty/trunk/t/TestApp/share/web/templates/index.html Wed Jan 17 20:10:40 2007
@@ -1,3 +1,4 @@
<&|/_elements/wrapper, title => 'Jifty Test Application' &>
<img src="/images/pony.jpg" alt="A Pony"/>
+This is content
</&>
Added: jifty/trunk/t/TestApp/t/02-dispatch-show-rule-in-wrong-ruleset.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/02-dispatch-show-rule-in-wrong-ruleset.t Wed Jan 17 20:10:40 2007
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+use lib 't/lib';
+use Jifty::SubTest;
+use Jifty::Test tests => 8;
+use Jifty::Test::WWW::Mechanize;
+
+my $server = Jifty::Test->make_server;
+
+isa_ok($server, 'Jifty::Server');
+
+my $URL = $server->started_ok;
+my $mech = Jifty::Test::WWW::Mechanize->new();
+
+$mech->get("$URL/before_stage_show", "Got /before_stage_show");
+$mech->content_lacks("This is content");
+is( $mech->status , '404');
+
+$mech->get_ok("$URL/on_stage_show", "Got /on_stage_show");
+$mech->content_contains("his is content");
+
+$mech->get("$URL/after_stage_show", "Got /after_stage_show");
+$mech->content_lacks("This is content");
+is( $mech->status , '404');
+
+1;
More information about the Jifty-commit
mailing list