package Apache::MVC::View::TT;
use Lingua::EN::Inflect;
use Template;
use File::Spec;
use UNIVERSAL::moniker;

sub template_root { "/opt/houseshare/templates" } # For now

sub new { bless {}, shift } # Not worth having

sub process {
    my ($self, $r) = @_;
    my $root = $self->template_root;
    my $template = Template->new({ INCLUDE_PATH => [
        $root,
        File::Spec->catdir($root, $r->model_class->moniker),
        File::Spec->catdir($root, "custom"),
        File::Spec->catdir($root, "factory")
    ]});
    my %args = (
        request => $r,
        class   => $r->model_class,
        objects => $r->objects,
        # ...
    );

    # User-friendliness facility for custom template writers.
    if (@{$r->objects} > 1){
        $args{$r->model_class->plural_moniker} = $r->objects;
    } else {
        ($args{$r->model_class->moniker}) = @{$r->objects};
    }

    $template->process($r->template, \%args);
}
