]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole/View/Base.pm
change template path to only look for custom, factory, etc on first/only path provided
[maypole.git] / lib / Maypole / View / Base.pm
index 0e9378fd465d15cbd60613304fb44f9456f7eba3..81e50446693305c9491e603fe0d46f20e7b11867 100644 (file)
@@ -10,12 +10,12 @@ sub new { bless {}, shift }    # By default, do nothing.
 
 sub paths {
     my ( $self, $r ) = @_;
-    warn "paths called with @_";
     my $root = $r->config->template_root || $r->get_template_root;
     if(ref($root) ne 'ARRAY') {
        $root = [ $root ];
     }
     my @output = ();
+    my $i = 0;
     foreach my $path (@$root) {
        push(@output,
             (
@@ -23,9 +23,10 @@ sub paths {
              && File::Spec->catdir( $path, $r->model_class->table )
              )
             );
-       push(@output, File::Spec->catdir( $path, "custom" ));
+       push(@output, File::Spec->catdir( $path, "custom" )) unless ($i);
        push(@output, $path);
-       push(@output, File::Spec->catdir( $path, "factory" ));
+       push(@output, File::Spec->catdir( $path, "factory" )) unless ($i);
+       $i = 1;
     }
 
     return grep( $_, @output);
@@ -49,14 +50,14 @@ sub vars {
         my $classmeta = $r->template_args->{classmetadata} ||= {};
         $classmeta->{name}              ||= $class;
         $classmeta->{table}             ||= $class->table;
-        $classmeta->{columns}           ||= [ $class->display_columns ];
-        $classmeta->{list_columns}      ||= [ $class->list_columns ];
-        $classmeta->{colnames}          ||= { $class->column_names };
+        $classmeta->{columns}           ||= [ $class->display_columns ] if ($class->can('display_columns'));
+        $classmeta->{list_columns}      ||= [ $class->list_columns ] if ($class->can('list_columns'));
+        $classmeta->{colnames}          ||= { $class->column_names } if ($class->can('column_names'));
         $classmeta->{related_accessors} ||= [ $class->related($r) ];
         $classmeta->{moniker}           ||= $class->moniker;
         $classmeta->{plural}            ||= $class->plural_moniker;
-        $classmeta->{cgi}               ||= { $class->to_cgi } if ($r->build_form_elements);
-       $classmeta->{stringify_column}  ||= $class->stringify_column;
+        $classmeta->{cgi}               ||= { $class->to_cgi } if ($r->build_form_elements && $class->can('to_cgi'));
+       $classmeta->{stringify_column}  ||= $class->stringify_column if ($class->can('stringify_column'));
 
         # User-friendliness facility for custom template writers.
         if ( @{ $r->objects || [] } > 1 ) {