[Jifty-commit] r528 - in jifty/trunk: . inc/Module lib/Jifty
lib/Jifty/Script share/web/templates
share/web/templates/__jifty share/web/templates/let t/TestApp/t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Jan 25 05:30:28 EST 2006
Author: alexmv
Date: Wed Jan 25 05:30:27 2006
New Revision: 528
Added:
jifty/trunk/lib/Jifty/MasonHandler.pm
Removed:
jifty/trunk/share/web/templates/let/
Modified:
jifty/trunk/ (props changed)
jifty/trunk/META.yml
jifty/trunk/Makefile.PL
jifty/trunk/inc/Module/Install.pm
jifty/trunk/lib/Jifty/Action.pm
jifty/trunk/lib/Jifty/Continuation.pm
jifty/trunk/lib/Jifty/Dispatcher.pm
jifty/trunk/lib/Jifty/Everything.pm
jifty/trunk/lib/Jifty/Handler.pm
jifty/trunk/lib/Jifty/Request.pm
jifty/trunk/lib/Jifty/Script/FastCGI.pm
jifty/trunk/lib/Jifty/Server.pm
jifty/trunk/lib/Jifty/Web.pm
jifty/trunk/lib/Jifty/Web/PageRegion.pm
jifty/trunk/lib/Jifty/Web/Session.pm
jifty/trunk/share/web/templates/__jifty/autocomplete.xml
jifty/trunk/share/web/templates/autohandler
jifty/trunk/t/TestApp/t/16-images.t
Log:
r8797 at zoq-fot-pik: chmrr | 2006-01-25 05:29:23 -0500
* More topsy-turvy-ness. We no longer are a H::S::S::Mason, as that
constructed the mason object at the wrong time.
* Dispatcher all goes through Jifty::Request
* Don't need to worry about subrequests hitting
jifty->web->handle_request anymore
Modified: jifty/trunk/META.yml
==============================================================================
--- jifty/trunk/META.yml (original)
+++ jifty/trunk/META.yml Wed Jan 25 05:30:27 2006
@@ -24,6 +24,7 @@
Email::Send: 1.99_01
Email::Simple: 0
Email::Simple::Creator: 0
+ Encode: 0
Exporter: 0
File::Basename: 0
File::Copy: 0
@@ -37,7 +38,6 @@
HTML::Mason::Plugin: 0
HTTP::Cookies: 0
HTTP::Server::Simple: 0.10
- HTTP::Server::Simple::Mason: 0.09
HTTP::Server::Simple::Recorder: 0
Hash::Merge: 0
Hook::LexWrap: 0
Modified: jifty/trunk/Makefile.PL
==============================================================================
--- jifty/trunk/Makefile.PL (original)
+++ jifty/trunk/Makefile.PL Wed Jan 25 05:30:27 2006
@@ -20,6 +20,7 @@
requires('Email::Send' => '1.99_01'); # Email::Send::Jifty::Test
requires('Email::Simple');
requires('Email::Simple::Creator');
+requires('Encode');
requires('Exporter');
requires('File::Basename');
requires('File::Copy');
@@ -32,8 +33,7 @@
requires('HTML::Mason' => 1.3101); # HTML::Mason::CGIHandler HTML::Mason::Interp HTML::Mason::Plugin
requires('HTML::Mason::Plugin');
requires('HTTP::Cookies');
-requires('HTTP::Server::Simple' => '0.10');
-requires('HTTP::Server::Simple::Mason' => '0.09');
+requires('HTTP::Server::Simple' => '0.10'); # HTTP::Server::Simple::CGI
requires('HTTP::Server::Simple::Recorder');
requires('Hash::Merge');
requires('Hook::LexWrap');
Modified: jifty/trunk/inc/Module/Install.pm
==============================================================================
--- jifty/trunk/inc/Module/Install.pm (original)
+++ jifty/trunk/inc/Module/Install.pm Wed Jan 25 05:30:27 2006
@@ -1,4 +1,4 @@
-#line 1 "/home/chmrr/work/rt/local/jifty-trunk/inc/Module/Install.pm - /usr/lib/perl5/site_perl/5.8.7/Module/Install.pm"
+#line 1 "/home/chmrr/work/rt/local/jifty/inc/Module/Install.pm - /usr/lib/perl5/site_perl/5.8.7/Module/Install.pm"
package Module::Install;
use 5.004;
Modified: jifty/trunk/lib/Jifty/Action.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action.pm (original)
+++ jifty/trunk/lib/Jifty/Action.pm Wed Jan 25 05:30:27 2006
@@ -361,7 +361,7 @@
%$info,
action => $self,
input_name => $self->double_fallback_form_field_name($name),
- sticky => 0,
+ sticky => 0,
default_value => ($self->argument_value($name) || $info->{'default_value'}),
render_as => 'Hidden'
)->render();
@@ -430,6 +430,12 @@
}
+sub _prefix_field {
+ my $self = shift;
+ my ($field_name, $prefix) = @_;
+ return join("-", $prefix, $field_name, $self->moniker);
+}
+
=head2 form_field_name ARGUMENT
Turn one of this action's L<arguments|Jifty::Manual::Glossary/arguments> into
@@ -439,11 +445,9 @@
sub form_field_name {
my $self = shift;
- my $field_name = shift;
- return "J:A:F-$field_name-".$self->moniker;
+ return $self->_prefix_field(shift, "J:A:F");
}
-
=head2 fallback_form_field_name ARGUMENT
Turn one of this action's L<arguments|Jifty::Manual::Glossary/arguments> into
@@ -462,8 +466,7 @@
sub fallback_form_field_name {
my $self = shift;
- my $field_name = shift;
- return "J:A:F:F-$field_name-".$self->moniker;
+ return $self->_prefix_field(shift, "J:A:F:F");
}
@@ -481,8 +484,7 @@
sub double_fallback_form_field_name {
my $self = shift;
- my $field_name = shift;
- return "J:A:F:F:F-$field_name-".$self->moniker;
+ return $self->_prefix_field(shift, "J:A:F:F:F");
}
Modified: jifty/trunk/lib/Jifty/Continuation.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Continuation.pm (original)
+++ jifty/trunk/lib/Jifty/Continuation.pm Wed Jan 25 05:30:27 2006
@@ -111,7 +111,7 @@
if ($args{clone} and Jifty->web->session->get_continuation($args{clone})) {
$self = Clone::clone(Jifty->web->session->get_continuation($args{clone}));
for (grep {/^J:A/} keys %{$args{request}->arguments}) {
- $self->request->merge_param($_ => $args{request}->arguments->{$_});
+ $self->request->argument($_ => $args{request}->arguments->{$_});
}
$self->response($args{response});
} else {
@@ -187,7 +187,9 @@
Jifty->web->response( Clone::clone($self->response) ) if $self->response;
$self->code->(Jifty->web->request)
if $self->code;
- Jifty->web->_internal_request( Clone::clone($self->request) );
+ local Jifty->web->{request} = Clone::clone($self->request);
+ Jifty->handler->dispatcher->handle_request();
+ Jifty::Dispatcher::last_rule();
}
}
Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm (original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm Wed Jan 25 05:30:27 2006
@@ -232,6 +232,7 @@
our $Dispatcher;
+sub request { Jifty->web->request }
sub _ret (@);
sub under ($$@) { _ret @_ } # partial match at beginning of path component
sub before ($$@) { _ret @_ } # exact match on the path component
@@ -246,7 +247,7 @@
sub default ($$@) { _ret @_ } # set parameter if it's not yet set
sub set ($$@) { _ret @_ } # set parameter
sub del ($@) { _ret @_ } # remove parameter
-sub get ($) { $Dispatcher->{cgi}->param( $_[0] ) }
+sub get ($) { request->argument( $_[0] ) }
sub _qualify ($@);
sub GET ($) { _qualify method => @_ }
@@ -395,16 +396,11 @@
sub handle_request {
my $self = shift;
- my ($cgi, $handler) = @_;
-
- my $path = $cgi->path_info;
+ my $path = Jifty->web->request->path;
$path =~ s{/index\.html$}{};
- local $Dispatcher = $self->new(
- handler => $handler,
- cgi => $cgi,
- );
+ local $Dispatcher = $self->new();
HANDLER: {
$Dispatcher->_do_dispatch($path);
@@ -615,7 +611,7 @@
# Fix up the path
$path = shift if (@_);
- $path ||= $self->{cgi}->path_info;
+ $path ||= request->path;
$path = "$self->{cwd}/$path" unless $path =~ m{^/};
$path .= "index.html" if $path =~ m{/$};
@@ -624,10 +620,10 @@
if -d Jifty::Util->absolute_path( (Jifty->config->framework('Web')->{'TemplateRoot'} || "html") . $path );
# Set the request path
- $self->{cgi}->path_info($path);
+ request->path($path);
# Handle the request with Mason
- eval { $self->{handler}->handle_cgi_object($self->{cgi}); };
+ eval { Jifty->handler->mason->handle_comp(request->path); };
# Handle parse errors
if ( $@ and not UNIVERSAL::isa $@, 'HTML::Mason::Exception::Abort' ) {
@@ -640,18 +636,18 @@
sub _do_set {
my ( $self, $key, $value ) = @_;
- $self->{cgi}->param($key, $value);
+ request->argument($key, $value);
}
sub _do_del {
my ( $self, $key ) = @_;
- $self->{cgi}->delete($key);
+ request->delete($key);
}
sub _do_default {
my ( $self, $key, $value ) = @_;
- $self->{cgi}->param($key, $value)
- unless defined $self->{cgi}->param($key);
+ request->argument($key, $value)
+ unless defined request->argument($key);
}
=head2 _do_dispatch [PATH]
@@ -679,7 +675,7 @@
eval {
HANDLER: {
$self->_handle_rules( [ $self->rules('SETUP') ] );
- Jifty->web->handle_request($self->{cgi});
+ Jifty->web->handle_request();
$self->_handle_rules( [ $self->rules('RUN'), 'show' ] );
$self->_handle_rules( [ $self->rules('CLEANUP') ] );
}
@@ -825,8 +821,7 @@
Private function.
-Turns a metaexpression containing * and % into a capturing perl regex pattern.
-
+Turns a metaexpression containing * and ? into a capturing perl regex pattern.
=cut
Modified: jifty/trunk/lib/Jifty/Everything.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Everything.pm (original)
+++ jifty/trunk/lib/Jifty/Everything.pm Wed Jan 25 05:30:27 2006
@@ -32,6 +32,7 @@
use Jifty::Logger ();
use Jifty::Handler ();
+use Jifty::MasonHandler ();
use Jifty::Model::Schema ();
Modified: jifty/trunk/lib/Jifty/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Handler.pm (original)
+++ jifty/trunk/lib/Jifty/Handler.pm Wed Jan 25 05:30:27 2006
@@ -22,6 +22,11 @@
L<Jifty::Handler> provides methods required to deal with Mason CGI
handlers.
+=cut
+
+use base qw/Class::Accessor/;
+__PACKAGE__->mk_accessors(qw(mason dispatcher));
+
=head2 new
Create a new Jifty::Handler object. Generally, Jifty.pm does this only once at startup.
@@ -33,7 +38,6 @@
my $self = {};
bless $self, $class;
return $self;
-
}
@@ -58,6 +62,7 @@
error_mode => 'fatal',
error_format => 'text',
default_escape_flags => 'h',
+ autoflush => 0,
# plugins => ['Jifty::SetupRequest']
);
}
@@ -67,7 +72,6 @@
When your server processs (be it Jifty-internal, FastCGI or anything else) wants
to handle a request coming in from the outside world, you should call C<handle_request>.
-It expects a few parameters. C<cgi> is required.
=over
@@ -75,12 +79,6 @@
A L<CGI>.pm object that your server has already set up and loaded with your request's data
-=item mason_handler
-
-An initialized L<HTML::Mason> CGIHandler or subclass.
-
-=item
-
=back
=cut
@@ -89,25 +87,91 @@
sub handle_request {
my $self = shift;
my %args = (
- mason_handler => undef,
cgi => undef,
@_
);
- my $handler = $args{'mason_handler'};
- my $cgi = $args{'cgi'};
Module::Refresh->refresh;
+
local $HTML::Mason::Commands::JiftyWeb = Jifty::Web->new();
+ Jifty->web->request(Jifty::Request->new()->fill($args{cgi}));
- my $dispatcher = Jifty->config->framework('ApplicationClass')."::Dispatcher";
- $dispatcher->require;
-
- $dispatcher->handle_request($cgi, $handler);
+ $self->mason(Jifty::MasonHandler->new(
+ $self->mason_config,
+ out_method => sub {
+ my $m = HTML::Mason::Request->instance;
+ my $r = $m->cgi_request;
+ # Send headers if they have not been sent by us or by user.
+ # We use instance here because if we store $request we get a
+ # circular reference and a big memory leak.
+ unless ($r->http_header_sent) {
+ $r->send_http_header();
+ }
+
+ $r->content_type || $r->content_type('text/html; charset=utf-8'); # Set up a default
+
+ if ($r->content_type =~ /charset=([\w-]+)$/ ) {
+ my $enc = $1;
+ binmode *STDOUT, ":encoding($enc)";
+ }
+ # We could perhaps install a new, faster out_method here that
+ # wouldn't have to keep checking whether headers have been
+ # sent and what the $r->method is. That would require
+ # additions to the Request interface, though.
+ print STDOUT grep {defined} @_;
+ },
+ ));
+ $self->mason->interp->set_escape(
+ h => \&Jifty::Handler::escape_utf8 );
+ $self->mason->interp->set_escape(
+ u => \&Jifty::Handler::escape_uri );
+
+
+ $self->dispatcher(Jifty->config->framework('ApplicationClass')."::Dispatcher");
+ $self->dispatcher->require;
+ $self->dispatcher->handle_request();
$self->cleanup_request();
}
+=head2 escape_utf8 SCALARREF
+
+Does a css-busting but minimalist escaping of whatever html you're passing in.
+
+=cut
+
+sub escape_utf8 {
+ my $ref = shift;
+ my $val = $$ref;
+ use bytes;
+ $val =~ s/&/&/g;
+ $val =~ s/</</g;
+ $val =~ s/>/>/g;
+ $val =~ s/\(/(/g;
+ $val =~ s/\)/)/g;
+ $val =~ s/"/"/g;
+ $val =~ s/'/'/g;
+ $$ref = $val;
+ Encode::_utf8_on($$ref);
+
+}
+
+=head2 escape_uri SCALARREF
+
+Escapes URI component according to RFC2396
+
+=cut
+
+use Encode qw();
+
+sub escape_uri {
+ my $ref = shift;
+ $$ref = Encode::encode_utf8($$ref);
+ $$ref =~ s/([^a-zA-Z0-9_.!~*'()-])/uc sprintf("%%%02X", ord($1))/eg;
+ Encode::_utf8_on($$ref);
+}
+
=head2 cleanup_request
Dispatchers should call this at the end of each request, as a class method.
Added: jifty/trunk/lib/Jifty/MasonHandler.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/MasonHandler.pm Wed Jan 25 05:30:27 2006
@@ -0,0 +1,8 @@
+package Jifty::MasonHandler;
+use base qw/HTML::Mason::CGIHandler/;
+
+sub request_args {
+ return %{Jifty->web->request->arguments};
+}
+
+1;
Modified: jifty/trunk/lib/Jifty/Request.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Request.pm (original)
+++ jifty/trunk/lib/Jifty/Request.pm Wed Jan 25 05:30:27 2006
@@ -4,7 +4,7 @@
package Jifty::Request;
use base qw/Jifty::Object Class::Accessor Clone/;
-__PACKAGE__->mk_accessors(qw(arguments just_validating path continuation));
+__PACKAGE__->mk_accessors(qw(arguments just_validating path _continuation));
use Jifty::JSON;
use Jifty::YAML;
@@ -99,11 +99,6 @@
my $self = shift;
my ($cgi) = @_;
- # If this is a subrequest, we need to pull from the mason args in
- # order to avoid infinite looping
- $self->from_cgi($cgi)
- if Jifty->web->mason and Jifty->web->mason->is_subrequest;
-
# Grab content type and posted data, if any
my $ct = $ENV{"CONTENT_TYPE"};
my $data = $cgi->param('POSTDATA');
@@ -193,13 +188,14 @@
for my $newarg (split /\|/, $splittable) {
# If there are multiple =s, you just lose.
my ($k, $v) = split /=/, $newarg;
- $args{$k} = $args{$k} ? (ref $args{$k} ? [@{$args{$k}},$v] : [$args{$k}, $v] ) : $v;
+ $args{$k} = $v;
+ # The following breaks page regions and the like, sadly:
+ #$args{$k} ? (ref $args{$k} ? [@{$args{$k}},$v] : [$args{$k}, $v] ) : $v;
}
}
return $self->from_webform( %args );
}
-
=head2 from_webform %QUERY_ARGS
Parses web form arguments into the Jifty::Request data structure.
@@ -231,28 +227,54 @@
return $self;
}
-=head2 merge_param KEY => VALUE
+=head2 argument KEY [=> VALUE]
Merges a single query parameter into the request. This may add
actions, change action arguments, or change state variables.
=cut
-sub merge_param {
+sub argument {
my $self = shift;
- my ($key, $value) = @_;
- $self->arguments->{$key} = $value;
+ my $key = shift;
+ if (@_) {
+ my $value = shift;
+ $self->arguments->{$key} = $value;
+
+ if ($key =~ /^J:A-(?:(\d+)-)?(.+)/s) {
+ $self->add_action(moniker => $2, class => $value, order => $1, arguments => {}, active => 1);
+ } elsif ($key =~ /^J:A:F-(\w+)-(.+)/s and $self->action($2)) {
+ $self->action($2)->argument($1 => $value);
+ } elsif ($key =~ /^J:V-(.*)/s) {
+ $self->add_state_variable(key => $1, value => $value);
+ }
+ }
+ return $self->arguments->{$key};
+}
+
+=head2 delete KEY
+Removes the argument supplied -- this is the opposite of L</argument>,
+above.
+
+=cut
+
+sub delete {
+ my $self = shift;
+
+ my $key = shift;
+ delete $self->arguments->{$key};
if ($key =~ /^J:A-(?:(\d+)-)?(.+)/s) {
- $self->add_action(moniker => $2, class => $value, order => $1, arguments => {}, active => 1);
+ $self->remove_action($2);
} elsif ($key =~ /^J:A:F-(\w+)-(.+)/s and $self->action($2)) {
- $self->action($2)->argument($1 => $value);
+ $self->action($2)->delete($1);
} elsif ($key =~ /^J:V-(.*)/s) {
- $self->add_state_variable(key => $1, value => $value);
+ $self->remove_state_variable($1);
}
}
+
sub _extract_state_variables_from_webform {
my $self = shift;
my %args = (@_);
@@ -348,16 +370,30 @@
my $self = shift;
my %args = (@_);
- # Loading a continuation
- foreach my $continuation_id ($args{'J:C'}, $args{'J:CALL'} ) {
- next unless $continuation_id;
- $self->continuation(Jifty->web->session->get_continuation($continuation_id));
- }
-
if ($args{'J:CLONE'} and Jifty->web->session->get_continuations($args{'J:CLONE'})) {
my %params = %{Jifty->web->session->get_continuations($args{'J:CLONE'})->request->arguments};
- $self->merge_param($_ => $params{$_}) for keys %params;
+ $self->argument($_ => $params{$_}) for keys %params;
+ }
+}
+
+=head2 continuation [CONTINUATION]
+
+Gets or sets the continuation associated with the request.
+
+=cut
+
+sub continuation {
+ my $self = shift;
+
+ $self->_continuation(@_) if @_;
+ return $self->_continuation if $self->_continuation;
+
+ foreach my $continuation_id ($self->argument('J:C'), $self->argument('J:CALL') ) {
+ next unless $continuation_id;
+ return Jifty->web->session->get_continuation($continuation_id);
}
+
+ return undef;
}
=head2 call_continuation
@@ -434,7 +470,19 @@
$state_var->$k($args{$k}) if defined $args{$k};
}
$self->{'state_variables'}{$args{'key'}} = $state_var;
+}
+
+=head2 remove_state_variable KEY
+Removes the given state variable. The opposite of
+L</add_state_variable>, above.
+
+=cut
+
+sub remove_state_variable {
+ my $self = shift;
+ my ($key) = @_;
+ delete $self->{'state_variables'}{$key};
}
=head2 actions
@@ -463,8 +511,6 @@
return $self->{'actions'}{$moniker};
}
-
-
=head2 add_action PARAMHASH
Required argument: C<moniker>.
@@ -507,6 +553,18 @@
$self;
}
+=head2 remove_action MONIKER
+
+Removes an action with the given moniker.
+
+=cut
+
+sub remove_action {
+ my $self = shift;
+ my ($moniker) = @_;
+ delete $self->{'actions'}{$moniker};
+}
+
=head2 fragments
Returns a list of fragments requested, as L<Jifty::Request::Fragment> objects.
@@ -581,7 +639,7 @@
my ($key, $value) = Jifty::Request::Mapper->map(destination => $_, source => $self->arguments->{$_}, %args);
next unless $key ne $_;
delete $self->arguments->{$_};
- $self->merge_param($key => $value);
+ $self->argument($key => $value);
}
}
@@ -617,6 +675,16 @@
$self->arguments->{$key};
}
+=head3 delete
+
+=cut
+
+sub delete {
+ my $self = shift;
+ my $argument = shift;
+ delete $self->arguments->{$argument};
+}
+
package Jifty::Request::StateVariable;
use base 'Class::Accessor';
@@ -662,6 +730,16 @@
$self->arguments->{$key};
}
+=head3 delete
+
+=cut
+
+sub delete {
+ my $self = shift;
+ my $argument = shift;
+ delete $self->arguments->{$argument};
+}
+
=head1 SERIALIZATION
=head2 CGI Query parameters
Modified: jifty/trunk/lib/Jifty/Script/FastCGI.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Script/FastCGI.pm (original)
+++ jifty/trunk/lib/Jifty/Script/FastCGI.pm Wed Jan 25 05:30:27 2006
@@ -56,7 +56,6 @@
sub run {
Jifty->new();
- my $handler = HTML::Mason::CGIHandler->new( Jifty->handler->mason_config );
while ( my $cgi = CGI::Fast->new ) {
# the whole point of fastcgi requires the env to get reset here..
# So we must squash it again
@@ -65,9 +64,9 @@
$ENV{'PATH_INFO'} = $ENV{'SCRIPT_NAME'}
if $ENV{'SERVER_SOFTWARE'} =~ /^lighttpd\b/;
for (qw(CDPATH ENV IFS)) {
- $ENV{$_} = '' if (defined $ENV{$_} );
+ $ENV{$_} = '' if (defined $ENV{$_} );
}
- Jifty->handler->handle_request(mason_handler => $handler, cgi => $cgi);
+ Jifty->handler->handle_request( cgi => $cgi );
}
}
Modified: jifty/trunk/lib/Jifty/Server.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Server.pm (original)
+++ jifty/trunk/lib/Jifty/Server.pm Wed Jan 25 05:30:27 2006
@@ -21,8 +21,7 @@
=cut
use Jifty::Everything;
-use base qw/HTTP::Server::Simple::Mason/;
-use base qw/Class::Accessor/;
+use base qw/HTTP::Server::Simple::CGI/;
use base qw/Jifty::Object/;
use File::Spec;
use Module::Refresh;
@@ -43,57 +42,20 @@
my $self = {};
bless $self, $class;
$self->setup_jifty(@_);
-
$self->recording_on if $ENV{'JIFTY_RECORD'};
- return ($self);
-
-}
-
-=head2 mason_config
-
-The Jifty standalone server gets its Mason configuration from the same place that any other
-Jifty handler does: L<Jifty::Handler/mason_config>.
-
-=cut
-
-sub mason_config { Jifty::Handler->mason_config }
-
-=head2 handle_error
-
-Overrides L<HTTP::Server::Simple::Mason>'s handle_error method to
-return an error to the browser, and log an error using Log::Log4perl
-
-=cut
+ use Hook::LexWrap;
+ wrap 'HTML::Mason::FakeApache::send_http_header', pre => sub {
+ my $r = shift;
+ $r->header_out( @{$_} ) for Jifty->web->response->headers;
+ my $status = $r->header_out('Status') || '200 Jifty OK';
+ print STDOUT "HTTP/1.0 $status\n";
+ };
-sub handle_error {
- my $self = shift;
- my $error = shift;
-
- # Report error as coming from the appropriate place
- $Log::Log4perl::caller_depth++;
- my $logger = Log::Log4perl::get_logger("");
- my $time = Log::Log4perl::DateFormat->new("yyyy/MM/dd HH:mm:ss")->format(time);
- my $escaped_error = $error;
- $escaped_error =~ s/</</gi;
-
- warn "THIS IS UNSAFE ESCAPING";
-
- print <<"EOF";
-<html>
- <head><title>Internal Error</title></head>
- <body>
- <h1>Internal error</h1>
- <p>Something bad happened inside the server. Generally, this indicates something like a programming error or a broken database.</p>
- <pre>@{[ $escaped_error ]}</pre>
- </body>
-</html>
-EOF
+ return ($self);
- $logger->logdie($error);
}
-
=head2 setup_jifty
Sets up the Jifty singleton. This is called automatically by L</new>.
@@ -108,7 +70,6 @@
);
Jifty->config->framework('Web')->{'Port'} = $args{port} if $args{port};
-
$self->port( Jifty->config->framework('Web')->{'Port'} || 8888 );
}
@@ -125,14 +86,7 @@
my $self = shift;
my $cgi = shift;
- use Hook::LexWrap;
- wrap 'HTML::Mason::FakeApache::send_http_header', pre => sub {
- my $r = shift;
- $r->header_out( @{$_} ) for Jifty->web->response->headers;
- };
-
- Jifty->handler->handle_request( mason_handler => $self->mason_handler,
- cgi => $cgi);
+ Jifty->handler->handle_request( cgi => $cgi );
}
Modified: jifty/trunk/lib/Jifty/Web.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web.pm (original)
+++ jifty/trunk/lib/Jifty/Web.pm Wed Jan 25 05:30:27 2006
@@ -111,7 +111,7 @@
=head3 setup_session
Sets up the current C<session> object (a L<Jifty::Web::Session> tied
-hash).
+hash). Aborts if the session is already loaded.
=cut
@@ -119,9 +119,8 @@
sub setup_session {
my $self = shift;
my $m = Jifty->web->mason;
- # avoid reentrancy, as suggested by masonbook
- return if $m and $m->is_subrequest;
+ return if $self->session->loaded;
$self->session->load();
}
@@ -182,16 +181,17 @@
=head2 REQUEST
-=head3 handle_request
+=head3 handle_request [REQUEST]
-This method sets up a current session, prepares a L<Jifty::Request>
-object and loads page-specific actions.
-
-Each action is vetted in three ways -- first, it must be marked as
-C<active> by the L<Jifty::Request> (this is the default). Second, it
-must be in the set of allowed classes of actions (see L</is_allowed>,
-below). Finally, the action must validate. If it passes all of these
-criteria, the action is fit to be run.
+This method sets up a current session, and then processes the given
+L<Jifty::Request> object. If no request object is given, processes
+the request object in L</request>.
+
+Each action on the request is vetted in three ways -- first, it must
+be marked as C<active> by the L<Jifty::Request> (this is the default).
+Second, it must be in the set of allowed classes of actions (see
+L</is_allowed>, below). Finally, the action must validate. If it
+passes all of these criteria, the action is fit to be run.
Before they are run, however, the request has a chance to be
interrupted and saved away into a continuation, to be resumed at some
@@ -209,32 +209,13 @@
sub handle_request {
my $self = shift;
+ die "No request to handle" unless Jifty->web->request;
+
+ Jifty->web->response( Jifty::Response->new ) unless $self->response;
+ Jifty->web->setup_session;
- $self->setup_session;
- $self->response( Jifty::Response->new ) unless $self->response;
-
- # We local the request if we have one right now -- for mason
- # subrequests, for instance, we want to make sure we get back the
- # original request after the subrequest ends. If this is *not* a
- # subrequest, than we want to *not* local it, so that the mason
- # components have access to the outermost request
- if ($self->request) {
- local $self->{request};
- $self->_internal_request( Jifty::Request->new->fill(@_) );
- } else {
- $self->_internal_request( Jifty::Request->new->fill(@_) );
- }
-}
-
-# Called when continuations get run, as well as by handle_request;
-# takes a Jifty::Request
-sub _internal_request {
- my $self = shift;
- my ($request) = @_;
-
- $self->request($request);
my @valid_actions;
- for my $request_action ( $self->request->actions ) {
+ for my $request_action ( $self->request->actions ) {
next unless $request_action->active;
unless ( $self->is_allowed( $request_action->class ) ) {
$self->log->warn( "Attempt to call denied action '"
@@ -700,7 +681,7 @@
unless ($request_action) {
my $request = Jifty::Request->new();
- $request->merge_param(
+ $request->argument(
'J:CALL' => Jifty->web->request->continuation->id )
if Jifty->web->request->continuation;
$request->path("/");
@@ -762,9 +743,8 @@
my $request = Jifty::Request->new(path => Jifty->web->request->path)
->from_webform($clickable->get_parameters);
- Jifty->web->_internal_request($request);
-
-
+ local Jifty->web->{request} = $request;
+ Jifty->web->handle_request();
}
}
@@ -1067,8 +1047,7 @@
# text/html -- so we have to override them after the fact.
$self->response->add_header("Content-Type" => 'text/xml; charset=utf-8');
- # Clear the buffer (in case something else snuck out) then output
- # the data and bail
+ # Print a header and the content, and then bail
my $apache = HTML::Mason::FakeApache->new();
$apache->send_http_header();
print $output;
Modified: jifty/trunk/lib/Jifty/Web/PageRegion.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/PageRegion.pm (original)
+++ jifty/trunk/lib/Jifty/Web/PageRegion.pm Wed Jan 25 05:30:27 2006
@@ -32,8 +32,7 @@
=item path
-The path to the fragment that this page region contains. This B<must>
-be under a C</fragments> path.
+The path to the fragment that this page region contains.
=item defaults (optional)
@@ -241,11 +240,10 @@
# Merge in defaults
%arguments = (%{ Jifty->web->request->arguments }, region => $self, 'J:ACTIONS' => '', %arguments);
-
- $Jifty::Dispatcher::Dispatcher->{handler}->interp->make_request(comp => $self->path,
- args => [ %arguments ],
- out_method => \$result,
- )->exec;
+ Jifty->handler->mason->interp->make_request(comp => $self->path,
+ args => [ %arguments ],
+ out_method => \$result,
+ )->exec;
if ($self->region_wrapper) {
$result .= qq|</div>|;
}
Modified: jifty/trunk/lib/Jifty/Web/Session.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Session.pm (original)
+++ jifty/trunk/lib/Jifty/Web/Session.pm Wed Jan 25 05:30:27 2006
@@ -51,11 +51,6 @@
my $self = shift;
my $session_id = shift;
- my $m = Jifty->web->mason;
- return
- if $m
- && $m->is_subrequest; # avoid reentrancy, as suggested by masonbook
-
require Apache::Session::File;
unless ($session_id) {
@@ -85,7 +80,6 @@
$self->_session( tied(%session) );
$session{_session_id} = $session{_session_id} || $session_id;
-
}
=head2 unload
@@ -104,6 +98,17 @@
$self->_session(undef);
}
+=head2 loaded
+
+Returns true if the session has already been loaded
+
+=cut
+
+sub loaded {
+ my $self = shift;
+ return $self->_session && $self->get('_session_id');
+}
+
sub _session {
my $self = shift;
$self->{'_session'} = shift if (@_);
Modified: jifty/trunk/share/web/templates/__jifty/autocomplete.xml
==============================================================================
--- jifty/trunk/share/web/templates/__jifty/autocomplete.xml (original)
+++ jifty/trunk/share/web/templates/__jifty/autocomplete.xml Wed Jan 25 05:30:27 2006
@@ -17,9 +17,3 @@
%}
</ul>
</body>
-<%method setup_actions>
-<%init>
-Jifty->web->deny_actions(qr/.*/);
-Jifty->web->allow_actions('Jifty::Action::Autocomplete');
-</%init>
-</%method>
Modified: jifty/trunk/share/web/templates/autohandler
==============================================================================
--- jifty/trunk/share/web/templates/autohandler (original)
+++ jifty/trunk/share/web/templates/autohandler Wed Jan 25 05:30:27 2006
@@ -9,15 +9,3 @@
$m->call_next();
return;
</%init>
-<%def .setup_actions>
-<%init>
-Jifty->web->allow_actions(qr/.*/);
-# this method turns around and calls the setup_actions method
-# it's called by Jifty::Web->setup_page_actions.
-my $delegate = $m->fetch_comp($m->next_comp->path);
-if ($delegate and $delegate->method_exists('setup_actions')) {
- $delegate->call_method('setup_actions');
-}
-
-</%init>
-</%def>
Modified: jifty/trunk/t/TestApp/t/16-images.t
==============================================================================
--- jifty/trunk/t/TestApp/t/16-images.t (original)
+++ jifty/trunk/t/TestApp/t/16-images.t Wed Jan 25 05:30:27 2006
@@ -19,6 +19,6 @@
my $res = $mech->response;
is($res->header('Content-Type'), 'image/jpeg', 'Content-Type is image/jpeg');
- like($res->status_line, qr/^200 H::S::Mason OK$/, 'Status line is from Mason');
+ like($res->status_line, qr/^200 Jifty OK$/, 'Status line is from Mason');
}
More information about the Jifty-commit
mailing list