[Catalyst-commits] r13137 - Catalyst-View-TT/branches/moose/lib/Catalyst/View

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Wed Apr 7 03:07:56 GMT 2010


Author: t0m
Date: 2010-04-07 04:07:56 +0100 (Wed, 07 Apr 2010)
New Revision: 13137

Modified:
   Catalyst-View-TT/branches/moose/lib/Catalyst/View/TT.pm
Log:
Part convert, not working entirely yet

Modified: Catalyst-View-TT/branches/moose/lib/Catalyst/View/TT.pm
===================================================================
--- Catalyst-View-TT/branches/moose/lib/Catalyst/View/TT.pm	2010-04-07 03:06:59 UTC (rev 13136)
+++ Catalyst-View-TT/branches/moose/lib/Catalyst/View/TT.pm	2010-04-07 03:07:56 UTC (rev 13137)
@@ -1,21 +1,20 @@
 package Catalyst::View::TT;
-
-use strict;
-use warnings;
-
-use base qw/Catalyst::View/;
+use Moose;
 use Data::Dump 'dump';
 use Template;
 use Template::Timer;
 use MRO::Compat;
 use Scalar::Util qw/blessed/;
+use namespace::autoclean;
 
+extends 'Catalyst::View';
+
 our $VERSION = '0.33';
 
-__PACKAGE__->mk_accessors('template');
-__PACKAGE__->mk_accessors('include_path');
+has template => ( is => 'ro' );
+has include_path  => ( is => 'rw' );
 
-*paths = \&include_path;
+__PACKAGE__->meta->add_method('paths' => __PACKAGE__->meta->find_method_by_name('include_path'));
 
 =head1 NAME
 
@@ -25,7 +24,7 @@
 
 # use the helper to create your View
 
-    myapp_create.pl view TT TT
+    myapp_create.pl view HTML TT
 
 # configure in lib/MyApp.pm (Could be set from configfile instead)
 
@@ -33,7 +32,7 @@
         name         => 'MyApp',
         root         => MyApp->path_to('root'),
         default_view => 'TT',
-        'View::TT' => {
+        'View::HTML' => {
             # any TT configurations items go here
             INCLUDE_PATH => [
               MyApp->path_to( 'root', 'src' ),
@@ -86,14 +85,17 @@
     return split( /$dlim/, $paths );
 }
 
-sub new {
-    my ( $class, $c, $arguments ) = @_;
-    my $config = {
-        EVAL_PERL          => 0,
-        TEMPLATE_EXTENSION => '',
-        %{ $class->config },
-        %{$arguments},
-    };
+#$class->merge_config_hashes( $class->config, $args );
+
+around BUILDARGS => sub {
+    my ( $orig, $class, $c, $arguments ) = @_;
+    my $config = $class->merge_config_hashes(
+        {
+            EVAL_PERL          => 0,
+            TEMPLATE_EXTENSION => '',
+        },
+        $class->$orig($c, $arguments)
+    );
     if ( ! (ref $config->{INCLUDE_PATH} eq 'ARRAY') ) {
         my $delim = $config->{DELIMITER};
         my @include_path
@@ -125,24 +127,6 @@
         $c->log->debug( "TT Config: ", dump($config) );
     }
 
-    my $self = $class->next::method(
-        $c, { %$config },
-    );
-
-    # Set base include paths. Local'd in render if needed
-    $self->include_path($config->{INCLUDE_PATH});
-
-    $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 weakend copy of self so we dont 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') {
@@ -188,7 +172,7 @@
         }
     }
 
-    $self->{template} =
+    $config->{template} =
         Template->new($config) || do {
             my $error = Template->error();
             $c->log->error($error);
@@ -196,8 +180,24 @@
             return undef;
         };
 
+    return $config;
+};
 
-    return $self;
+sub BUILD {
+    my ($self, $config) = @_;
+    # Set base include paths. Local'd in render if needed
+    $self->include_path($config->{INCLUDE_PATH});
+
+    $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 weakend copy of self so we dont have loops preventing GC from working
+    my $copy = $self;
+    Scalar::Util::weaken($copy);
+    $config->{INCLUDE_PATH} = [ sub { $copy->paths } ];
 }
 
 sub process {




More information about the Catalyst-commits mailing list