[Catalyst-commits] r6693 - in trunk/Catalyst-View-MicroMason: .
lib/Catalyst/View t t/lib/TestApp/Controller
jrockway at dev.catalyst.perl.org
jrockway at dev.catalyst.perl.org
Sun Aug 19 02:23:07 GMT 2007
Author: jrockway
Date: 2007-08-19 02:23:07 +0100 (Sun, 19 Aug 2007)
New Revision: 6693
Modified:
trunk/Catalyst-View-MicroMason/
trunk/Catalyst-View-MicroMason/Build.PL
trunk/Catalyst-View-MicroMason/Changes
trunk/Catalyst-View-MicroMason/Makefile.PL
trunk/Catalyst-View-MicroMason/lib/Catalyst/View/MicroMason.pm
trunk/Catalyst-View-MicroMason/t/lib/TestApp/Controller/Root.pm
trunk/Catalyst-View-MicroMason/t/live.t
Log:
merge templated conversion micromason branch back into trunk
Property changes on: trunk/Catalyst-View-MicroMason
___________________________________________________________________
Name: svk:merge
+ 4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/templated_conversion/Catalyst-View-MicroMason:6692
Modified: trunk/Catalyst-View-MicroMason/Build.PL
===================================================================
--- trunk/Catalyst-View-MicroMason/Build.PL 2007-08-19 01:21:30 UTC (rev 6692)
+++ trunk/Catalyst-View-MicroMason/Build.PL 2007-08-19 01:23:07 UTC (rev 6693)
@@ -1,12 +1 @@
-use strict;
-use Module::Build;
-
-my $build = Module::Build->new(
- create_makefile_pl => 'passthrough',
- license => 'perl',
- module_name => 'Catalyst::View::MicroMason',
- requires => { Catalyst => 5.7, 'Text::MicroMason' => 1.99 },
- create_makefile_pl => 'passthrough',
- test_files => [ glob('t/*.t') ]
-);
-$build->create_build_script;
+link Makefile.PL
\ No newline at end of file
Property changes on: trunk/Catalyst-View-MicroMason/Build.PL
___________________________________________________________________
Name: svn:special
+ *
Modified: trunk/Catalyst-View-MicroMason/Changes
===================================================================
--- trunk/Catalyst-View-MicroMason/Changes 2007-08-19 01:21:30 UTC (rev 6692)
+++ trunk/Catalyst-View-MicroMason/Changes 2007-08-19 01:23:07 UTC (rev 6693)
@@ -1,5 +1,8 @@
Revision history for Perl extension Catalyst::View::MicroMason
-0.04 Sat Oct 7 07:16:55 CDT 2006
+0.05 Sat Aug 18 18:38:29 CDT 2007
+ - use View::Templated API
+
+0.04_01 Sat Oct 7 07:16:55 CDT 2006
- Works more like C::V::TT now, with process/render
- Accepts config properly (via a config file)
- Added a simple test
Modified: trunk/Catalyst-View-MicroMason/Makefile.PL
===================================================================
--- trunk/Catalyst-View-MicroMason/Makefile.PL 2007-08-19 01:21:30 UTC (rev 6692)
+++ trunk/Catalyst-View-MicroMason/Makefile.PL 2007-08-19 01:23:07 UTC (rev 6693)
@@ -1,31 +1,12 @@
-# Note: this file was auto-generated by Module::Build::Compat version 0.03
-
- unless (eval "use Module::Build::Compat 0.02; 1" ) {
- print "This module requires Module::Build to install itself.\n";
-
- require ExtUtils::MakeMaker;
- my $yn = ExtUtils::MakeMaker::prompt
- (' Install Module::Build now from CPAN?', 'y');
-
- unless ($yn =~ /^y/i) {
- die " *** Cannot install without Module::Build. Exiting ...\n";
- }
-
- require Cwd;
- require File::Spec;
- require CPAN;
-
- # Save this 'cause CPAN will chdir all over the place.
- my $cwd = Cwd::cwd();
- my $makefile = File::Spec->rel2abs($0);
-
- CPAN::Shell->install('Module::Build::Compat')
- or die " *** Cannot install without Module::Build. Exiting ...\n";
-
- chdir $cwd or die "Cannot chdir() back to $cwd: $!";
- }
- eval "use Module::Build::Compat 0.02; 1" or die $@;
- use lib '_build/lib';
- Module::Build::Compat->run_build_pl(args => \@ARGV);
- require Module::Build;
- Module::Build::Compat->write_makefile(build_class => 'Module::Build');
+use inc::Module::Install;
+
+name('Catalyst-View-MicroMason');
+all_from('lib/Catalyst/View/MicroMason.pm');
+
+requires 'Catalyst::View::Templated';
+requires 'Text::MicroMason';
+
+build_requires 'Catalyst::Runtime' => 5.7;
+build_requires 'Test::More';
+
+WriteAll();
Modified: trunk/Catalyst-View-MicroMason/lib/Catalyst/View/MicroMason.pm
===================================================================
--- trunk/Catalyst-View-MicroMason/lib/Catalyst/View/MicroMason.pm 2007-08-19 01:21:30 UTC (rev 6692)
+++ trunk/Catalyst-View-MicroMason/lib/Catalyst/View/MicroMason.pm 2007-08-19 01:23:07 UTC (rev 6693)
@@ -1,13 +1,14 @@
package Catalyst::View::MicroMason;
use strict;
-use base qw/Catalyst::View Class::Accessor/;
+use base qw/Catalyst::View::Templated Class::Accessor/;
use Text::MicroMason;
-use NEXT;
+use Class::C3;
-our $VERSION = '0.04';
+our $VERSION = '0.05';
-__PACKAGE__->mk_accessors(qw(template Mixins template_root));
+# template_root is the old way of saying INCLUDE_PATH. don't use it.
+__PACKAGE__->mk_accessors(qw(_template Mixins template_root));
=head1 NAME
@@ -15,56 +16,76 @@
=head1 SYNOPSIS
- # use the helper
+Use the helper:
+
script/create.pl view MicroMason MicroMason
+To create a simple View subclass:
+
# lib/MyApp/View/MicroMason.pm
package MyApp::View::MicroMason;
-
use base 'Catalyst::View::MicroMason';
+ 1;
- __PACKAGE__->config(
+And configure it in your app's config:
+
+ MyApp->config->{View::MicroMason} = {
# -Filters : to use |h and |u
# -ExecuteCache : to cache template output
# -CompileCache : to cache the templates
Mixins => [qw( -Filters -CompileCache )],
- template_root => '/path/to/comp_root'
- );
+ INCLUDE_PATH => '/path/to/comp_root'
+ };
+
+In an 'end' action:
- 1;
-
- # In an 'end' action
+ $c->view('MicroMason')->template('foo.mc');
$c->forward('MyApp::View::MicroMason');
+Or perhaps:
+
+ my $output = $c->view('MicroMason')->render('foo.mc');
+
=head1 DESCRIPTION
Want to use a MicroMason component in your views? No problem!
Catalyst::View::MicroMason comes to the rescue.
-=head1 CAVEATS
+=head1 METHODS
-You have to define C<template_root>. If C<template_root> is not directly
-defined within C<config>, the value comes from C<config->{root}>. If you don't
-define it at all, MicroMason is going to use the root of your system.
+=head2 new
-=head1 METHODS
+Create an instance; should be called from C<COMPONENT>, not by you.
=cut
sub new {
- my ($self, $c) = @_;
+ my ($self, $c, $args) = @_;
shift;
+
+ my $real_include = $args->{INCLUDE_PATH};
- $self = $self->NEXT::new(@_);
- my $root = $self->template_root || $c->config->{root};
+ $self = $self->next::method(@_);
+
+ my $root = $real_include ||
+ $self->template_root ||
+ $c->config->{root};
+ if (ref $root eq 'ARRAY' && @$root > 1) {
+ die "Catalyst::View::MicroMason only supports one entry in ".
+ "the INCLUDE_PATH or template_root.";
+ }
+
+ $root = $root->[0] if ref $root;
+ $self->template_root($root);
+
my @Mixins = @{ $self->Mixins || [] };
push @Mixins, qw(-TemplateDir -AllowGlobals);
- $self->template(Text::MicroMason->new(@Mixins,
+ $self->_template(Text::MicroMason->new(@Mixins,
template_root => $root,
%$self
)
- );
+ );
return $self;
}
@@ -72,71 +93,57 @@
=head2 process
Renders the component specified in $c->stash->{template} or by the
-value $c->action (if $c->stash->{template} is undefined).
+value $c->action (if $c->stash->{template} is undefined). See
+L<Catalyst::View::Templated> for all the details.
-MicroMason global variables C<$base>, C<$c> and c<$name> are
-automatically set to the base, context and name of the app,
-respectively.
+MicroMason global variables C<$base>, C<$c> (or whatever you pass in
+at config time as CATALYST_VAR) and c<$name> are automatically set to the base,
+context and name of the app, respectively.
An exception is thrown if processing fails, otherwise the output is stored
in C<< $c->response->body >>.
-=cut
+=head2 render([$template])
-sub process {
- my ( $self, $c ) = @_;
-
- $c->response->headers->content_type('text/html;charset=utf8')
- unless $c->response->content_type;
-
- $c->res->body( $self->render($c) );
- return 1;
-}
+Renders the given template and returns output.
-=head2 render($c, [$template])
+Throws an exception on error. If C<$template> is not defined, it is
+determined by calling C<< $self->template >>. See
+L<Catalyst::View::Templated> for details.
-Renders the given template and returns output. Throws an exception on
-error. If $template is not defined, the value of "template" from the
-stash is used instead.
-
=cut
-sub render {
- my ($self, $c, $component_path) = @_;
- $component_path ||= $c->stash->{template} || $c->action;
+sub _render {
+ my ($self, $template, $stash, $args) = @_;
+
+ my $c_name = '$'. $self->{CATALYST_VAR};
# Set the URL base, context and name of the app as global Mason vars
# $base, $c and $name
- $self->template->set_globals(
- '$base' => $c->req->base,
- '$c' => $c,
- '$name' => $c->config->{name}
- );
+ $self->_template->set_globals( '$base' => $self->context->req->base,
+ $c_name => $self->context,
+ '$name' => $self->context->config->{name},
+ );
- # render it
- my $output = eval {
- $self->template->execute(file => $component_path, %{$c->stash});
- };
+ delete $stash->{$self->{CATALYST_VAR}};
+ delete $stash->{base};
+ delete $stash->{name};
+
+ warn "MicroMason: using a stash key called 'file' sets the template"
+ if exists $stash->{file};
- # errors?
- if (my $error = $@ ) {
- chomp $error;
- $error =
- qq/Couldn't render component "$component_path" - error was "$error"/;
- $c->error($error);
- }
-
- return $output;
+ return $self->_template->execute(file => $template, %$stash);
}
=head1 SEE ALSO
-L<Catalyst>, L<Text::MicroMason>, L<Catalyst::View::Mason>
+L<Catalyst>, L<Catalyst::View::Templated>, L<Text::MicroMason>,
+L<Catalyst::View::Mason>
=head1 AUTHOR
-Jonas Alves C<jgda at cpan.org>
+Jonas Alves C<< <jgda at cpan.org> >>
=head1 MAINTAINER
Modified: trunk/Catalyst-View-MicroMason/t/lib/TestApp/Controller/Root.pm
===================================================================
--- trunk/Catalyst-View-MicroMason/t/lib/TestApp/Controller/Root.pm 2007-08-19 01:21:30 UTC (rev 6692)
+++ trunk/Catalyst-View-MicroMason/t/lib/TestApp/Controller/Root.pm 2007-08-19 01:23:07 UTC (rev 6693)
@@ -19,4 +19,11 @@
$c->forward('TestApp::View::MicroMason');
}
+sub bar : Global('bar') {
+ my ($self, $c, @args) = @_;
+ $c->view->template('foo');
+ $c->stash->{foo} = 'this is bar';
+ $c->detach('TestApp::View::MicroMason');
+}
+
1;
Modified: trunk/Catalyst-View-MicroMason/t/live.t
===================================================================
--- trunk/Catalyst-View-MicroMason/t/live.t 2007-08-19 01:21:30 UTC (rev 6692)
+++ trunk/Catalyst-View-MicroMason/t/live.t 2007-08-19 01:23:07 UTC (rev 6693)
@@ -5,7 +5,7 @@
use FindBin qw($Bin);
use lib "$Bin/lib";
use Catalyst::Test qw(TestApp);
-use Test::More tests => 4;
+use Test::More tests => 6;
my $test = request('this is handled by default I hope');
ok($test->content, 'content');
@@ -13,3 +13,6 @@
$test = request('/foo');
ok($test->content, 'foo content');
is($test->content, 'foo', 'got expected result');
+$test = request('/bar');
+ok($test->content, 'bar content');
+is($test->content, 'this is bar', 'got expected result');
More information about the Catalyst-commits
mailing list