initial import of catalyst.
Marcus Ramberg [Mon, 28 Feb 2005 19:24:51 +0000 (19:24 +0000)]
Changes [new file with mode: 0644]
Makefile.PL [new file with mode: 0644]
README [new file with mode: 0644]
lib/Catalyst/Helper/View/TT.pm [new file with mode: 0644]
lib/Catalyst/View/TT.pm [new file with mode: 0644]
test.pl [new file with mode: 0644]

diff --git a/Changes b/Changes
new file mode 100644 (file)
index 0000000..f3548d2
--- /dev/null
+++ b/Changes
@@ -0,0 +1,16 @@
+Revision history for Perl extension Catalyst::View::TT.
+
+0.05  Mon Feb 28 10:00:00 2005
+        - added helper
+
+0.04  Sun Feb 27 22:00:00 2005
+        - better debug messages (Marcus Ramberg)
+
+0.03  Thu Feb 17 22:00:00 2005
+        - don't try to render something without a template
+
+0.02  Tue Feb 01 02:00:00 2005
+        - using $c->req->match instead of $c->req->action
+
+0.01  Fri Jan 28 22:00:00 2005
+        - first release
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644 (file)
index 0000000..99f138e
--- /dev/null
@@ -0,0 +1,12 @@
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME      => 'Catalyst::View::TT',
+    AUTHOR    => 'Sebastian Riedel (sri@oook.de)',
+    PREREQ_PM => {
+        Catalyst        => '4.00',
+        Template        => 0,
+        Template::Timer => 0
+    },
+    VERSION_FROM => 'lib/Catalyst/View/TT.pm'
+);
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..9591668
--- /dev/null
+++ b/README
@@ -0,0 +1,40 @@
+NAME
+    Catalyst::View::TT - Template View Class
+
+SYNOPSIS
+        # use the helper
+        create view TT TT
+
+        # lib/MyApp/View/TT.pm
+        package MyApp::View::TT;
+
+        use base 'Catalyst::View::TT';
+
+        __PACKAGE__->config->{DEBUG} = 'all';
+
+        1;
+    
+        $c->forward('MyApp::View::TT');
+
+DESCRIPTION
+    This is the "Template" view class.
+
+  OVERLOADED METHODS
+   process
+    Renders the template specified in $c->stash->{template} or
+    $c->request->match to $c->response->output.
+
+   config
+    This allows your view subclass to pass additional settings to the TT
+    config hash.
+
+SEE ALSO
+    Catalyst.
+
+AUTHOR
+    Sebastian Riedel, "sri@cpan.org" Marcus Ramberg
+
+COPYRIGHT
+    This program is free software, you can redistribute it and/or modify it
+    under the same terms as Perl itself.
+
diff --git a/lib/Catalyst/Helper/View/TT.pm b/lib/Catalyst/Helper/View/TT.pm
new file mode 100644 (file)
index 0000000..6781e51
--- /dev/null
@@ -0,0 +1,78 @@
+package Catalyst::Helper::View::TT;
+
+use strict;
+use IO::File;
+
+=head1 NAME
+
+Catalyst::Helper::View::TT - Helper for TT Views
+
+=head1 SYNOPSIS
+
+    bin/create view TT TT
+
+=head1 DESCRIPTION
+
+Helper for TT Views.
+
+=head2 METHODS
+
+=head3 mk_compclass
+
+=cut
+
+sub mk_compclass {
+    my ( $self, $helper ) = @_;
+    my $file  = $helper->{file};
+    my $class = $helper->{class};
+    my $comp  = IO::File->new("> $file") or die qq/Couldn't open "$file", "$!"/;
+    print $comp <<"EOF";
+package $class;
+
+use strict;
+use base 'Catalyst::View::TT';
+
+=head1 NAME
+
+$class - TT View Component
+
+=head1 SYNOPSIS
+
+    Very simple to use
+
+=head1 DESCRIPTION
+
+Very nice component.
+
+=head1 AUTHOR
+
+Clever guy
+
+=head1 LICENSE
+
+This library is free software . You can redistribute it and/or modify it under
+the same terms as perl itself.
+
+=cut
+
+1;
+EOF
+}
+
+=head1 SEE ALSO
+
+L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
+L<Catalyst::Response>, L<Catalyst::Helper>
+
+=head1 AUTHOR
+
+Sebastian Riedel, C<sri@oook.de>
+
+=head1 LICENSE
+
+This library is free software . You can redistribute it and/or modify it under
+the same terms as perl itself.
+
+=cut
+
+1;
diff --git a/lib/Catalyst/View/TT.pm b/lib/Catalyst/View/TT.pm
new file mode 100644 (file)
index 0000000..934ab6a
--- /dev/null
@@ -0,0 +1,118 @@
+package Catalyst::View::TT;
+
+use strict;
+use base qw/Catalyst::Base Class::Data::Inheritable/;
+use Template;
+use Template::Timer;
+use NEXT;
+
+our $VERSION = '0.05';
+
+__PACKAGE__->mk_accessors('template');
+__PACKAGE__->mk_classdata('config');
+
+__PACKAGE__->config( { EVAL_PERL => 1 } );
+
+=head1 NAME
+
+Catalyst::View::TT - Template View Class
+
+=head1 SYNOPSIS
+
+    # use the helper
+    create view TT TT
+
+    # lib/MyApp/View/TT.pm
+    package MyApp::View::TT;
+
+    use base 'Catalyst::View::TT';
+
+    __PACKAGE__->config->{DEBUG} = 'all';
+
+    1;
+    
+    $c->forward('MyApp::View::TT');
+
+=head1 DESCRIPTION
+
+This is the C<Template> view class.
+
+=head2 OVERLOADED METHODS
+
+=cut
+
+sub new {
+    my $class  = shift;
+    my $c      = shift;
+    my $self   = $class->NEXT::new(@_);
+    my $root   = $c->config->{root};
+    my %config =
+      ( %{ $class->config }, INCLUDE_PATH => [ $root, "$root/base" ] );
+    $config{CONTEXT} = Template::Timer->new(%config) if $c->debug;
+    $self->template( Template->new( \%config ) );
+    return $self;
+}
+
+=head3 process
+
+Renders the template specified in $c->stash->{template} or $c->request->match
+to $c->response->output.
+
+=cut
+
+sub process {
+    my ( $self, $c ) = @_;
+    $c->res->headers->content_type('text/html;charset=utf8');
+    my $output;
+    my $name = $c->stash->{template} || $c->req->match;
+    unless ($name) {
+        $c->log->debug('No template specified for rendering') if $c->debug;
+        return 0;
+    }
+    $c->log->debug(qq/Rendering template "$name"/) if $c->debug;
+    unless (
+        $self->template->process(
+            $name,
+            {
+                %{ $c->stash },
+                base => $c->req->base,
+                c    => $c,
+                name => $c->config->{name}
+            },
+            \$output
+        )
+      )
+    {
+        my $error = $self->template->error;
+        $error = qq/Couldn't render template "$error"/;
+        $c->log->error($error);
+        $c->errors($error);
+    }
+    $c->res->output($output);
+    return 1;
+}
+
+=head3 config
+
+This allows your view subclass to pass additional settings to the
+TT config hash.
+
+=cut 
+
+=head1 SEE ALSO
+
+L<Catalyst>.
+
+=head1 AUTHOR
+
+Sebastian Riedel, C<sri@cpan.org>
+Marcus Ramberg
+
+=head1 COPYRIGHT
+
+This program is free software, you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
+
+1;
diff --git a/test.pl b/test.pl
new file mode 100644 (file)
index 0000000..ccc1771
--- /dev/null
+++ b/test.pl
@@ -0,0 +1,5 @@
+use strict;
+use Test::More tests => 2;
+
+BEGIN { use_ok('Catalyst::View::TT') }
+BEGIN { use_ok('Catalyst::Helper::View::TT') }