version 0.36
[catagits/Catalyst-View-TT.git] / lib / Catalyst / View / TT.pm
index adacc1c..9dbb34c 100644 (file)
@@ -8,11 +8,13 @@ use Data::Dump 'dump';
 use Template;
 use Template::Timer;
 use MRO::Compat;
-use Scalar::Util qw/blessed/;
+use Scalar::Util qw/blessed weaken/;
 
-our $VERSION = '0.34';
+our $VERSION = '0.36';
+$VERSION = eval $VERSION;
 
 __PACKAGE__->mk_accessors('template');
+__PACKAGE__->mk_accessors('expose_methods');
 __PACKAGE__->mk_accessors('include_path');
 
 *paths = \&include_path;
@@ -128,6 +130,7 @@ sub new {
     # Set base include paths. Local'd in render if needed
     $self->include_path($config->{INCLUDE_PATH});
 
+    $self->expose_methods($config->{expose_methods});
     $self->config($config);
 
     # Creation of template outside of call to new so that we can pass [ $self ]
@@ -273,16 +276,18 @@ sub template_vars {
         name => $c->config->{name}
       );
 
-    if ($self->config->{expose_methods}) {
+    if ($self->expose_methods) {
         my $meta = $self->meta;
-        foreach my $method_name (@{$self->config->{expose_methods}}) {
-            my $method = $meta->get_method( $method_name );
+        foreach my $method_name (@{$self->expose_methods}) {
+            my $method = $meta->find_method_by_name( $method_name );
             unless ($method) {
                 Catalyst::Exception->throw( "$method_name not found in TT view" );
             }
             my $method_body = $method->body;
+            my $weak_ctx = $c;
+            weaken $weak_ctx;
             my $sub = sub {
-                $self->$method_body($c, @_);
+                $self->$method_body($weak_ctx, @_);
             };
             $vars{$method_name} = $sub;
         }
@@ -580,7 +585,7 @@ The list of methods in your View class which should be made available to the tem
 
 For example:
 
-  expose_methods => [qw/uri_for_static/],
+  expose_methods => [qw/uri_for_css/],
 
   ...
 
@@ -724,6 +729,8 @@ Jesse Sheidlower, C<jester@panix.com>
 
 Andy Wardley, C<abw@cpan.org>
 
+Luke Saunders, C<luke.saunders@gmail.com>
+
 =head1 COPYRIGHT
 
 This program is free software. You can redistribute it and/or modify it