Skip Menu |

This queue is for tickets about the CGI-Application-Plugin-HTCompiled CPAN distribution.

Report information
The Basics
Id: 48086
Status: resolved
Priority: 0/
Queue: CGI-Application-Plugin-HTCompiled

People
Owner: MARKSTOS [...] cpan.org
Requestors: asb_ehb [...] yahoo.de
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.01
Fixed in: (no value)



Subject: set up html_tmpl_class
This package should set up html_tmpl_class(). Atm, using HTCompiled and calling $self->html_tmpl_class() returns HTML::Template, which is not correct.
Subject: Re: [rt.cpan.org #48086] set up html_tmpl_class
Date: Wed, 22 Jul 2009 12:36:09 -0400
To: bug-CGI-Application-Plugin-HTCompiled [...] rt.cpan.org
From: Mark Stosberg <mark [...] summersault.com>
Show quoted text
> This package should set up html_tmpl_class(). Atm, using HTCompiled and > calling $self->html_tmpl_class() returns HTML::Template, which is not > correct.
Because of the introduction of html_tmpl_class(), I think this plugin is now obsolete, except for this one line of logic that it contains: my %tmpl_params = (c=>$self); Are you interested in being a co-maintainer of the module and making a new release which avoids the old the technique of replacing load_tmpl(), and instead simply sets html_tmpl_class() through the "init" callback, and sets " c=> $self" through the load_tmpl() callback? I am not currently using the plugin myself, and don't have plans to use it soon. Mark
On Mi. 22. Jul. 2009, 12:36:39, mark@summersault.com wrote: Show quoted text
> > This package should set up html_tmpl_class(). Atm, using HTCompiled and > > calling $self->html_tmpl_class() returns HTML::Template, which is not > > correct.
> > Because of the introduction of html_tmpl_class(), I think this plugin is > now obsolete, except for this one line of logic that it contains: > > my %tmpl_params = (c=>$self); > > Are you interested in being a co-maintainer of the module and making a > new release which avoids the old the technique of replacing load_tmpl(), > and instead simply sets html_tmpl_class() through the "init" callback, > and sets " c=> $self" through the load_tmpl() callback? > > I am not currently using the plugin myself, and don't have plans to use > it soon. > > Mark
As already sent via CA mailing list, here is some new code. See attachement. Please feel free to copy & paste it as a new release, or to change anything you want. HTH, Alex
package CGI::Application::Plugin::HTCompiled; use CGI::Application 4.31; use 5.006; use strict; use warnings; =head1 NAME CGI::Application::Plugin::HTCompiled - Integrate with HTML::Template::Compiled =cut $CGI::Application::Plugin::HTCompiled::VERSION = '1.02'; use vars qw( $VERSION ); =head1 SYNOPSIS # In your CGI::Application-derived base class. . . use base "CGI::Application"; use CGI::Application::Plugin::HTCompiled; # Later, in a run mode far, far away. . . sub view { my $self = shift; my $username = $self->query->param("user"); my $user = My::Users->retrieve($username); my $tmpl_view = $self->load_tmpl( "view_user.tmpl" ); $tmpl_view->param( user => $user ); return $tmpl_view->output(); } =head1 DESCRIPTION Allows you to use L<HTML::Template::Compiled> as a seamless replacement for HTML::Template, as far as is possible with that module. =head1 DEFAULT PARAMETERS By default, the HTCompiled plugin will automatically add a parameter 'c' to the template that will return to your CGI::Application object $self. This allows you to access any methods in your CGI::Application module that you could normally call on $self from within your template. This allows for some powerful actions in your templates. For example, your templates will be able to access query parameters, or if you use the CGI::Application::Plugin::Session module, you can access session parameters. <a href="<tmpl_var c.query.self_url>">Reload this page</a> With this extra flexibility comes some responsibilty as well. It could lead down a dangerous path if you start making alterations to your object from within the template. For example you could call c.header_add to add new outgoing headers, but that is something that should be left in your code, not in your template. Try to limit yourself to pulling in information into your templates (like the session example above does). =head1 FUNCTIONS =head2 import() Will be called when your Module uses L<HTML::Template::Compiled>. Registers callbacks at the inti and the load_tmpl stages. =cut sub import { my $caller = scalar( caller ); $caller->add_callback( 'init' => \&_add_init ); $caller->add_callback( 'load_tmpl' => \&_pass_in_self ); goto &Exporter::import; } # /import =head2 _pass_in_self() Adds the parameter c each template that will be processed. See DEFAULT PARAMETERS for more information. =cut sub _pass_in_self { my ( $self, $one, $tmpl_params, $template_file ) = @_; warn("Template param 'c' will be overwritten.") if exists $tmpl_params->{c}; $tmpl_params->{c} = $self; } # /_pass_in_self =head2 _add_init() Set html_tmpl_class to L<HTML::Template::Compiled> at the init stage. That way, each time a template is loaded using load_tmpl, an instance of HTML::Template::Compiled will be created instead of the defualt HTML::Template. See the l<CGI::Appliaction> manpage for more information. =cut sub _add_init { my $self = shift; $self->html_tmpl_class('HTML::Template::Compiled'); } # /_add_init =head2 Extending load_tmpl() There are times when the basic C<load_tmpl()> functionality just isn't enough. The easiest way to do this is by replacing or extending the functionality of L<CGI::Application>'s C<load_tmpl()> method. This is still possible using the plugin. The following code snippet illustrates one possible way of achieving this: sub load_tmpl { my ($self, $tmpl_file, @extra_params) = @_; push @extra_params, "cache", "1"; return $self->SUPER::load_tmpl($tmpl_file, @extra_params); } =head1 AUTHOR Mark Stosberg C<< <mark@summersault.com> >> ...but largely modeled on HTDot plugin by Jason A. Crome. =head1 BUGS Please report any bugs or feature requests to C<bug-cgi-application-plugin-htcompiled@rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Application-Plugin-HTCompiled>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 ACKNOWLEDGEMENTS The usual crowd in #cgiapp on irc.perl.org =head1 SEE ALSO L<CGI::Application>, L<HTML::Template>, L<HTML::Template::Compiled>, =head1 COPYRIGHT & LICENSE Copyright 2005 Mark Stosberg, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # End of CGI::Application::Plugin::HTCompiled
Subject: Re: [rt.cpan.org #48086] set up html_tmpl_class
Date: Mon, 10 Aug 2009 11:47:28 -0400
To: bug-CGI-Application-Plugin-HTCompiled [...] rt.cpan.org
From: Mark Stosberg <mark [...] summersault.com>
Show quoted text
> As already sent via CA mailing list, here is some new code. See > attachement. Please feel free to copy & paste it as a new release, or to > change anything you want.
Looks reasonable to me. Do have a CPAN account yet, Alex? I could mark you as a co-maintainer, and you could upload the release yourself. OTOH, I don't expect the module to change much more over time, and I could upload it myself as well. If you are interested in contributing more to CPAN, this could be a good place to start. Mark -- . . . . . . . . . . . . . . . . . . . . . . . . . . . Mark Stosberg Principal Developer mark@summersault.com Summersault, LLC 765-939-9301 ext 202 database driven websites . . . . . http://www.summersault.com/ . . . . . . . .
Subject: Re: [rt.cpan.org #48086] set up html_tmpl_class
Date: Mon, 10 Aug 2009 20:07:48 -0400
To: bug-CGI-Application-Plugin-HTCompiled [...] rt.cpan.org
From: Mark Stosberg <mark [...] summersault.com>
Alex, I made your changes to the distribution, but the included tests are failing for at least two reasons: 1. The old multiple inheritence syntax seems to no longer work with it, as shown in the original documentation. Personally, I consider it a 'feature' that the MI hack is no longer required, but the question of backcompat still needs to be considered and addressed, even if the outcome is continue break backwards compatibility. 2. The tests for "c.foo" are failing. I haven't looked into way. I have published the integration work I have so far here: http://mark.stosberg.com/darcs_hive/CGI-Application-Plugin-HTCompiled/ It's a darcs repo, but you can also just browse and download files. Darcs is very user-friendly if you want to try it, and binaries are easily available. darcs get http://mark.stosberg.com/darcs_hive/CGI-Application-Plugin-HTCompiled/ cd CGI-Application-Application-Plugin-HTCompiled # hack... darcs record darcs send You are also welcome to take over this module and upload it under your own PAUSE ID. I no longer use it myself and trust you would do a fine job maintaining it. Mark
Hi! I thought on the problem with the backwards compatibility and I don't see a way to preserve it (maybe there is a way, but I'm simply not capable to do it). So I suggest to push the module to the next version, setting up a big text about the backwards compatibility problem. Code for this is attached. Regarding the module maintenance: If the module will never change again, then there would b no need to change its maintainer :) But I doubt that. I will try to read all this "getting a cpan author" stuff, but it could take a while. Meanwhile, you could do the update :) Best regards, Alex On Mo. 10. Aug. 2009, 20:08:08, mark@summersault.com wrote: Show quoted text
> > Alex, > > I made your changes to the distribution, but the included tests are > failing for at least two reasons: > > 1. The old multiple inheritence syntax seems to no longer work with > it, as > shown in the original documentation. Personally, I consider it a > 'feature' > that the MI hack is no longer required, but the question of backcompat > still > needs to be considered and addressed, even if the outcome is continue > break > backwards compatibility. > > 2. The tests for "c.foo" are failing. I haven't looked into way. I > have published the integration work I have so far here: > > http://mark.stosberg.com/darcs_hive/CGI-Application-Plugin-HTCompiled/ > > It's a darcs repo, but you can also just browse and download files. > > Darcs is very user-friendly if you want to try it, and binaries are > easily available. > > darcs get http://mark.stosberg.com/darcs_hive/CGI-Application-Plugin- > HTCompiled/ > cd CGI-Application-Application-Plugin-HTCompiled > # hack... > darcs record > darcs send > > You are also welcome to take over this module and upload it under your > own > PAUSE ID. I no longer use it myself and trust you would do a fine job > maintaining it. > > Mark
package CGI::Application::Plugin::HTCompiled; use CGI::Application 4.31; use 5.006; use strict; use warnings; =head1 NAME CGI::Application::Plugin::HTCompiled - Integrate with HTML::Template::Compiled =cut $CGI::Application::Plugin::HTCompiled::VERSION = '2.0'; use vars qw( $VERSION ); =head1 SYNOPSIS # In your CGI::Application-derived base class. . . use base "CGI::Application"; use CGI::Application::Plugin::HTCompiled; # Later, in a run mode far, far away. . . sub view { my $self = shift; my $username = $self->query->param("user"); my $user = My::Users->retrieve($username); my $tmpl_view = $self->load_tmpl( "view_user.tmpl" ); $tmpl_view->param( user => $user ); return $tmpl_view->output(); } =head1 DESCRIPTION Allows you to use L<HTML::Template::Compiled> as a seamless replacement for HTML::Template, as far as is possible with that module. =head1 DEFAULT PARAMETERS By default, the HTCompiled plugin will automatically add a parameter 'c' to the template that will return to your CGI::Application object $self. This allows you to access any methods in your CGI::Application module that you could normally call on $self from within your template. This allows for some powerful actions in your templates. For example, your templates will be able to access query parameters, or if you use the CGI::Application::Plugin::Session module, you can access session parameters. <a href="<tmpl_var c.query.self_url>">Reload this page</a> With this extra flexibility comes some responsibilty as well. It could lead down a dangerous path if you start making alterations to your object from within the template. For example you could call c.header_add to add new outgoing headers, but that is something that should be left in your code, not in your template. Try to limit yourself to pulling in information into your templates (like the session example above does). =head1 FUNCTIONS =head2 import() Will be called when your Module uses L<HTML::Template::Compiled>. Registers callbacks at the inti and the load_tmpl stages. =cut sub import { my $caller = scalar( caller ); $caller->add_callback( 'init' => \&_add_init ); $caller->add_callback( 'load_tmpl' => \&_pass_in_self ); goto &Exporter::import; } # /import =head2 _pass_in_self() Adds the parameter c each template that will be processed. See DEFAULT PARAMETERS for more information. =cut sub _pass_in_self { my ( $self, $one, $tmpl_params, $template_file ) = @_; warn("Template param 'c' will be overwritten.") if exists $tmpl_params->{c}; $tmpl_params->{c} = $self; } # /_pass_in_self =head2 _add_init() Set html_tmpl_class to L<HTML::Template::Compiled> at the init stage. That way, each time a template is loaded using load_tmpl, an instance of HTML::Template::Compiled will be created instead of the defualt HTML::Template. See the l<CGI::Appliaction> manpage for more information. =cut sub _add_init { my $self = shift; $self->html_tmpl_class('HTML::Template::Compiled'); } # /_add_init =head2 Extending load_tmpl() There are times when the basic C<load_tmpl()> functionality just isn't enough. The easiest way to do this is by replacing or extending the functionality of L<CGI::Application>'s C<load_tmpl()> method. This is still possible using the plugin. The following code snippet illustrates one possible way of achieving this: sub load_tmpl { my ($self, $tmpl_file, @extra_params) = @_; push @extra_params, "cache", "1"; return $self->SUPER::load_tmpl($tmpl_file, @extra_params); } =head1 BACKWARDS COMPATIBILITY As of version 2.0, CGI::Application::Plugin::HTCompiled breaks backwards compatibility. No interface has been changed, you can still use the load_tmpl() method as you did before. The difference is, that you don't use the plugin via multiple inheritance anymore, but simply use it. Old usage: # In your CGI::Application-derived base class. . . use base ("CGI::Application::Plugin::HTCompiled", "CGI::Application"); New usage: # In your CGI::Application-derived base class. . . use base "CGI::Application"; use CGI::Application::Plugin::HTCompiled; Multiple inheritance was the onyl way before CGI::Application v. 4.13 to use HTML::Template::Compiled with the standard load_tmpl() method. Now, there is no need to use language specific features (such as multiple inheritance) to implement plugin behavior, because we now have a proper way to do such plugins. This is the reason why we break backwards compatibility. If you depend on the old interface, use an older version of this module, such as 1.01. There is no difference in using this module in version 1.01 or 2.0. No interface has been changed. It's only the way to actually "use" the plugin, that changed. =head1 AUTHOR Mark Stosberg C<< <mark@summersault.com> >> ...but largely modeled on HTDot plugin by Jason A. Crome. =head1 BUGS Please report any bugs or feature requests to C<bug-cgi-application-plugin-htcompiled@rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Application-Plugin-HTCompiled>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 ACKNOWLEDGEMENTS The usual crowd in #cgiapp on irc.perl.org =head1 SEE ALSO L<CGI::Application>, L<HTML::Template>, L<HTML::Template::Compiled>, =head1 COPYRIGHT & LICENSE Copyright 2005 Mark Stosberg, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # End of CGI::Application::Plugin::HTCompiled
Thanks Alexander, I'll see what I can do. Becoming a CPAN author is a great step for professional development. It pushes you to think about quality, documentation and testing in new ways due to the public nature of the work. There's are plenty of maintainers who would like help as way to get you feet wet.
On Mi. 26. Aug. 2009, 10:26:04, MARKSTOS wrote: Show quoted text
> Thanks Alexander, I'll see what I can do. > > Becoming a CPAN author is a great step for professional development. It > pushes you to think about quality, documentation and testing in new ways > due to the public nature of the work. > > There's are plenty of maintainers who would like help as way to get you > feet wet.
Hi! I set up my pause account PLUS I found a way to achieve backward compatibility. How do I get the module maintainership? Do I register the namespace or do you set up permissions for it? Regards, Alex
Show quoted text
> I set up my pause account PLUS I found a way to achieve backward > compatibility. How do I get the module maintainership? Do I register
the Show quoted text
> namespace or do you set up permissions for it?
Alex, I've now made you an official co-maintainer, meaning that you can upload the next release, and that will be considered legitimate. I believe it should also mean that you get bug reports as they come in. I did this assuming that your PAUSE ID IS "ASB". Let me know if it's something else. You should also be able to manage the bug queue, such as marking bugs as "resolved". Give these changes 24 hours to propagate, and I think you are good to go. Good luck! Mark
Show quoted text
> Alex, > > I've now made you an official co-maintainer, meaning that you can
upload Show quoted text
> the next release, and that will be considered legitimate. I believe
it Show quoted text
> should also mean that you get bug reports as they come in. I did this > assuming that your PAUSE ID IS "ASB". Let me know if it's something > else. > > You should also be able to manage the bug queue, such as marking bugs
as Show quoted text
> "resolved". Give these changes 24 hours to propagate, and I think you > are good to go. > > Good luck! > > Mark
It's done now, although the release is marked as an ** UNAUTHORIZED RELEASE **. I'll clean up the POD a bit for the next release - provided it works. Best regards & many thanks for your help and encouragement, Alex
Subject: Re: [rt.cpan.org #48086] set up html_tmpl_class
Date: Wed, 14 Oct 2009 11:33:39 -0400
To: bug-CGI-Application-Plugin-HTCompiled [...] rt.cpan.org
From: Mark Stosberg <mark [...] summersault.com>
Show quoted text
> It's done now, although the release is marked as an ** UNAUTHORIZED > RELEASE **.
I see that's because of the permissions on "TestApp2", which is a namespace owned by JERLBAUM, but I am marked as a co-maintainer for. I can't give you permissions for that name space. You could rename the test module to something unique, or see if there is something else that can be done that would prevent it from being indexed. I'm sorry for the hassle. Mark
It's done. tmpl_class is set up and backwards compatibility achieved.