r69060 - in /branches/upstream/libplack-perl/current: ./ lib/ lib/Plack/ lib/Plack/App/ lib/Plack/Middleware/ lib/Plack/Server/ scripts/ t/Plack-Middleware/ t/Plack-Middleware/cascade/ t/Plack-Middleware/recursive/ t/Plack-Middleware/stacktrace/

jawnsy-guest at users.alioth.debian.org jawnsy-guest at users.alioth.debian.org
Sat Feb 19 04:00:33 UTC 2011


Author: jawnsy-guest
Date: Sat Feb 19 03:59:57 2011
New Revision: 69060

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=69060
Log:
[svn-upgrade] new version libplack-perl (0.9968)

Added:
    branches/upstream/libplack-perl/current/t/Plack-Middleware/cascade/
    branches/upstream/libplack-perl/current/t/Plack-Middleware/cascade/basic.t
    branches/upstream/libplack-perl/current/t/Plack-Middleware/cascade/streaming.t
    branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/
    branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/basic.t
    branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/force.t
    branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/streaming.t
    branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/utf8.t
Removed:
    branches/upstream/libplack-perl/current/t/Plack-Middleware/cascade.t
    branches/upstream/libplack-perl/current/t/Plack-Middleware/cascade_streaming.t
    branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace.t
    branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace_force.t
    branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace_streaming.t
    branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace_utf8.t
Modified:
    branches/upstream/libplack-perl/current/Changes
    branches/upstream/libplack-perl/current/MANIFEST
    branches/upstream/libplack-perl/current/META.yml
    branches/upstream/libplack-perl/current/README
    branches/upstream/libplack-perl/current/lib/Plack.pm
    branches/upstream/libplack-perl/current/lib/Plack/App/Cascade.pm
    branches/upstream/libplack-perl/current/lib/Plack/Builder.pm
    branches/upstream/libplack-perl/current/lib/Plack/Component.pm
    branches/upstream/libplack-perl/current/lib/Plack/Loader.pm
    branches/upstream/libplack-perl/current/lib/Plack/Middleware.pm
    branches/upstream/libplack-perl/current/lib/Plack/Middleware/Recursive.pm
    branches/upstream/libplack-perl/current/lib/Plack/Request.pm
    branches/upstream/libplack-perl/current/lib/Plack/Response.pm
    branches/upstream/libplack-perl/current/lib/Plack/Server/ServerSimple.pm
    branches/upstream/libplack-perl/current/lib/Plack/Util.pm
    branches/upstream/libplack-perl/current/scripts/plackup
    branches/upstream/libplack-perl/current/t/Plack-Middleware/recursive/throw.t

Modified: branches/upstream/libplack-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/Changes?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/Changes (original)
+++ branches/upstream/libplack-perl/current/Changes Sat Feb 19 03:59:57 2011
@@ -1,12 +1,18 @@
 Revision history for Perl extension Plack
 
 Take a look at http://github.com/miyagawa/Plack/issues for the planned changes before 1.0 release.
+
+0.9968  Wed Feb  9 19:07:48 PST 2011
+        - Fixed Recursive middleware to rethrow unknown exceptions. #166 (reported by waba)
+        - Document response_cb. #121
+        - Plack::Loader to print errors if it is really a compilation error
+        - Fixed the Cascade app to work with all 404 responses with the streaming interface. #171 (reported by eevee)
 
 0.9967  Tue Jan 25 14:26:37 PST 2011
         - Fixed StackTrace to require D::ST::WithLexicals 0.08 that supports 'message' (doy)
 
 0.9966  Tue Jan 25 12:00:25 PST 2011
-        - Fixed a memory leak in SimploLogger (vti)
+        - Fixed a memory leak in SimpleLogger (vti)
         - Support %v in AccessLog (Ranguard)
         - Force set CONTENT_LENGTH in req_to_psgi when $content is given to HTTP::Request (timbunce) #150
         - Fixed a case where SCRIPT_NAME and PATH_INFO can both get empty in req_to_psgi (doy) #163

Modified: branches/upstream/libplack-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/MANIFEST?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/MANIFEST (original)
+++ branches/upstream/libplack-perl/current/MANIFEST Sat Feb 19 03:59:57 2011
@@ -164,8 +164,8 @@
 t/Plack-Middleware/auth_basic_env.t
 t/Plack-Middleware/auth_basic_simple.t
 t/Plack-Middleware/bufferedstreaming.t
-t/Plack-Middleware/cascade.t
-t/Plack-Middleware/cascade_streaming.t
+t/Plack-Middleware/cascade/basic.t
+t/Plack-Middleware/cascade/streaming.t
 t/Plack-Middleware/cgi-bin/hello.cgi
 t/Plack-Middleware/cgi-bin/hello.py
 t/Plack-Middleware/cgi-bin/hello2.cgi
@@ -205,10 +205,10 @@
 t/Plack-Middleware/runtime.t
 t/Plack-Middleware/simple_content_filter.t
 t/Plack-Middleware/simple_logger.t
-t/Plack-Middleware/stacktrace.t
-t/Plack-Middleware/stacktrace_force.t
-t/Plack-Middleware/stacktrace_streaming.t
-t/Plack-Middleware/stacktrace_utf8.t
+t/Plack-Middleware/stacktrace/basic.t
+t/Plack-Middleware/stacktrace/force.t
+t/Plack-Middleware/stacktrace/streaming.t
+t/Plack-Middleware/stacktrace/utf8.t
 t/Plack-Middleware/static.t
 t/Plack-Middleware/static.txt
 t/Plack-Middleware/static_env.t

Modified: branches/upstream/libplack-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/META.yml?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/META.yml (original)
+++ branches/upstream/libplack-perl/current/META.yml Sat Feb 19 03:59:57 2011
@@ -40,4 +40,4 @@
   homepage: http://plackperl.org
   license: http://dev.perl.org/licenses/
   repository: git://github.com/miyagawa/Plack.git
-version: 0.9967
+version: 0.9968

Modified: branches/upstream/libplack-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/README?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/README (original)
+++ branches/upstream/libplack-perl/current/README Sat Feb 19 03:59:57 2011
@@ -133,7 +133,7 @@
     The following copyright notice applies to all the files provided in this
     distribution, including binary files, unless explicitly noted otherwise.
 
-    Copyright 2009-2010 Tatsuhiko Miyagawa
+    Copyright 2009-2011 Tatsuhiko Miyagawa
 
 CONTRIBUTORS
     Yuval Kogman (nothingmuch)

Modified: branches/upstream/libplack-perl/current/lib/Plack.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/lib/Plack.pm?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/lib/Plack.pm (original)
+++ branches/upstream/libplack-perl/current/lib/Plack.pm Sat Feb 19 03:59:57 2011
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 use 5.008_001;
-our $VERSION = '0.9967';
+our $VERSION = '0.9968';
 $VERSION = eval $VERSION;
 
 1;
@@ -171,7 +171,7 @@
 this distribution, including binary files, unless explicitly noted
 otherwise.
 
-Copyright 2009-2010 Tatsuhiko Miyagawa
+Copyright 2009-2011 Tatsuhiko Miyagawa
 
 =head1 CONTRIBUTORS
 

Modified: branches/upstream/libplack-perl/current/lib/Plack/App/Cascade.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/lib/Plack/App/Cascade.pm?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/lib/Plack/App/Cascade.pm (original)
+++ branches/upstream/libplack-perl/current/lib/Plack/App/Cascade.pm Sat Feb 19 03:59:57 2011
@@ -38,7 +38,7 @@
         };
 
         for my $app (@{$self->apps || []}) {
-            $res = $app->($env);
+            my $res = $app->($env);
             if (ref $res eq 'CODE') {
                 $res->($respond_wrapper);
             } else {

Modified: branches/upstream/libplack-perl/current/lib/Plack/Builder.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/lib/Plack/Builder.pm?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/lib/Plack/Builder.pm (original)
+++ branches/upstream/libplack-perl/current/lib/Plack/Builder.pm Sat Feb 19 03:59:57 2011
@@ -124,72 +124,71 @@
       enable "Plack::Middleware::Foo";
       enable "Plack::Middleware::Bar", opt => "val";
       enable "Plack::Middleware::Baz";
+      $app;
+  };
+
+  # use URLMap
+
+  builder {
+      mount "/foo" => builder {
+          enable "Plack::Middleware::Foo";
+          $app;
+      };
+
+      mount "/bar" => $app2;
+      mount "http://example.com/" => builder { $app3 };
+  };
+
+  # using OO interface
+
+  my $builder = Plack::Builder->new();
+  $builder->add_middleware('Foo', opt => 1);
+  $app = $builder->mount('/app' => $app);
+  $app = $builder->to_app($app);
+
+=head1 DESCRIPTION
+
+Plack::Builder gives you a quick domain specific language (DSL) to
+wrap your application with Plack::Middleware subclasses. The
+middleware you're trying to use should use L<Plack::Middleware> as a
+base class to use this DSL, inspired by Rack::Builder.
+
+Whenever you call C<enable> on any middleware, the middleware app is
+pushed to the stack inside the builder, and then reversed when it
+actually creates a wrapped application handler, so:
+
+  builder {
+      enable "Plack::Middleware::Foo";
+      enable "Plack::Middleware::Bar", opt => "val";
+      $app;
+  };
+
+is syntactically equal to:
+
+  $app = Plack::Middleware::Bar->wrap($app, opt => "val");
+  $app = Plack::Middleware::Foo->wrap($app);
+
+In other words, you're supposed to C<enable> middleware from outer to inner.
+
+=head1 INLINE MIDDLEWARE
+
+Plack::Builder allows you to code middleware inline using a nested
+code reference.
+
+If the first argument to C<enable> is a code reference, it will be
+passed an C<$app> and is supposed to return another code reference
+which is PSGI application that consumes C<$env> in runtime. So:
+
+  builder {
       enable sub {
           my $app = shift;
           sub {
               my $env = shift;
-              $app->($env);
+              # do preprocessing
+              my $res = $app->($env);
+              # do postprocessing
+              return $res;
           };
-      };
-      $app;
-  };
-
-  # use URLMap
-
-  builder {
-      mount "/foo" => builder {
-          enable "Plack::Middleware::Foo";
-          $app;
-      };
-
-      mount "/bar" => $app2;
-      mount "http://example.com/" => builder { $app3 };
-  };
-
-  # using OO interface
-
-  my $builder = Plack::Builder->new();
-  $builder->add_middleware('Foo', opt => 1);
-  $app = $builder->mount('/app' => $app);
-  $app = $builder->to_app($app);
-
-=head1 DESCRIPTION
-
-Plack::Builder gives you a quick domain specific language (DSL) to
-wrap your application with Plack::Middleware subclasses. The
-middleware you're trying to use should use L<Plack::Middleware> as a
-base class to use this DSL, inspired by Rack::Builder.
-
-Whenever you call C<enable> on any middleware, the middleware app is
-pushed to the stack inside the builder, and then reversed when it
-actually creates a wrapped application handler, so:
-
-  builder {
-      enable "Plack::Middleware::Foo";
-      enable "Plack::Middleware::Bar", opt => "val";
-      $app;
-  };
-
-is syntactically equal to:
-
-  $app = Plack::Middleware::Bar->wrap($app, opt => "val");
-  $app = Plack::Middleware::Foo->wrap($app);
-
-In other words, you're supposed to C<enable> middleware from outer to inner.
-
-=head1 INLINE MIDDLEWARE
-
-Plack::Builder allows you to code middleware inline using a nested
-code reference.
-
-If the first argument to C<enable> is a code reference, it will be
-passed an C<$app> and is supposed to return another code reference
-which is PSGI application that consumes C<$env> in runtime. So:
-
-  builder {
-      enable sub {
-          my $app = shift;
-          sub { my $env = shift; $app->($env) };
       };
       $app;
   };

Modified: branches/upstream/libplack-perl/current/lib/Plack/Component.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/lib/Plack/Component.pm?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/lib/Plack/Component.pm (original)
+++ branches/upstream/libplack-perl/current/lib/Plack/Component.pm Sat Feb 19 03:59:57 2011
@@ -109,6 +109,11 @@
 override this method, it is recommended to use C<prepare_app> and C<call>
 instead.
 
+=item response_cb
+
+This is a wrapper for C<response_cb> in L<Plack::Util>. See
+L<Plack::Middleware/RESPONSE CALLBACK> for details.
+
 =back
 
 =head1 OBJECT LIFECYCLE

Modified: branches/upstream/libplack-perl/current/lib/Plack/Loader.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/lib/Plack/Loader.pm?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/lib/Plack/Loader.pm (original)
+++ branches/upstream/libplack-perl/current/lib/Plack/Loader.pm Sat Feb 19 03:59:57 2011
@@ -22,9 +22,11 @@
     my $server = try {
         $class->load($backend, @args);
     } catch {
-        warn "Autoloading '$backend' backend failed. Falling back to the Standalone. ",
-            "(You might need to install Plack::Handler::$backend from CPAN.  Caught error was: $_)\n"
-                if $ENV{PLACK_ENV} && $ENV{PLACK_ENV} eq 'development';
+        if (($ENV{PLACK_ENV}||'') eq 'development' or !/Can't locate/) {
+            warn "Autoloading '$backend' backend failed. Falling back to the Standalone. ",
+                "(You might need to install Plack::Handler::$backend from CPAN.  Caught error was: $_)\n"
+                    if $ENV{PLACK_ENV} && $ENV{PLACK_ENV} eq 'development';
+        }
         $class->load('Standalone' => @args);
     };
 

Modified: branches/upstream/libplack-perl/current/lib/Plack/Middleware.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/lib/Plack/Middleware.pm?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/lib/Plack/Middleware.pm (original)
+++ branches/upstream/libplack-perl/current/lib/Plack/Middleware.pm Sat Feb 19 03:59:57 2011
@@ -72,7 +72,7 @@
 cache per-request data like C<$env> in your middleware object. See
 also L<Plack::Component/"OBJECT LIFECYCLE">.
 
-See L<Plack::Builder> how to actually enable middlewares in your
+See L<Plack::Builder> how to actually enable middleware in your
 I<.psgi> application file using the DSL. If you do not like our
 builder DSL, you can also use C<wrap> method to wrap your application
 with a middleware:
@@ -83,6 +83,106 @@
   $app = Plack::Middleware::Foo->wrap($app, %options);
   $app = Plack::Middleware::Bar->wrap($app, %options);
 
+=head1 RESPONSE CALLBACK
+
+The typical middleware is written like this:
+
+  package Plack::Middleware::Something;
+  use parent qw(Plack::Middleware);
+
+  sub call {
+      my($self, $env) = @_;
+      # pre-processing $env
+      my $res = $self->app->($env);
+      # post-processing $res
+      return $res;
+  }
+
+The tricky thing about post processing the response is that it could
+either be an immediate 3 element array ref, or a code reference that
+implements the delayed (streaming) interface.
+
+Dealing with these two types of response in each piece of middleware
+is pointless, so you're recommended to use the C<response_cb> wrapper
+function in L<Plack::Util> when implementing a post processing
+middleware.
+
+  my $res = $app->($env);
+  Plack::Util::response_cb($res, sub {
+      my $res = shift;
+      # do something with $res;
+  });
+
+The callback function gets a PSGI response as a 3 element array
+reference, and you can update the reference to implement the post
+processing.
+
+  package Plack::Middleware::Always500;
+  use parent qw(Plack::Middleware);
+  use Plack::Util;
+
+  sub call {
+      my($self, $env) = @_;
+      my $res  = $self->app->($env);
+      Plack::Util::response_cb($res, sub {
+          my $res = shift;
+          $res->[0] = 500;
+          return;
+      });
+  }
+
+In this example, the callback gets the C<$res> and updates its first
+element (status code) to 500. Using C<response_cb> makes sure that
+this works with the delayed response too.
+
+You're not required (and not recommended either) to return a new array
+reference - they will be simply ignored. You're suggested to
+explicitly return, unless you fiddle with the content filter callback
+(see below).
+
+Similarly, note that you have to keep the C<$res> reference when you
+swap the entire response.
+
+  Plack::Util::response_cb($res, sub {
+      my $res = shift;
+      $res = [ $new_status, $new_headers, $new_body ]; # THIS DOES NOT WORK
+      return;
+  });
+
+This does not work, since assigning a new anonymous array to C<$res>
+doesn't update the original PSGI response value. You should instead
+do:
+
+  Plack::Util::response_cb($res, sub {
+      my $res = shift;
+      @$res = ($new_status, $new_headers, $new_body); # THIS WORKS
+      return;
+  });
+
+The third element of PSGI response array ref is a body, and it could
+be either array ref or IO::Handle-ish object. The application could
+also make use of C<$writer> object if C<psgi.streaming> is in
+effect. Dealing with these variants is again really painful, and
+C<response_cb> can take care of that too, by allowing you to return a
+content filter as a code reference.
+
+  # replace all "Foo" in content body with "Bar"
+  Plack::Util::response_cb($res, sub {
+      my $res = shift;
+      return sub {
+          my $chunk = shift;
+          return unless defined $chunk;
+          $chunk =~ s/Foo/Bar/g;
+          return $chunk;
+      }
+  });
+
+The callback takes one argument C<$chunk> and your callback is
+expected to return the updated chunk. If the given C<$chunk> is undef,
+it means the stream has reached the end, so your callback should also
+return undef, or return the final chunk and return undef when called
+next time.
+
 =head1 SEE ALSO
 
 L<Plack> L<Plack::Builder> L<Plack::Component>

Modified: branches/upstream/libplack-perl/current/lib/Plack/Middleware/Recursive.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/lib/Plack/Middleware/Recursive.pm?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/lib/Plack/Middleware/Recursive.pm (original)
+++ branches/upstream/libplack-perl/current/lib/Plack/Middleware/Recursive.pm Sat Feb 19 03:59:57 2011
@@ -17,6 +17,8 @@
     } catch {
         if (blessed $_ && $_->isa('Plack::Recursive::ForwardRequest')) {
             return $self->recurse_callback($env)->($_->path);
+        } else {
+            die $_; # rethrow
         }
     };
 
@@ -116,6 +118,14 @@
 Plack::Recursive::ForwardRequest anywhere in the code to I<forward>
 the current request (i.e. abort the current and redo the request).
 
+=head1 EXCEPTIONS
+
+This middleware passes through unknown exceptions to the outside
+middleware stack, so if you use this middleware with other exception
+handlers such as L<Plack::Middleware::StackTrace> or
+L<Plack::Middleware::HTTPExceptions>, be sure to wrap this so
+L<Plack::Middleware::Recursive> gets as inner as possible.
+
 =head1 AUTHORS
 
 Tatsuhiko Miyagawa

Modified: branches/upstream/libplack-perl/current/lib/Plack/Request.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/lib/Plack/Request.pm?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/lib/Plack/Request.pm (original)
+++ branches/upstream/libplack-perl/current/lib/Plack/Request.pm Sat Feb 19 03:59:57 2011
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 use 5.008_001;
-our $VERSION = '0.9967';
+our $VERSION = '0.9968';
 $VERSION = eval $VERSION;
 
 use HTTP::Headers;

Modified: branches/upstream/libplack-perl/current/lib/Plack/Response.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/lib/Plack/Response.pm?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/lib/Plack/Response.pm (original)
+++ branches/upstream/libplack-perl/current/lib/Plack/Response.pm Sat Feb 19 03:59:57 2011
@@ -1,7 +1,7 @@
 package Plack::Response;
 use strict;
 use warnings;
-our $VERSION = '0.9967';
+our $VERSION = '0.9968';
 $VERSION = eval $VERSION;
 
 use Plack::Util::Accessor qw(body status);

Modified: branches/upstream/libplack-perl/current/lib/Plack/Server/ServerSimple.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/lib/Plack/Server/ServerSimple.pm?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/lib/Plack/Server/ServerSimple.pm (original)
+++ branches/upstream/libplack-perl/current/lib/Plack/Server/ServerSimple.pm Sat Feb 19 03:59:57 2011
@@ -1,6 +1,6 @@
 package Plack::Server::ServerSimple;
 use strict;
-our $VERSION = '0.9967';
+our $VERSION = '0.9968';
 $VERSION = eval $VERSION;
 
 use parent qw(Plack::Handler::HTTP::Server::Simple);

Modified: branches/upstream/libplack-perl/current/lib/Plack/Util.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/lib/Plack/Util.pm?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/lib/Plack/Util.pm (original)
+++ branches/upstream/libplack-perl/current/lib/Plack/Util.pm Sat Feb 19 03:59:57 2011
@@ -490,6 +490,10 @@
 constructor. Handy to create when you need to create an IO stream
 object for input or errors.
 
+=item response_cb
+
+See L<Plack::Middleware/RESPONSE CALLBACK> for details.
+
 =back
 
 =cut

Modified: branches/upstream/libplack-perl/current/scripts/plackup
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/scripts/plackup?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/scripts/plackup (original)
+++ branches/upstream/libplack-perl/current/scripts/plackup Sat Feb 19 03:59:57 2011
@@ -43,11 +43,11 @@
 
   #!/usr/bin/perl
   use MyApp;
-  my $app = MyApp->new;
-  my $handler = sub { $app->run_psgi(@_) };
-
-The last statement of C<app.psgi> should be a code reference that is a
-PSGI application.
+  my $application = MyApp->new;
+  my $app = sub { $application->run_psgi(@_) };
+
+The last statement of C<app.psgi>, in this case C<$app>, should be a
+code reference that is a PSGI application.
 
 =head1 ARGUMENTS
 

Added: branches/upstream/libplack-perl/current/t/Plack-Middleware/cascade/basic.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/t/Plack-Middleware/cascade/basic.t?rev=69060&op=file
==============================================================================
--- branches/upstream/libplack-perl/current/t/Plack-Middleware/cascade/basic.t (added)
+++ branches/upstream/libplack-perl/current/t/Plack-Middleware/cascade/basic.t Sat Feb 19 03:59:57 2011
@@ -1,0 +1,29 @@
+use Plack::Test;
+use Test::More;
+
+use Plack::App::Cascade;
+use Plack::App::URLMap;
+use Plack::App::File;
+use HTTP::Request::Common;
+
+my $cascade = Plack::App::Cascade->new;
+$cascade->add( Plack::App::File->new(root => "t/Plack-Middleware")->to_app );
+$cascade->add( Plack::App::File->new(root => "t/Plack-Util")->to_app );
+
+my $app = Plack::App::URLMap->new;
+$app->map("/static", $cascade);
+
+test_psgi app => $app->to_app, client => sub {
+    my $cb = shift;
+
+    my $res = $cb->(GET "http://localhost/static/access_log.t");
+    is $res->code, 200;
+
+    $res = $cb->(GET "http://localhost/static/foo");
+    is $res->code, 404;
+
+    $res = $cb->(GET "http://localhost/static/foreach.t");
+    is $res->code, 200;
+};
+
+done_testing;

Added: branches/upstream/libplack-perl/current/t/Plack-Middleware/cascade/streaming.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/t/Plack-Middleware/cascade/streaming.t?rev=69060&op=file
==============================================================================
--- branches/upstream/libplack-perl/current/t/Plack-Middleware/cascade/streaming.t (added)
+++ branches/upstream/libplack-perl/current/t/Plack-Middleware/cascade/streaming.t Sat Feb 19 03:59:57 2011
@@ -1,0 +1,35 @@
+use Plack::Test;
+use Test::More;
+
+use Plack::App::Cascade;
+use HTTP::Request::Common;
+
+my $cascade = Plack::App::Cascade->new;
+$cascade->add( sub { return sub { my $respond = shift; $respond->([ 404, [], [ "Duh" ] ]) } } );
+$cascade->add( sub { return [ 403, [ 'Content-Type', 'text/plain' ], [ "Forbidden" ] ] } );
+$cascade->add( sub { my $env = shift;
+                     return sub {
+                         my $r = shift;
+                         if ($env->{PATH_INFO} eq '/') {
+                             my $w = $r->([ 200, [ 'Content-Type', 'text/plain' ] ]);
+                             $w->write("Hello");
+                             $w->close;
+                         } else {
+                             $r->([ 404, [ 'Content-Type', 'text/plain' ], [ "Not Found" ] ]);
+                         }
+                     } });
+
+$cascade->catch([ 403, 404 ]);
+
+test_psgi $cascade, sub {
+    my $cb = shift;
+
+    my $res = $cb->(GET "http://localhost/");
+    is $res->code, 200;
+    is $res->content, "Hello";
+
+    $res = $cb->(GET "http://localhost/xyz");
+    is $res->code, 404;
+};
+
+done_testing;

Modified: branches/upstream/libplack-perl/current/t/Plack-Middleware/recursive/throw.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/t/Plack-Middleware/recursive/throw.t?rev=69060&op=diff
==============================================================================
--- branches/upstream/libplack-perl/current/t/Plack-Middleware/recursive/throw.t (original)
+++ branches/upstream/libplack-perl/current/t/Plack-Middleware/recursive/throw.t Sat Feb 19 03:59:57 2011
@@ -13,6 +13,8 @@
         return [ 200, [ 'Content-Type', 'text/plain' ], [ "Hello $env->{QUERY_STRING}" ] ];
     } elsif ($env->{PATH_INFO} eq '/forwarded') {
         Plack::Recursive::ForwardRequest->throw("/forwarded2?q=bar");
+    } elsif ($env->{PATH_INFO} eq '/die') {
+        die "Foo";
     }
 
     Plack::Recursive::ForwardRequest->throw("/forwarded?q=bar");
@@ -26,6 +28,10 @@
     my $res = $cb->(GET "/");
     is $res->code, 200;
     is $res->content, "Hello q=bar";
+
+    $res = $cb->(GET "/die");
+    is $res->code, 500;
+    like $res->content, qr/Foo at t/;
 };
 
 done_testing;

Added: branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/basic.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/basic.t?rev=69060&op=file
==============================================================================
--- branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/basic.t (added)
+++ branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/basic.t Sat Feb 19 03:59:57 2011
@@ -1,0 +1,29 @@
+use strict;
+use warnings;
+use Test::More;
+use Plack::Middleware::StackTrace;
+use Plack::Test;
+use HTTP::Request::Common;
+
+my $traceapp = Plack::Middleware::StackTrace->wrap(sub { die "orz" }, no_print_errors => 1);
+my $app = sub {
+    my $env = shift;
+    my $ret = $traceapp->($env);
+    like $env->{'plack.stacktrace.text'}, qr/orz/;
+    return $ret;
+};
+
+test_psgi $app, sub {
+    my $cb = shift;
+
+    my $req = GET "/";
+    $req->header(Accept => "text/html,*/*");
+    my $res = $cb->($req);
+
+    ok $res->is_error;
+    is_deeply [ $res->content_type ], [ 'text/html', 'charset=utf-8' ];
+    like $res->content, qr/<title>Error: orz/;
+};
+
+done_testing;
+

Added: branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/force.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/force.t?rev=69060&op=file
==============================================================================
--- branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/force.t (added)
+++ branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/force.t Sat Feb 19 03:59:57 2011
@@ -1,0 +1,39 @@
+use strict;
+use warnings;
+use Test::More;
+use Plack::Middleware::StackTrace;
+use Plack::Test;
+use HTTP::Request::Common;
+
+my $app = sub {
+    eval { die "Blah" };
+
+    return [ 500, [ 'Content-Type', 'text/html' ], [ "Fancy Error" ] ];
+};
+
+my $default_app = Plack::Middleware::StackTrace->wrap($app, no_print_errors => 1);
+
+test_psgi $default_app, sub {
+    my $cb = shift;
+
+    my $req = GET "/";
+    my $res = $cb->($req);
+
+    is $res->code, 500;
+    like $res->content, qr/Fancy Error/;
+};
+
+my $force_app = Plack::Middleware::StackTrace->wrap($app, force => 1, no_print_errors => 1);
+
+test_psgi $force_app, sub {
+    my $cb = shift;
+
+    my $req = GET "/";
+    my $res = $cb->($req);
+
+    is $res->code, 500;
+    like $res->content, qr/Blah/;
+};
+
+done_testing;
+

Added: branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/streaming.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/streaming.t?rev=69060&op=file
==============================================================================
--- branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/streaming.t (added)
+++ branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/streaming.t Sat Feb 19 03:59:57 2011
@@ -1,0 +1,30 @@
+use strict;
+use warnings;
+use Test::More;
+use Plack::Middleware::StackTrace;
+use Plack::Test;
+use HTTP::Request::Common;
+
+my $app = sub {
+    eval { require DooBar };
+
+    return sub {
+        my $respond = shift;
+        $respond->([ 200, [ "Content-Type", "text/plain" ], [ "Hello World" ] ]);
+    };
+};
+
+$app = Plack::Middleware::StackTrace->wrap($app);
+
+test_psgi $app, sub {
+    my $cb = shift;
+
+    my $req = GET "/";
+    my $res = $cb->($req);
+
+    ok $res->is_success;
+    like $res->content, qr/Hello World/;
+};
+
+done_testing;
+

Added: branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/utf8.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/utf8.t?rev=69060&op=file
==============================================================================
--- branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/utf8.t (added)
+++ branches/upstream/libplack-perl/current/t/Plack-Middleware/stacktrace/utf8.t Sat Feb 19 03:59:57 2011
@@ -1,0 +1,28 @@
+use strict;
+use warnings;
+use Test::More;
+use Test::Requires { 'Devel::StackTrace::AsHTML' => 0.08 };
+use Plack::Middleware::StackTrace;
+use Plack::Test;
+use HTTP::Request::Common;
+
+$Plack::Test::Impl = "Server";
+my $app = Plack::Middleware::StackTrace->wrap(sub { die "Foo \x{30c6}" }, no_print_errors => 1);
+
+test_psgi $app, sub {
+    my $cb = shift;
+
+    my $req = GET "/";
+    $req->header(Accept => "text/html,*/*");
+    my $res = $cb->($req);
+
+    like $res->content, qr/Foo &#12486;/;
+
+    $req = GET "/";
+    $res = $cb->($req);
+    is $res->code, 500;
+    like $res->content, qr/Foo/;
+};
+
+done_testing;
+




More information about the Pkg-perl-cvs-commits mailing list