Date: | Tue, 12 Jul 2005 00:54:30 -0700 (PDT) |
From: | Salvador "Fandiño" <sfandino [...] yahoo.com> |
Subject: | [patch] CGI::Prototype support for alternative Template systems |
To: | bug-cgi-prototype [...] rt.cpan.org |
not a bug, but a patch for a new feature...
Show quoted text
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Received: from [212.166.209.1] by web52704.mail.yahoo.com via HTTP; Mon, 11 Jul 2005 09:15:20 PDT
Date: Mon, 11 Jul 2005 09:15:20 -0700 (PDT)
From: Salvador Fandiño <sfandino@yahoo.com>
Subject: [patch] CGI::Prototype support for alternative Template systems
To: merlyn@stonehenge.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="0-509565728-1121098520=:68590"
Content-Transfer-Encoding: 8bit
Content-Length: 1086
--0-509565728-1121098520=:68590
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Content-Id:
Content-Disposition: inline
Hi Randal,
(IMO) The attached patch makes using template systems other than the
template toolkit from CGI::Prototype easier. It adds support for a
new callback method, 'engine_package', that has to return the name of
the package implementing the template system, and then it gets
automatically loaded and used when required.
For instance, I have created an adapter package for Petal,
CGI::Prototype::Petal, and with this patch, all I have to do to use
it from CGI::Prototype is...
package My::App;
use base 'CGI::Prototype';
sub engine_package { 'CGI::Prototype::Petal' }
I hope you would like to include it on your package.
Cheers,
- Salvador.
Show quoted text
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--0-509565728-1121098520=:68590
Content-Type: text/x-patch; name="cgip-other-templates-0.patch"
Content-Description: 3352908775-cgip-other-templates-0.patch
Content-Disposition: inline; filename="cgip-other-templates-0.patch"
--- /root/.cpan/build/CGI-Prototype-0.9053/lib/CGI/Prototype.pm 2005-05-12 02:49:53.000000000 +0200
+++ /usr/local/share/perl/5.8.7/CGI/Prototype.pm 2005-07-11 16:05:06.000000000 +0200
@@ -354,9 +354,11 @@
$_mirror->addSlot
([qw(engine FIELD autoload)] => sub {
my $self = shift;
- require Template;
- Template->new($self->engine_config)
- or die "Creating tt: $Template::ERROR\n";
+ my $pkg = $self->engine_package;
+ eval "require $pkg; 1"
+ or die "Loading template package $pkg: $@";
+ $pkg->new($self->engine_config)
+ or die "Creating template: ".$pkg->error."\n";
});
=item engine_config
@@ -371,6 +373,17 @@
return {};
}
+=item engine_package
+
+returns the name of the package implementing the template
+engine. Defaults to C<Template>.
+
+=cut
+
+sub engine_package {
+ return 'Template';
+}
+
=item prototype_enter
Called when the prototype mechanism is entered, at the very beginning
--0-509565728-1121098520=:68590--