Commits

Fabrice Gabolde committed 8006525

Document sugar.

  • Participants
  • Parent commits b656a2a

Comments (0)

Files changed (1)

File lib/Floop/Confectionery.pm

 }
 
 1;
+__END__
+=pod
+
+=head1 NAME
+
+Floop::Confectionery -- Sugar for your Floop apps!
+
+=head1 SYNOPSIS
+
+  class Whatever extends Floop {
+      use Floop::Confectionery qw/sugar/;
+      method BUILD { ... }
+      method article_fetch ($app: $context) is GET ('/article/:slug') {
+          my $article_rs = $app->schema('default')->resultset('Article');
+          my $article = $article_rs->find({ slug => $context->route_parameters->get('slug') },
+                                          { key => 'slug_unique' });
+          $context->stash(article => $article);
+      }
+      method article_view ($app: $context) is GET ('', parent => 'article_fetch') {
+          my $article = $context->stash('article');
+          unless ($article->rendered) {
+              $article->do_render;
+          }
+          $context->render({}, { template => 'article/view.tt' });
+      }
+      method article_create ($app: $context) is GET ('/article/compose') { ... }
+      method article_post ($app: $context) is POST ('/article/compose') { ... }
+  }
+
+=head1 DESCRIPTION
+
+This is, so far, the only part of Floop that heavily uses the "m" in
+"mop", and it is fully optional.
+
+L<Floop::Confectionery> provides method traits so you can write a
+Floop app as its own class, declare methods in it, and have them
+handle the incoming requests, like you would in e.g. Catalyst
+controllers.
+
+=head1 EXPORTS
+
+None by default.
+
+=head2 HTTP
+
+  method fish is HTTP('GET', '/fish/:id') {
+      # define your handler body like you would in a Floop::Route
+  }
+  method gallop is HTTP('GET', '/gallop', parent => 'fish') {
+      # have you never heard of seahorses
+  }
+
+This trait can be applied only to methods.  It changes their metaclass
+to one that is able to generate routes.
+
+The following shortcuts are also available and exportable, as e.g.
+
+  method fish is GET('/fish/:id') { ... }
+
+=over 4
+
+=item GET
+
+=item POST
+
+=item PUT
+
+=item DELETE
+
+=item PATCH
+
+=item HEAD
+
+=item OPTIONS
+
+=back
+
+They are all (with the C<HTTP> trait) available through the "sugar"
+export tag, or individually.
+
+=head2 sugarcoat
+
+You should not call this method yourself.  It is called by the
+L<Floop> class' C<BUILD> method, to generate all the routes from the
+corresponding methods.
+
+=head1 SEE ALSO
+
+L<Floop>
+
+=head1 AUTHOR
+
+Fabrice Gabolde <fabrice.gabolde@gmail.com>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2014 Fabrice Gabolde
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.10.0 or,
+at your option, any later version of Perl 5 you may have available.
+
+=cut