[Catalyst-commits] r13852 - trunk/examples/CatalystAdvent/root/2010/pen

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Wed Dec 15 00:41:39 GMT 2010


Author: t0m
Date: 2010-12-15 00:41:39 +0000 (Wed, 15 Dec 2010)
New Revision: 13852

Modified:
   trunk/examples/CatalystAdvent/root/2010/pen/clousres_in_the_stash.pod
Log:
Note TT sugar

Modified: trunk/examples/CatalystAdvent/root/2010/pen/clousres_in_the_stash.pod
===================================================================
--- trunk/examples/CatalystAdvent/root/2010/pen/clousres_in_the_stash.pod	2010-12-14 23:47:24 UTC (rev 13851)
+++ trunk/examples/CatalystAdvent/root/2010/pen/clousres_in_the_stash.pod	2010-12-15 00:41:39 UTC (rev 13852)
@@ -88,10 +88,29 @@
 Whilst this looks somewhat more baroqe than the previous version, it won't leak any
 memory, and is tremendously useful.
 
+=head2 Sugar
+
+The latest (0.36) version of L<Catalyst::View::TT> has some syntax sugar to make
+adding closures much easier. You don't get the flexibility of being able to change them
+during the request cycle, but for most cases that isn't needed.
+
+In your view configuration, you declare which methods on your view class will be exposed:
+
+    expose_methods => [qw/uri_for_css/],
+
+and you then implement the method (in your View class), without having to worry
+about circular references through the context object, E.g.
+
+    sub uri_for_css {
+        my ($self, $c, $filename) = @_;
+        # Additional complexity here - this is a trivial example!
+        return $c->uri_for('/static/css/' . $filename);
+    }
+
 =head2 Further thoughts and ideas.
 
-The great thing about a stashed closure is that you can have entirely different implementations
-of it for different parts of your site (without needing to add a method on your MyApp object with
+Other great things about a stashed closures is that you can have entirely different implementations
+of them for different parts of your site (without needing to add a method on your MyApp object with
 horrible conditional logic in it).
 
 If you're using Chained dispatch, then you can fill in a default closure at the base of your
@@ -101,7 +120,7 @@
 As the closures are code refs, it is in fact entirely possible to further customise them by wrapping
 them inside another code ref which does some further work.
 
-For example:
+For example (building in the C<ContextClosure> example):
 
     my $old = $c->stash->{uri_with_secure};
     $c->stash( uri_with_secure => sub { my $uri = $old->(@_); $uri->path('/sekrit' . $uri->path); return $uri });




More information about the Catalyst-commits mailing list