[cgiapp] [patch] CAP::MessageStack + CAP::FormState
Cees Hek
ceeshek at gmail.com
Mon Oct 19 18:18:53 EDT 2009
On Tue, Oct 20, 2009 at 8:47 AM, Alex <capfan at gmx.de> wrote:
> Hi!
>
> I had a quick look at the source of CAP::TT. In contrast to my previous
> assumption, you use Template 2.0. So you should set tmpl_class to Template
> -
> if you want to.
>
>
Template === Template::Toolkit. I'm still thinking that it would be clearer
to set it to Template::Toolkit, and not just Template.
> I don't get exactly what your import method does, as I'm not very familiar
> with all that import and plugin stuff.
>
> Here it is (original), v. 1.04
> [code]
> sub import {
> my $pkg = shift;
> my $callpkg = caller;
> no strict 'refs';
> foreach my $sym (@EXPORT) {
> *{"${callpkg}::$sym"} = \&{$sym};
> }
> $callpkg->tt_config(@_) if @_;
> if ($callpkg->isa('CGI::Application')) {
> $callpkg->new_hook('tt_pre_process');
> $callpkg->new_hook('tt_post_process');
> } else {
> warn "Calling package is not a CGI::Application module so not
> installing tt_pre_process and tt_post_process hooks. If you are using
> \@ISA
> instead of 'use base', make sure it is in a BEGIN { } block, and make sure
> these statements appear before the plugin is loaded";
> }
>
> }
> [/code]
>
> E.g. I don't know why you are using that "no strict refs" and the loop
> afterwards. But then you do the configuration and declare the hooks for
> classes, that are based on CGI::Application.
>
The * in there means I am manipulating the symbol table directly, and that
spits out warnings. The "no strict 'refs';" just suppresses those
warnings. That code basically creates a bunch of new methods in the calling
class (ie the class that loaded the plugin).
> This is the part, where I think, you could set up the tmpl_class.
> [code]
> sub import {
> my $pkg = shift;
> my $callpkg = caller;
> no strict 'refs';
> foreach my $sym (@EXPORT) {
> *{"${callpkg}::$sym"} = \&{$sym};
> }
> $callpkg->tt_config(@_) if @_;
> $callpkg->html_tmpl_class('Template'); # << here
> if ($callpkg->isa('CGI::Application')) {
> $callpkg->new_hook('tt_pre_process');
> $callpkg->new_hook('tt_post_process');
> } else {
> warn "Calling package is not a CGI::Application module so not
> installing tt_pre_process and tt_post_process hooks. If you are using
> \@ISA
> instead of 'use base', make sure it is in a BEGIN { } block, and make sure
> these statements appear before the plugin is loaded";
> }
>
> }
> [/code]
>
That looks about right.
If this is the way we decide to go, then I can patch this pretty quickly. A
test case should be easy to whip up as well.
Cheers,
Cees
More information about the cgiapp
mailing list