[Jifty-commit] r1201 - in jifty/trunk: lib/Jifty
plugins/EditInPlace/lib/Jifty/Plugin/EditInPlace
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Jun 8 00:07:11 EDT 2006
Author: alexmv
Date: Thu Jun 8 00:07:11 2006
New Revision: 1201
Modified:
jifty/trunk/ (props changed)
jifty/trunk/META.yml
jifty/trunk/lib/Jifty/Dispatcher.pm
jifty/trunk/lib/Jifty/Web.pm
jifty/trunk/plugins/EditInPlace/lib/Jifty/Plugin/EditInPlace/Dispatcher.pm
Log:
r13677 at zoq-fot-pik: chmrr | 2006-06-08 00:04:18 -0400
* 'last_rule' now aborts only the current stage -- thus, last_rule
from a 'before' block will *NOT* prevent the RUN stage from happening!
This is a *BACKWARDS-INCOMPATIBILE CHANGE*, but fixes the dispatcher
to agree with its docs
* 'abort' is the correct call to skip straight to the cleanup block.
* This allows the edit in place plugin to 'claim' its path and
protect it from access control in the app's 'before' blocks
Modified: jifty/trunk/META.yml
==============================================================================
--- jifty/trunk/META.yml (original)
+++ jifty/trunk/META.yml Thu Jun 8 00:07:11 2006
@@ -12,6 +12,7 @@
- DB
requires:
App::CLI: 0.03
+ CSS::Squish: 0.01
Cache::Cache: 0
Calendar::Simple: 0
Class::Accessor: 0
Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm (original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm Thu Jun 8 00:07:11 2006
@@ -72,7 +72,7 @@
to enable L<Jifty::LetMe> actions.
You can entirely stop processing with the C<redirect> and C<abort>
-directives.
+directives, though L</after> rules will still run.
=item on
@@ -235,7 +235,7 @@
=head2 abort $code
-Abort the request.
+Abort the request; this skips straight to the cleanup stage.
=head2 redirect $uri
@@ -447,18 +447,40 @@
local $HTML::Mason::Commands::m = undef;
# Mason introduces a DIE handler that generates a mason exception
# which in turn generates a backtrace. That's fine when you only
- # do it once per request. But it's really, really painful when you do it
- # often, as is the case with fragments
+ # do it once per request. But it's really, really painful when you
+ # do it often, as is the case with fragments
local $SIG{__DIE__} = 'DEFAULT';
eval {
$Dispatcher->_do_dispatch( Jifty->web->request->path);
};
if ( my $err = $@ ) {
- $self->log->warn(ref($err) . " " ."'$err'") if ( $err !~ /^LAST RULE/);
+ $self->log->warn(ref($err) . " " ."'$err'") if ( $err !~ /^ABORT/ );
}
}
+=head2 _handle_stage NAME, EXTRA_RULES
+
+Handles the all rules in the stage named C<NAME>. Additionally, any
+other arguments passed after the stage C<NAME> are added to the end of
+the rules for that stage.
+
+This is the unit which calling L</last_rule> skips to the end of.
+
+=cut
+
+sub _handle_stage {
+ my ($self, $stage, @rules) = @_;
+
+ eval { $self->_handle_rules( [ $self->rules($stage), @rules ] ); };
+ if ( my $err = $@ ) {
+ $self->log->warn( ref($err) . " " . "'$err'" )
+ if ( $err !~ /^(LAST RULE|ABORT)/ );
+ return $err =~ /^ABORT/ ? 0 : 1;
+ }
+ return 1;
+}
+
=head2 _handle_rules RULESET
When handed an arrayref or array of rules (RULESET), walks through the
@@ -523,17 +545,7 @@
no warnings 'exiting';
sub next_rule { next RULE }
-sub last_rule {
-
- # Mason introduces a DIE handler that generates a mason exception
- # which in turn generates a backtrace. That's fine when you only
- # do it once per request. But it's really, really painful when you do it
- # often, as is the case with fragments
-
- local $SIG{__DIE__} = 'IGNORE';
-
- die "LAST RULE";
-}
+sub last_rule { die "LAST RULE" }
=head2 _do_under
@@ -669,7 +681,6 @@
my ( $self, $path ) = @_;
$self->log->debug("Redirecting to $path");
Jifty->web->redirect($path);
- last_rule;
}
=head2 _do_abort
@@ -683,9 +694,11 @@
sub _do_abort {
my $self = shift;
$self->log->debug("Aborting processing");
- last_rule;
+ $self->_abort;
}
+sub _abort { die "ABORT" }
+
=head2 _do_show [PATH]
This method is called by the dispatcher internally. You shouldn't need to.
@@ -775,23 +788,21 @@
$self->log->debug("Dispatching request to ".$self->{path});
- eval {
- $self->_handle_rules( [ $self->rules('SETUP') ] );
- HANDLE_WEB: { Jifty->web->handle_request(); }
- $self->_handle_rules( [ $self->rules('RUN'), 'show' ] );
- };
- if ( my $err = $@ ) {
- $self->log->warn(ref($err) . " " ."'$err'") if ( $err !~ /^LAST RULE/);
- }
+ # Setup -- we we don't abort out of setup, then run the
+ # actions and then the RUN stage.
+ if ($self->_handle_stage('SETUP')) {
+ # Run actions
+ Jifty->web->handle_request();
- eval {
- $self->_handle_rules( [ $self->rules('CLEANUP') ] );
- };
- if ( my $err = $@ ) {
- $self->log->warn(ref($err) . " " ."'$err'") if ( $err !~ /^LAST RULE/);
+ # Run, and show the page
+ $self->_handle_stage('RUN' => 'show');
}
- last_rule;
+ # Cleanup
+ $self->_handle_stage('CLEANUP');
+
+ # Out to the next dispatcher's cleanup
+ $self->_abort;
}
=head2 _match CONDITION
Modified: jifty/trunk/lib/Jifty/Web.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web.pm (original)
+++ jifty/trunk/lib/Jifty/Web.pm Thu Jun 8 00:07:11 2006
@@ -266,9 +266,11 @@
$request_action->has_run(1);
if ( my $err = $@ ) {
- # poor man's exception propagation
- # We need to get "LAST RULE" exceptions back up to the dispatcher
- die $err if ( $err =~ /^LAST RULE/ );
+ # Poor man's exception propagation; we need to get
+ # "LAST RULE" and "ABORT" exceptions back up to the
+ # dispatcher. This is specifically for redirects from
+ # actions
+ die $err if ( $err =~ /^(LAST RULE|ABORT)/ );
$self->log->fatal($err);
$action->result->error(
Jifty->config->framework("DevelMode")
@@ -556,12 +558,11 @@
$apache->header_out( Status => 302 );
$apache->send_http_header();
- # Abort or last_rule out of here
+ # Mason abort, or dispatcher abort out of here
$self->mason->abort if $self->mason;
print ".\r\n" unless $self->mason;
# close STDOUT unless $self->mason;
- Jifty::Dispatcher::last_rule();
-
+ Jifty::Dispatcher::_abort;
}
=head3 save_continuation
Modified: jifty/trunk/plugins/EditInPlace/lib/Jifty/Plugin/EditInPlace/Dispatcher.pm
==============================================================================
--- jifty/trunk/plugins/EditInPlace/lib/Jifty/Plugin/EditInPlace/Dispatcher.pm (original)
+++ jifty/trunk/plugins/EditInPlace/lib/Jifty/Plugin/EditInPlace/Dispatcher.pm Thu Jun 8 00:07:11 2006
@@ -4,6 +4,11 @@
package Jifty::Plugin::EditInPlace::Dispatcher;
use Jifty::Dispatcher -base;
+before qr'^/__jifty/edit/(.*?)/(.*)$', run {
+ # Claim this as ours -- skip ACLs, etc
+ last_rule;
+};
+
on qr'^/__jifty/edit/(.*?)/(.*)$', run {
my $editor = Jifty->web->new_action(
class => 'Jifty::Plugin::EditInPlace::Action::FileEditor',
More information about the Jifty-commit
mailing list