715cd3ee0b26046b4743daee00a103da2d28e0a5
[catagits/Web-Simple.git] / lib / Web / Simple.pm
1 package Web::Simple;
2
3 use strictures 1;
4 use 5.008;
5 use warnings::illegalproto ();
6 use Moo ();
7 use Web::Dispatch::Wrapper ();
8
9 our $VERSION = '0.020';
10
11 sub import {
12   my ($class, $app_package) = @_;
13   $app_package ||= caller;
14   $class->_export_into($app_package);
15   eval "package $app_package; use Web::Dispatch::Wrapper; use Moo; 1"
16     or die "Failed to setup app package: $@";
17   strictures->import;
18   warnings::illegalproto->unimport;
19 }
20
21 sub _export_into {
22   my ($class, $app_package) = @_;
23   {
24     no strict 'refs';
25     *{"${app_package}::PSGI_ENV"} = sub () { -1 };
26     require Web::Simple::Application;
27     unshift(@{"${app_package}::ISA"}, 'Web::Simple::Application');
28   }
29   (my $name = $app_package) =~ s/::/\//g;
30   $INC{"${name}.pm"} = 'Set by "use Web::Simple;" invocation';
31 }
32
33 1;
34
35 =head1 NAME
36
37 Web::Simple - A quick and easy way to build simple web applications
38
39
40 =head1 SYNOPSIS
41
42   #!/usr/bin/env perl
43
44   package HelloWorld;
45   use Web::Simple;
46
47   sub dispatch_request {
48     sub (GET) {
49       [ 200, [ 'Content-type', 'text/plain' ], [ 'Hello world!' ] ]
50     },
51     sub () {
52       [ 405, [ 'Content-type', 'text/plain' ], [ 'Method not allowed' ] ]
53     }
54   }
55
56   HelloWorld->run_if_script;
57
58 If you save this file into your cgi-bin as C<hello-world.cgi> and then visit:
59
60   http://my.server.name/cgi-bin/hello-world.cgi/
61
62 you'll get the "Hello world!" string output to your browser. At the same time
63 this file will also act as a class module, so you can save it as HelloWorld.pm
64 and use it as-is in test scripts or other deployment mechanisms.
65
66 Note that you should retain the ->run_if_script even if your app is a
67 module, since this additionally makes it valid as a .psgi file, which can
68 be extremely useful during development.
69
70 For more complex examples and non-CGI deployment, see
71 L<Web::Simple::Deployment>. To get help with L<Web::Simple>, please connect to
72 the irc.perl.org IRC network and join #web-simple.
73
74 =head1 DESCRIPTION
75
76 The philosophy of L<Web::Simple> is to keep to an absolute bare minimum for
77 everything. It is not designed to be used for large scale applications;
78 the L<Catalyst> web framework already works very nicely for that and is
79 a far more mature, well supported piece of software.
80
81 However, if you have an application that only does a couple of things, and
82 want to not have to think about complexities of deployment, then L<Web::Simple>
83 might be just the thing for you.
84
85 The only public interface the L<Web::Simple> module itself provides is an
86 C<import> based one:
87
88   use Web::Simple 'NameOfApplication';
89
90 This sets up your package (in this case "NameOfApplication" is your package)
91 so that it inherits from L<Web::Simple::Application> and imports L<strictures>,
92 as well as installs a C<PSGI_ENV> constant for convenience, as well as some
93 other subroutines.
94
95 Importing L<strictures> will automatically make your code use the C<strict> and
96 C<warnings> pragma, so you can skip the usual:
97
98   use strict;
99   use warnings FATAL => 'aa';
100
101 provided you 'use Web::Simple' at the top of the file. Note that we turn
102 on *fatal* warnings so if you have any warnings at any point from the file
103 that you did 'use Web::Simple' in, then your application will die. This is,
104 so far, considered a feature.
105
106 When we inherit from L<Web::Simple::Application> we also use L<Moo>, which is
107 the the equivalent of:
108
109   {
110     package NameOfApplication;
111     use Moo;
112     extends 'Web::Simple::Application';
113   }
114
115 So you can use L<Moo> features in your application, such as creating attributes
116 using the C<has> subroutine, etc.  Please see the documentation for L<Moo> for
117 more information.
118
119 It also exports the following subroutines for use in dispatchers:
120
121   response_filter { ... };
122
123   redispatch_to '/somewhere';
124
125 Finally, import sets
126
127   $INC{"NameOfApplication.pm"} = 'Set by "use Web::Simple;" invocation';
128
129 so that perl will not attempt to load the application again even if
130
131   require NameOfApplication;
132
133 is encountered in other code.
134
135 One important thing to remember when using
136
137   NameOfApplication->run_if_script;
138
139 At the end of your app is that this call will create an instance of your app
140 for you automatically, regardless of context. An easier way to think of this
141 would be if the method were more verbosely named
142
143  NameOfApplication->run_request_if_script_else_turn_coderef_for_psgi;
144
145 =head1 DISPATCH STRATEGY
146
147 L<Web::Simple> despite being straightforward to use, has a powerful system
148 for matching all sorts of incoming URLs to one or more subroutines.  These
149 subroutines can be simple actions to take for a given URL, or something
150 more complicated, including entire L<Plack> applications, L<Plack::Middleware>
151 and nested subdispatchers.
152
153 =head2 Examples
154
155  sub dispatch_request {
156    # matches: GET /user/1.htm?show_details=1
157    #          GET /user/1.htm
158    sub (GET + /user/* + ?show_details~ + .htm|.html|.xhtml) {
159      my ($self, $user_id, $show_details) = @_;
160      ...
161    },
162    # matches: POST /user?username=frew
163    #          POST /user?username=mst&first_name=matt&last_name=trout
164    sub (POST + /user + ?username=&*) {
165       my ($self, $username, $misc_params) = @_;
166      ...
167    },
168    # matches: DELETE /user/1/friend/2
169    sub (DELETE + /user/*/friend/*) {
170      my ($self, $user_id, $friend_id) = @_;
171      ...
172    },
173    # matches: PUT /user/1?first_name=Matt&last_name=Trout
174    sub (PUT + /user/* + ?first_name~&last_name~) {
175      my ($self, $user_id, $first_name, $last_name) = @_;
176      ...
177    },
178    sub (/user/*/...) {
179      my $user_id = $_[1];
180      # matches: PUT /user/1/role/1
181      sub (PUT + /role/*) {
182        my $role_id = $_[1];
183        ...
184      },
185      # matches: DELETE /user/1/role/1
186      sub (DELETE + /role/*) {
187        my $role_id = $_[1];
188        ...
189      },
190    },
191  }
192
193 =head2 The dispatch cycle
194
195 At the beginning of a request, your app's dispatch_request method is called
196 with the PSGI $env as an argument. You can handle the request entirely in
197 here and return a PSGI response arrayref if you want:
198
199   sub dispatch_request {
200     my ($self, $env) = @_;
201     [ 404, [ 'Content-type' => 'text/plain' ], [ 'Amnesia == fail' ] ]
202   }
203
204 However, generally, instead of that, you return a set of dispatch subs:
205
206   sub dispatch_request {
207     my $self = shift;
208     sub (/) { redispatch_to '/index.html' },
209     sub (/user/*) { $self->show_user($_[1]) },
210     ...
211   }
212
213 Well, a sub is a valid PSGI response too (for ultimate streaming and async
214 cleverness). If you want to return a PSGI sub you have to wrap it into an
215 array ref.
216
217   sub dispatch_request {
218     [ sub {
219         my $respond = shift;
220         # This is pure PSGI here, so read perldoc PSGI
221     } ]
222   }
223
224 If you return a subroutine with a prototype, the prototype is treated
225 as a match specification - and if the test is passed, the body of the
226 sub is called as a method and passed any matched arguments (see below for more details).
227
228 You can also return a plain subroutine which will be called with just C<$env>
229 - remember that in this case if you need C<$self> you B<must> close over it.
230
231 If you return a normal object, L<Web::Simple> will simply return it upwards on
232 the assumption that a response_filter (or some arbitrary L<Plack::Middleware>)
233 somewhere will convert it to something useful.  This allows:
234
235   sub dispatch_request {
236     my $self = shift;
237     sub (.html) { response_filter { $self->render_zoom($_[0]) } },
238     sub (/user/*) { $self->users->get($_[1]) },
239   }
240
241 An alternative to using prototypes to declare a match specification for a given
242 route is to provide a Dancer like key-value list:
243
244   sub dispatch_request {
245     my $self = shift;
246     (
247       '.html' => sub { response_filter { $self->render_zoom($_[0]) } },
248       '/user/*' => sub { $self->users->get($_[1]) }<
249     )
250   }
251
252 This can be useful in situations where you are generating a dispatch table
253 programmatically, where setting a subroutines protoype is difficult.
254
255 to render a user object to HTML, if there is an incoming URL such as:
256
257   http://myweb.org/user/111.html
258
259 This works because as we descend down the dispachers, we first match
260 C<sub (.html)>, which adds a C<response_filter> (basically a specialized routine
261 that follows the L<Plack::Middleware> specification), and then later we also
262 match C<sub (/user/*)> which gets a user and returns that as the response.
263 This user object 'bubbles up' through all the wrapping middleware until it hits
264 the C<response_filter> we defined, after which the return is converted to a
265 true html response.
266
267 However, two types of objects are treated specially - a C<Plack::Component> object
268 will have its C<to_app> method called and be used as a dispatcher:
269
270   sub dispatch_request {
271     my $self = shift;
272     sub (/static/...) { Plack::App::File->new(...) },
273     ...
274   }
275
276 A L<Plack::Middleware> object will be used as a filter for the rest of the
277 dispatch being returned into:
278
279   ## responds to /admin/track_usage AND /admin/delete_accounts
280
281   sub dispatch_request {
282     my $self = shift;
283     sub (/admin/**) {
284       Plack::Middleware::Session->new(%opts);
285     },
286     sub (/admin/track_usage) {
287       ## something that needs a session
288     },
289     sub (/admin/delete_accounts) {
290       ## something else that needs a session
291     },
292   }
293
294 Note that this is for the dispatch being B<returned> to, so if you want to
295 provide it inline you need to do:
296
297   ## ALSO responds to /admin/track_usage AND /admin/delete_accounts
298
299   sub dispatch_request {
300     my $self = shift;
301     sub (/admin/...) {
302       sub {
303         Plack::Middleware::Session->new(%opts);
304       },
305       sub (/track_usage) {
306         ## something that needs a session
307       },
308       sub (/delete_accounts) {
309         ## something else that needs a session
310       },
311     }
312   }
313
314 And that's it - but remember that all this happens recursively - it's
315 dispatchers all the way down.  A URL incoming pattern will run all matching
316 dispatchers and then hit all added filters or L<Plack::Middleware>.
317
318 =head2 Web::Simple match specifications
319
320 =head3 Method matches
321
322   sub (GET) {
323
324 A match specification beginning with a capital letter matches HTTP requests
325 with that request method.
326
327 =head3 Path matches
328
329   sub (/login) {
330
331 A match specification beginning with a / is a path match. In the simplest
332 case it matches a specific path. To match a path with a wildcard part, you
333 can do:
334
335   sub (/user/*) {
336     $self->handle_user($_[1])
337
338 This will match /user/<anything> where <anything> does not include a literal
339 / character. The matched part becomes part of the match arguments. You can
340 also match more than one part:
341
342   sub (/user/*/*) {
343     my ($self, $user_1, $user_2) = @_;
344
345   sub (/domain/*/user/*) {
346     my ($self, $domain, $user) = @_;
347
348 and so on. To match an arbitrary number of parts, use C<**>:
349
350   sub (/page/**) {
351     my ($self, $match) = @_;
352
353 This will result in a single element for the entire match. Note that you can do
354
355   sub (/page/**/edit) {
356
357 to match an arbitrary number of parts up to but not including some final
358 part.
359
360 Note: Since Web::Simple handles a concept of file extensions, C<*> and C<**>
361 matchers will not by default match things after a final dot, and this
362 can be modified by using C<*.*> and C<**.*> in the final position, e.g.:
363
364   /one/*       matches /one/two.three    and captures "two"
365   /one/*.*     matches /one/two.three    and captures "two.three"
366   /**          matches /one/two.three    and captures "one/two"
367   /**.*        matches /one/two.three    and captures "one/two.three"
368
369 Finally,
370
371   sub (/foo/...) {
372
373 Will match C</foo/> on the beginning of the path B<and> strip it. This is
374 designed to be used to construct nested dispatch structures, but can also prove
375 useful for having e.g. an optional language specification at the start of a
376 path.
377
378 Note that the '...' is a "maybe something here, maybe not" so the above
379 specification will match like this:
380
381   /foo         # no match
382   /foo/        # match and strip path to '/'
383   /foo/bar/baz # match and strip path to '/bar/baz'
384
385 Almost the same,
386
387   sub (/foo...) {
388
389 Will match on C</foo/bar/baz>, but also include C</foo>.  Otherwise it
390 operates the same way as C</foo/...>.
391
392   /foo         # match and strip path to ''
393   /foo/        # match and strip path to '/'
394   /foo/bar/baz # match and strip path to '/bar/baz'
395
396 Please note the difference between C<sub(/foo/...)> and C<sub(/foo...)>.  In
397 the first case, this is expecting to find something after C</foo> (and fails to
398 match if nothing is found), while in the second case we can match both C</foo>
399 and C</foo/more/to/come>.  The following are roughly the same:
400
401   sub (/foo)   { 'I match /foo' },
402   sub (/foo/...) {
403     sub (/bar) { 'I match /foo/bar' },
404     sub (/*)   { 'I match /foo/{id}' },
405   }
406
407 Versus
408
409   sub (/foo...) {
410     sub (~)    { 'I match /foo' },
411     sub (/bar) { 'I match /foo/bar' },
412     sub (/*)   { 'I match /foo/{id}' },
413   }
414
415 You may prefer the latter example should you wish to take advantage of
416 subdispatchers to scope common activities.  For example:
417
418   sub (/user...) {
419     my $user_rs = $schema->resultset('User');
420     sub (~) { $user_rs },
421     sub (/*) { $user_rs->find($_[1]) },
422   }
423
424 You should note the special case path match C<sub (~)> which is only meaningful
425 when it is contained in this type of path match. It matches to an empty path.
426
427 =head4 Naming your patch matches
428
429 Any C<*>, C<**>, C<*.*>, or C<**.*> match can be followed with C<:name> to make it into a named
430 match, so:
431
432   sub (/*:one/*:two/*:three/*:four) {
433     "I match /1/2/3/4 capturing { one => 1, two =>  2, three => 3, four => 4 }"
434   }
435   
436   sub (/**.*:allofit) {
437     "I match anything capturing { allofit => \$whole_path }"
438   }
439
440 In the specific case of a simple single-* match, the * may be omitted, to
441 allow you to write:
442
443   sub (/:one/:two/:three/:four) {
444     "I match /1/2/3/4 capturing { one => 1, two =>  2, three => 3, four => 4 }"
445   }
446
447 =head4 C</foo> and C</foo/> are different specs
448
449 As you may have noticed with the difference between C<sub(/foo/...)> and
450 C<sub(/foo...)>, trailing slashes in path specs are significant. This is
451 intentional and necessary to retain the ability to use relative links on
452 websites. Let's demonstrate on this link:
453
454   <a href="bar">bar</a>
455
456 If the user loads the url C</foo/> and clicks on this link, they will be
457 sent to C</foo/bar>. However when they are on the url C</foo> and click this
458 link, then they will be sent to C</bar>.
459
460 This makes it necessary to be explicit about the trailing slash.
461
462 =head3 Extension matches
463
464   sub (.html) {
465
466 will match .html from the path (assuming the subroutine itself returns
467 something, of course). This is normally used for rendering - e.g.:
468
469   sub (.html) {
470     response_filter { $self->render_html($_[1]) }
471   }
472
473 Additionally,
474
475   sub (.*) {
476
477 will match any extension and supplies the extension as a match argument.
478
479 =head3 Query and body parameter matches
480
481 Query and body parameters can be match via
482
483   sub (?<param spec>) { # match URI query
484   sub (%<param spec>) { # match body params
485
486 The body spec will match if the request content is either
487 application/x-www-form-urlencoded or multipart/form-data - the latter
488 of which is required for uploads - see below.
489
490 The param spec is elements of one of the following forms:
491
492   param~        # optional parameter
493   param=        # required parameter
494   @param~       # optional multiple parameter
495   @param=       # required multiple parameter
496   :param~       # optional parameter in hashref
497   :param=       # required parameter in hashref
498   :@param~      # optional multiple in hashref
499   :@param=      # required multiple in hashref
500   *             # include all other parameters in hashref
501   @*            # include all other parameters as multiple in hashref
502
503 separated by the C<&> character. The arguments added to the request are
504 one per non-C<:>/C<*> parameter (scalar for normal, arrayref for multiple),
505 plus if any C<:>/C<*> specs exist a hashref containing those values.
506
507 Please note that if you specify a multiple type parameter match, you are
508 ensured of getting an arrayref for the value, EVEN if the current incoming
509 request has only one value.  However if a parameter is specified as single
510 and multiple values are found, the last one will be used.
511
512 For example to match a C<page> parameter with an optional C<order_by> parameter one
513 would write:
514
515   sub (?page=&order_by~) {
516     my ($self, $page, $order_by) = @_;
517     return unless $page =~ /^\d+$/;
518     $page ||= 'id';
519     response_filter {
520       $_[1]->search_rs({}, $p);
521     }
522   }
523
524 to implement paging and ordering against a L<DBIx::Class::ResultSet> object.
525
526 Another Example: To get all parameters as a hashref of arrayrefs, write:
527
528   sub(?@*) {
529     my ($self, $params) = @_;
530     ...
531
532 To get two parameters as a hashref, write:
533
534   sub(?:user~&:domain~) {
535     my ($self, $params) = @_; # params contains only 'user' and 'domain' keys
536
537 You can also mix these, so:
538
539   sub (?foo=&@bar~&:coffee=&@*) {
540      my ($self, $foo, $bar, $params);
541
542 where $bar is an arrayref (possibly an empty one), and $params contains
543 arrayref values for all parameters B<not> mentioned and a scalar value for
544 the 'coffee' parameter.
545
546 Note, in the case where you combine arrayref, single parameter and named
547 hashref style, the arrayref and single parameters will appear in C<@_> in the
548 order you defined them in the protoype, but all hashrefs will merge into a
549 single C<$params>, as in the example above.
550
551 =head3 Upload matches
552
553   sub (*foo=) { # param specifier can be anything valid for query or body
554
555 The upload match system functions exactly like a query/body match, except
556 that the values returned (if any) are C<Web::Dispatch::Upload> objects.
557
558 Note that this match type will succeed in two circumstances where you might
559 not expect it to - first, when the field exists but is not an upload field
560 and second, when the field exists but the form is not an upload form (i.e.
561 content type "application/x-www-form-urlencoded" rather than
562 "multipart/form-data"). In either of these cases, what you'll get back is
563 a C<Web::Dispatch::NotAnUpload> object, which will C<die> with an error
564 pointing out the problem if you try and use it. To be sure you have a real
565 upload object, call
566
567   $upload->is_upload # returns 1 on a valid upload, 0 on a non-upload field
568
569 and to get the reason why such an object is not an upload, call
570
571   $upload->reason # returns a reason or '' on a valid upload.
572
573 Other than these two methods, the upload object provides the same interface
574 as L<Plack::Request::Upload> with the addition of a stringify to the temporary
575 filename to make copying it somewhere else easier to handle.
576
577 =head3 Combining matches
578
579 Matches may be combined with the + character - e.g.
580
581   sub (GET + /user/*) {
582
583 to create an AND match. They may also be combined withe the | character - e.g.
584
585   sub (GET|POST) {
586
587 to create an OR match. Matches can be nested with () - e.g.
588
589   sub ((GET|POST) + /user/*) {
590
591 and negated with ! - e.g.
592
593   sub (!/user/foo + /user/*) {
594
595 ! binds to the immediate rightmost match specification, so if you want
596 to negate a combination you will need to use
597
598   sub ( !(POST|PUT|DELETE) ) {
599
600 and | binds tighter than +, so
601
602   sub ((GET|POST) + /user/*) {
603
604 and
605
606   sub (GET|POST + /user/*) {
607
608 are equivalent, but
609
610   sub ((GET + /admin/...) | (POST + /admin/...)) {
611
612 and
613
614   sub (GET + /admin/... | POST + /admin/...) {
615
616 are not - the latter is equivalent to
617
618   sub (GET + (/admin/...|POST) + /admin/...) {
619
620 which will never match!
621
622 =head3 Whitespace
623
624 Note that for legibility you are permitted to use whitespace:
625
626   sub (GET + /user/*) {
627
628 but it will be ignored. This is because the perl parser strips whitespace
629 from subroutine prototypes, so this is equivalent to
630
631   sub (GET+/user/*) {
632
633 =head3 Accessing parameters via C<%_>
634
635 If your dispatch specification causes your dispatch subroutine to receive
636 a hash reference as its first argument, the contained named parameters
637 will be accessible via C<%_>.
638
639 This can be used to access your path matches, if they are named:
640
641   sub (GET + /foo/:path_part) {
642     [ 200,
643       ['Content-type' => 'text/plain'],
644       ["We are in $_{path_part}"],
645     ];
646   }
647
648 Or, if your first argument would be a hash reference containing named
649 query parameters:
650
651   sub (GET + /foo + ?:some_param=) {
652     [ 200,
653       ['Content-type' => 'text/plain'],
654       ["We received $_{some_param} as parameter"],
655     ];
656   }
657
658 Of course this also works when all you are doing is slurping the whole set
659 of parameters by their name:
660
661   sub (GET + /foo + ?*) {
662     [ 200,
663       ['Content-type' => 'text/plain'],
664       [exists($_{foo}) ? "Received a foo: $_{foo}" : "No foo!"],
665     ],
666   }
667
668 Note that only the first hash reference will be available via C<%_>. If
669 you receive additional hash references, you will need to access them as
670 usual.
671
672 =head3 Accessing the PSGI env hash
673
674 In some cases you may wish to get the raw PSGI env hash - to do this,
675 you can either use a plain sub:
676
677   sub {
678     my ($env) = @_;
679     ...
680   }
681
682 or use the C<PSGI_ENV> constant exported to retrieve it from C<@_>:
683
684   sub (GET + /foo + ?some_param=) {
685     my $param = $_[1];
686     my $env = $_[PSGI_ENV];
687   }
688
689 but note that if you're trying to add a middleware, you should simply use
690 Web::Simple's direct support for doing so.
691
692 =head1 EXPORTED SUBROUTINES
693
694 =head2 response_filter
695
696   response_filter {
697     # Hide errors from the user because we hates them, preciousss
698     if (ref($_[0]) eq 'ARRAY' && $_[0]->[0] == 500) {
699       $_[0] = [ 200, @{$_[0]}[1..$#{$_[0]}] ];
700     }
701     return $_[0];
702   };
703
704 The response_filter subroutine is designed for use inside dispatch subroutines.
705
706 It creates and returns a special dispatcher that always matches, and calls
707 the block passed to it as a filter on the result of running the rest of the
708 current dispatch chain.
709
710 Thus the filter above runs further dispatch as normal, but if the result of
711 dispatch is a 500 (Internal Server Error) response, changes this to a 200 (OK)
712 response without altering the headers or body.
713
714 =head2 redispatch_to
715
716   redispatch_to '/other/url';
717
718 The redispatch_to subroutine is designed for use inside dispatch subroutines.
719
720 It creates and returns a special dispatcher that always matches, and instead
721 of continuing dispatch re-delegates it to the start of the dispatch process,
722 but with the path of the request altered to the supplied URL.
723
724 Thus if you receive a POST to C</some/url> and return a redispatch to
725 C</other/url>, the dispatch behaviour will be exactly as if the same POST
726 request had been made to C</other/url> instead.
727
728 Note, this is not the same as returning an HTTP 3xx redirect as a response;
729 rather it is a much more efficient internal process.
730
731 =head1 CHANGES BETWEEN RELEASES
732
733 =head2 Changes between 0.004 and 0.005
734
735 =over 4
736
737 =item * dispatch {} replaced by declaring a dispatch_request method
738
739 dispatch {} has gone away - instead, you write:
740
741   sub dispatch_request {
742     my $self = shift;
743     sub (GET /foo/) { ... },
744     ...
745   }
746
747 Note that this method is still B<returning> the dispatch code - just like
748 C<dispatch> did.
749
750 Also note that you need the C<< my $self = shift >> since the magic $self
751 variable went away.
752
753 =item * the magic $self variable went away.
754
755 Just add C<< my $self = shift; >> while writing your C<< sub dispatch_request { >>
756 like a normal perl method.
757
758 =item * subdispatch deleted - all dispatchers can now subdispatch
759
760 In earlier releases you needed to write:
761
762   subdispatch sub (/foo/...) {
763     ...
764     [
765       sub (GET /bar/) { ... },
766       ...
767     ]
768   }
769
770 As of 0.005, you can instead write simply:
771
772   sub (/foo/...) {
773     ...
774     (
775       sub (GET /bar/) { ... },
776       ...
777     )
778   }
779
780 =back
781
782 =head2 Changes since Antiquated Perl
783
784 =over 4
785
786 =item * filter_response renamed to response_filter
787
788 This is a pure rename; a global search and replace should fix it.
789
790 =item * dispatch [] changed to dispatch {}
791
792 Simply changing
793
794   dispatch [ sub(...) { ... }, ... ];
795
796 to
797
798   dispatch { sub(...) { ... }, ... };
799
800 should work fine.
801
802 =back
803
804 =head1 DEVELOPMENT HISTORY
805
806 Web::Simple was originally written to form part of my Antiquated Perl talk for
807 Italian Perl Workshop 2009, but in writing the bloggery example I realised
808 that having a bare minimum system for writing web applications that doesn't
809 drive me insane was rather nice and decided to spend my attempt at nanowrimo
810 for 2009 improving and documenting it to the point where others could use it.
811
812 The Antiquated Perl talk can be found at L<http://www.shadowcat.co.uk/archive/conference-video/> and the slides are reproduced in this distribution under
813 L<Web::Simple::AntiquatedPerl>.
814
815 =head1 COMMUNITY AND SUPPORT
816
817 =head2 IRC channel
818
819 irc.perl.org #web-simple
820
821 =head2 No mailing list yet
822
823 Because mst's non-work email is a bombsite so he'd never read it anyway.
824
825 =head2 Git repository
826
827 Gitweb is on http://git.shadowcat.co.uk/ and the clone URL is:
828
829   git clone git://git.shadowcat.co.uk/catagits/Web-Simple.git
830
831 =head1 AUTHOR
832
833 Matt S. Trout (mst) <mst@shadowcat.co.uk>
834
835 =head1 CONTRIBUTORS
836
837 Devin Austin (dhoss) <dhoss@cpan.org>
838
839 Arthur Axel 'fREW' Schmidt <frioux@gmail.com>
840
841 gregor herrmann (gregoa) <gregoa@debian.org>
842
843 John Napiorkowski (jnap) <jjn1056@yahoo.com>
844
845 Josh McMichael <jmcmicha@linus222.gsc.wustl.edu>
846
847 Justin Hunter (arcanez) <justin.d.hunter@gmail.com>
848
849 Kjetil Kjernsmo <kjetil@kjernsmo.net>
850
851 markie <markie@nulletch64.dreamhost.com>
852
853 Christian Walde (Mithaldu) <walde.christian@googlemail.com>
854
855 nperez <nperez@cpan.org>
856
857 Robin Edwards <robin.ge@gmail.com>
858
859 Andrew Rodland (hobbs) <andrew@cleverdomain.org>
860
861 Robert Sedlacek (phaylon) <r.sedlacek@shadowcat.co.uk>
862
863 =head1 COPYRIGHT
864
865 Copyright (c) 2011 the Web::Simple L</AUTHOR> and L</CONTRIBUTORS>
866 as listed above.
867
868 =head1 LICENSE
869
870 This library is free software and may be distributed under the same terms
871 as perl itself.
872
873 =cut