Permalink
Browse files

get_handler renamed to psgi_callback

  • Loading branch information...
1 parent f681961 commit ec5f12e3acaa9f4912a6c9b8ac01d1a34ace0080 Zbigniew Lukasiak committed May 18, 2010
Showing with 35 additions and 25 deletions.
  1. +30 −20 lib/WebNano.pm
  2. +1 −1 t/10.main.t
  3. +1 −1 t/app.psgi
  4. +1 −1 t/crud_base_controller.t
  5. +1 −1 t/crudapp.t
  6. +1 −1 t/web_dispatch_table.t
View
@@ -8,31 +8,36 @@ use Plack::Request;
use Scalar::Util qw(blessed);
use Class::XSAccessor { accessors => [ 'renderer' ], constructor => 'new' };
-sub get_handler {
+sub psgi_callback {
my $self = shift;
sub {
- my $req = Plack::Request->new(shift);
- my $c_class = ref($self) . '::Controller';
- eval "require $c_class";
- my $path = $req->path;
- $path =~ s{^/}{};
- my $out = $c_class->handle( path => $path, application => $self, request => $req, self_url => '/' );
- if( blessed $out and $out->isa( 'Plack::Response' ) ){
- return $out->finalize;
- }
- elsif( ref $out eq 'CODE' ){
- return $out;
- }
- else{
- my $res = $req->new_response(200);
- $res->content_type('text/html');
- $res->body( $out );
- return $res->finalize;
- }
+ my $req = Plack::Request->new( shift );
+ $self->handle( $req );
};
}
+sub handle {
+ my( $self, $req ) = @_;
+ my $c_class = ref($self) . '::Controller';
+ eval "require $c_class";
+ my $path = $req->path;
+ $path =~ s{^/}{};
+ my $out = $c_class->handle( path => $path, application => $self, request => $req, self_url => '/' );
+ if( blessed $out and $out->isa( 'Plack::Response' ) ){
+ return $out->finalize;
+ }
+ elsif( ref $out eq 'CODE' ){
+ return $out;
+ }
+ else{
+ my $res = $req->new_response(200);
+ $res->content_type('text/html');
+ $res->body( $out );
+ return $res->finalize;
+ }
+}
+
1;
__END__
@@ -97,10 +102,15 @@ that the whole object lives in that scope. This is the same as
Tatsumaki handlers (and controllers in Rails, Django and probably
other frameworks) - but different from Catalyst.
+=head2 Streamming
+
+WebNano does not have any features helping with streaming content, but it also
+does not create any obstacles in using the original PSGI streamming interface.
+See for example the streaming_action method in t/lib/MyApp/Controller.pm.
=head1 ATTRIBUTES and METHODS
-=head2 get_handler
+=head2 psgi_callback
This is a method which returns a subroutine reference suitable for PSGI.
The returned subrourine ref is a closure over the application object.
View
@@ -8,7 +8,7 @@ use File::Copy;
copy('t/data/dvdzbr.db','t/tmp/dvdzbr.db') or die "Copy failed: $!";
test_psgi(
- app => MyApp->new()->get_handler,
+ app => MyApp->new()->psgi_callback,
client => sub {
my $cb = shift;
my $res = $cb->(GET "/");
View
@@ -1,5 +1,5 @@
use MyApp;
my $app = MyApp->new();
-$app->get_handler;
+$app->psgi_callback;
@@ -9,7 +9,7 @@ use File::Copy;
copy('t/data/dvdzbr.db','t/tmp/dvdzbr.db') or die "Copy failed: $!";
test_psgi(
- app => MyApp->new()->get_handler,
+ app => MyApp->new()->psgi_callback,
client => sub {
my $cb = shift;
$res = $cb->(GET "/DvdWithBaseCRUD/");
View
@@ -8,7 +8,7 @@ use File::Copy;
copy('t/data/dvdzbr.db','t/tmp/dvdzbr.db') or die "Copy failed: $!";
test_psgi(
- app => MyApp->new()->get_handler,
+ app => MyApp->new()->psgi_callback,
client => sub {
my $cb = shift;
my $res = $cb->(GET "/");
@@ -7,7 +7,7 @@ use MyApp;
use File::Copy;
test_psgi(
- app => MyApp->new()->get_handler,
+ app => MyApp->new()->psgi_callback,
client => sub {
my $cb = shift;
my $res = $cb->(GET "/WebDispatchTable");

0 comments on commit ec5f12e

Please sign in to comment.