Catalyst-View-TT

 view release on metacpan or  search on metacpan

lib/Catalyst/View/TT.pm  view on Meta::CPAN

package Catalyst::View::TT;

use strict;
use warnings;

use base qw/Catalyst::View/;
use Data::Dump 'dump';
use Template;
use Template::Timer;
use MRO::Compat;
use Scalar::Util qw/blessed weaken/;

our $VERSION = '0.46';
$VERSION =~ tr/_//d;

__PACKAGE__->mk_accessors('template');
__PACKAGE__->mk_accessors('expose_methods');
__PACKAGE__->mk_accessors('include_path');
__PACKAGE__->mk_accessors('content_type');

*paths = \&include_path;

lib/Catalyst/View/TT.pm  view on Meta::CPAN

    # 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 ]
    # as INCLUDE_PATH config item, which then gets ->paths() called to get list
    # of include paths to search for templates.

    # Use a weakened copy of self so we don't have loops preventing GC from working
    my $copy = $self;
    Scalar::Util::weaken($copy);
    $config->{INCLUDE_PATH} = [ sub { $copy->paths } ];

    if ( $config->{PROVIDERS} ) {
        my @providers = ();
        if ( ref($config->{PROVIDERS}) eq 'ARRAY') {
            foreach my $p (@{$config->{PROVIDERS}}) {
                my $pname = $p->{name};
                my $prov = 'Template::Provider';
                if($pname eq '_file_')
                {

lib/Catalyst/View/TT.pm  view on Meta::CPAN


    if ($self->expose_methods) {
        my $meta = $self->meta;
        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 {
                my @args = @_;
                my $ret;
                eval {
                    $ret = $self->$method_body($weak_ctx, @args);
                };
                if ($@) {
                    if (blessed($@)) {
                        die $@;
                    } else {

t/08cycle.t  view on Meta::CPAN

{
    my $view = new Catalyst::View::TT("TestApp", {});

    # Can't Test::Memory::Cycle test since it doesn't detect 
    #  [ sub { $copy->paths } ]
    # as a cycle, but the above does prevent it getting garbage collected.
    #
    # memory_cycle_ok($view, 'No cycles in View');

    $copy = $view;
    Scalar::Util::weaken($copy);
}

ok(!defined $copy, 'Copy went out of scope');



( run in 0.238 second using v1.01-cache-2.11-cpan-65fba6d93b7 )