plack/Plack — pull request #369 by miyagawa (2013-02-08 03:05:45+00:00)
Title: Give warnings in to_app() auto promotion

Here's one of the under-documented features in Plack: If a .psgi file returns an object that has `to_app` method, plackup will automatically call the method, to make it a PSGI code reference.

When you combine that with Plack::Builder with `builder { ...; $app }`, or use the command line `plackup -e 'Plack::App::File->new'` with the default *development* environment, the application object is now **wrapped by the builder and default middleware** - which means there's no chance of calling `->to_app`.

PSGI handlers will now have `$app` as an object to call as a code ref, and at the runtime, Plack::App::Component automatically promotes itself to the coderef via `to_app`, with the sub overloading, **for each request**.

This is bad in terms of performance and all that, and messy, so here're two attempts in this pull request to make it less worse:

a) Gives warning when such automatic conversion happens, when PLACK_ENV is set to development, so that developers will notice that something is wrong, and that they have to call `->to_app` to get the right PSGI application.

b) Move the automatic promotion code to Builder. Ideally this conversion should be gone in the future (or at least specified as part of the specification etc.), but this is necessary for a backward compatibility reason, to prevent the actual use of `plackup -e 'Plack::App::File->new'` from breaking with the upgrade.