X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FWeb%2FSimple%2FApplication.pm;fp=lib%2FWeb%2FSimple%2FApplication.pm;h=99e64363e9d47458f7db9ea9583990edd0c5654c;hb=6a4808bf0d52746eec29e8335002600600ea07c4;hp=05873c5d643982e504338edc04c249d241549fae;hpb=32d29dcd27e2b021ba40a6e39b2fcdff601b9742;p=catagits%2FWeb-Simple.git diff --git a/lib/Web/Simple/Application.pm b/lib/Web/Simple/Application.pm index 05873c5..99e6436 100644 --- a/lib/Web/Simple/Application.pm +++ b/lib/Web/Simple/Application.pm @@ -99,7 +99,7 @@ sub _cli_usage { =head1 NAME -Web::Simple::Application - A base class for your Web-Simple applications +Web::Simple::Application - A base class for your Web-Simple application =head1 DESCRIPTION @@ -109,11 +109,12 @@ lifting' for you in that regards. =head1 METHODS -This class exposes the follow public methods. +This class exposes the following public methods. =head2 default_config -Provide configuration information to your application, for example: +Merges with the C initializer to provide configuration information for +your application. For example: sub default_config { ( @@ -122,12 +123,18 @@ Provide configuration information to your application, for example: ); } -Now, C<$self> will have an attribute C which will be set to a HashRef +Now, the C attribute of C<$self> will be set to a HashRef containing keys 'title' and 'posts_dir'. +If you construct your application like: + + MyWebSimpleApp::Web->new(config=>{environment=>'dev'}) + +then C will have a C key with a value of 'dev'. + =head2 run_if_script -In the case where you wish to run you L based application as a +In the case where you wish to run your L based application as a stand alone CGI application, you can simple do: ## my_web_simple_app.pl @@ -155,6 +162,18 @@ Or (even more simply) just inline the entire application: HelloWorld->run_if_script; +Additionally, you can treat the above script as though it were a standard PSGI +application file (*.psgi). For example you can start up up with C + + plackup my_web_simple_app.pl + +Which means you can write a L application as a plain old CGI +application and seemlessly migrate to a L based solution when you are +ready for that. + +Lastly, L will automatically detect and support a Fast CGI +environment. + =head2 to_psgi_app Given a L application root namespace, return it in a form suitable @@ -182,6 +201,26 @@ L application; your app.psgi could be as simple as: use MyWebSimpleApp::Web; MyWebSimpleApp::Web->to_psgi_app; +This means if you want to provide a 'default' set of middleware, one option is +to modify this method: + + use Web::Simple 'HelloWorld'; + use Plack::Builder; + + { + package HelloWorld; + + + around 'to_psgi_app', sub { + my ($orig, $self) = (shift, shift); + my $app = $self->$orig(@_); + builder { + enable ...; ## whatever middleware you want + $app; + }; + }; + } + As always, mix and match the pieces you actually need and remember the L philosophy of trying to keep it as minimal and simple as possible. @@ -204,7 +243,7 @@ None required yet. Maybe this module is perfect (hahahahaha ...). =head1 COPYRIGHT -Copyright (c) 2009 the Web::Simple L and L +Copyright (c) 2010 the Web::Simple L and L as listed above. =head1 LICENSE