[Catalyst-commits] r6295 -
branches/Catalyst-View-TT-nothingmuch_constructor_refactoring/lib/Catalyst/View
nothingmuch at dev.catalyst.perl.org
nothingmuch at dev.catalyst.perl.org
Wed Apr 18 13:38:22 GMT 2007
Author: nothingmuch
Date: 2007-04-18 13:38:22 +0100 (Wed, 18 Apr 2007)
New Revision: 6295
Modified:
branches/Catalyst-View-TT-nothingmuch_constructor_refactoring/lib/Catalyst/View/TT.pm
Log:
break the constructor into various methods responsible for setting up the config and constructing the template object
Modified: branches/Catalyst-View-TT-nothingmuch_constructor_refactoring/lib/Catalyst/View/TT.pm
===================================================================
--- branches/Catalyst-View-TT-nothingmuch_constructor_refactoring/lib/Catalyst/View/TT.pm 2007-04-18 12:22:44 UTC (rev 6294)
+++ branches/Catalyst-View-TT-nothingmuch_constructor_refactoring/lib/Catalyst/View/TT.pm 2007-04-18 12:38:22 UTC (rev 6295)
@@ -78,18 +78,42 @@
unless ( defined $dlim ) {
$dlim = ( $^O eq 'MSWin32' ) ? ':(?!\\/)' : ':';
}
- return split( /$dlim/, $paths );
+ return split( qr/$dlim/, $paths );
}
-sub new {
- my ( $class, $c, $arguments ) = @_;
- my $config = {
- EVAL_PERL => 0,
- TEMPLATE_EXTENSION => '',
- %{ $class->config },
- %{$arguments},
- };
- if ( ! (ref $config->{INCLUDE_PATH} eq 'ARRAY') ) {
+use constant default_config => (
+ EVAL_PERL => 0,
+ TEMPLATE_EXTENSION => '',
+);
+
+sub prepare_config {
+ my ( $class, $c, $arguments ) = @_;
+
+ my $config = $class->prepare_config_hash( $c, $arguments );
+
+ $class->prepare_config_paths($c, $config);
+
+ $class->prepare_config_misc($c, $config);
+
+ $class->prepare_config_providers($c, $config);
+
+ return $config;
+}
+
+sub prepare_config_hash {
+ my ( $class, $c, $arguments ) = @_;
+
+ return {
+ $class->default_config,
+ %{ $class->config },
+ %{$arguments},
+ };
+}
+
+sub prepare_config_paths {
+ my ( $class, $c, $config ) = @_;
+
+ unless ( ( ref($config->{INCLUDE_PATH}) || '' ) eq 'ARRAY' ) {
my $delim = $config->{DELIMITER};
my @include_path
= _coerce_paths( $config->{INCLUDE_PATH}, $delim );
@@ -100,7 +124,11 @@
}
$config->{INCLUDE_PATH} = \@include_path;
}
+}
+sub prepare_config_misc {
+ my ( $class, $c, $config ) = @_;
+
# if we're debugging and/or the TIMER option is set, then we install
# Template::Timer as a custom CONTEXT object, but only if we haven't
# already got a custom CONTEXT defined
@@ -119,6 +147,11 @@
if ( $c->debug && $config->{DUMP_CONFIG} ) {
$c->log->debug( "TT Config: ", Dump($config) );
}
+}
+
+sub prepare_config_providers {
+ my ( $class, $c, $config ) = @_;
+
if ( $config->{PROVIDERS} ) {
my @providers = ();
if ( ref($config->{PROVIDERS}) eq 'ARRAY') {
@@ -148,7 +181,13 @@
$config->{LOAD_TEMPLATES} = \@providers;
}
}
+}
+sub new {
+ my ( $class, $c, $arguments ) = @_;
+
+ my $config = $class->prepare_config( $c, $arguments );
+
my $self = $class->NEXT::new(
$c, { %$config },
);
@@ -167,18 +206,29 @@
Scalar::Util::weaken($copy);
$config->{INCLUDE_PATH} = [ sub { $copy->paths } ];
- $self->{template} =
- Template->new($config) || do {
- my $error = Template->error();
- $c->log->error($error);
- $c->error($error);
- return undef;
- };
+ $self->{template} = $self->construct_template_object($c, $config) || return undef;
return $self;
}
+sub construct_template_object {
+ my ( $self, $c, $config ) = @_;
+
+ my $class = $self->template_class($c, $config);
+
+ if ( my $t = $class->new($config) ) {
+ return $t;
+ } else {
+ my $error = $class->error();
+ $c->log->error($error);
+ $c->error($error);
+ return undef;
+ };
+}
+
+use constant template_class => 'Template';
+
sub process {
my ( $self, $c ) = @_;
More information about the Catalyst-commits
mailing list