Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSGI file evaluation convention #12

Open
miyagawa opened this issue Apr 22, 2011 · 3 comments
Open

PSGI file evaluation convention #12

miyagawa opened this issue Apr 22, 2011 · 3 comments

Comments

@miyagawa
Copy link
Member

https://github.com/plack/psgi-specs/wiki/PSGI-file-evaluation-convention

Attach your feedbacks to this issue.

@dolmen
Copy link

dolmen commented Jul 22, 2011

I load my PSGI apps with "require" instead of "eval do". "require" returns the result of last expression of the file, so that works well.

This allow me to make a clean package for the application, with a known namespace, and so I can distribute the application as a CPAN distribution. Also, "require" use @inc to find the file.

Here is an example: https://metacpan.org/source/DOLMEN/Pod-POM-Web-PSGI-0.002/lib/Pod/POM/Web/PSGI.pm (have a look at the code AND the POD).

@miyagawa
Copy link
Member Author

Yes, I like it, but one problem with require is that you can't instantiate the same application twice, which means it gets moot when the module is preloaded somehow, or when you want to instantiate the app per children in a forked environment.

my $app1 = require MyApp::PSGI;
mu $app2 = require MyApp::PSGI; # doesn't work

@miyagawa
Copy link
Member Author

This convention doesn't prevent you from loading your app with require though - this is more lower level discussion that happens in the web server when given a path to the .psgi file. You can always do require MyApp inside .psgi, like you can currently do.

Whether your app/framework gives the PSGI code refs with require (as in the return value of the .pm) or ->psgi_app or sub { MyApp->run_psgi } or anything else, is out of the scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants