bug with multiple "template" calls ?
Hello, In my dancer application, I'm using "template" to create documents that are not necessarily displayed as HTML (they are message bodies that will be sent with Dancer::Plugin::Email). I have one (or more) calls to "template" to create the email text. and the last "template" creates the HTML page. Conceptual example: ==== get "/hello" => sub { my $name = params->{name}; my $email = params->{email}; ## Email to be sent to the user, NOT rendered as HTML. my $msg = template("email_body", { name => $name }, { layout => undef } ) ; my $subject = template("email_subject", { name => $name }, { layout => undef } ) ; email { message => $msg, subject => $subject, to => $email } ; ## The welcome page, sent back to the user return template("welcome", { name => $name, email => $email } ) ; } ===== With Dancer version 1.3079_3, it worked perfectly. After upgrading to 1.3090, the result of the first template is always returned to the user - what changed ? any ideas/suggestions are welcomed. Thanks, -gordon
More details: Assaf Gordon wrote, On 12/15/2011 02:18 PM:
Hello,
I have one (or more) calls to "template" to create the email text. and the last "template" creates the HTML page.
[...]
With Dancer version 1.3079_3, it worked perfectly. After upgrading to 1.3090, the result of the first template is always returned to the user - what changed ? any ideas/suggestions are welcomed.
It seems now that a call to "template" immediately terminates the route's handling code - no code is executed after calling template (it's not just "return" because it exits multiple function calls"). Example: ============== sub foo { print STDERR "foo - start\n"; my $text = template("dummy", {} ); print STDERR "foo - done\n"; } sub bar { print STDERR "bar - start\n"; foo(); print STDERR "bar - done\n"; } get '/' => sub { print STDERR "before bar\n"; bar(); print STDERR "after bar\n"; return template("index.tt", {} ); }; ================== prints "bar-start" and "foo-start" but never "foo-done" and "bar-done" . Using "git bisect" (if I used it correctly), this is the first bad commit: ======== cfda458efb1e6458a25c57469d95cf25b2ec7f75 is the first bad commit commit cfda458efb1e6458a25c57469d95cf25b2ec7f75 Author: Damien Krotkine <dams@cpan.org> Date: Fri Oct 7 11:32:07 2011 +0200 pass, redirect, forward, halt, send_error, send_file, template now intterupt route workflows (no need to return) :040000 040000 8911d9022331792a8a49c00d8eb758bb6d424f7c a958def44e6f1e764029d9bd27403a1b5cda3248 M lib :040000 040000 47f431b5e310a8870ced9665964088c621a900d8 d708491c4379283a9286f05862ef45b84a2772a1 M t ======== (hehe, after reading the commit message, it's kind of obvious...) . In any case - is this behavior going to be permanent ? Meaning: "template" can only be used once, and must be the last statement ? I can see why it makes sense for "pass", "direct", "send_error" etc. (and probably for most use cases of "template") - but there are exception, like in my case... thanks, -gordon
I'm glad you sent these emails before I "upgraded," this will definitely break my application as well. On Thu, Dec 15, 2011 at 12:02 PM, Assaf Gordon <gordon@cshl.edu> wrote:
More details:
Assaf Gordon wrote, On 12/15/2011 02:18 PM:
Hello,
I have one (or more) calls to "template" to create the email text. and the last "template" creates the HTML page.
[...]
With Dancer version 1.3079_3, it worked perfectly. After upgrading to 1.3090, the result of the first template is always returned to the user - what changed ? any ideas/suggestions are welcomed.
It seems now that a call to "template" immediately terminates the route's handling code - no code is executed after calling template (it's not just "return" because it exits multiple function calls").
Example: ============== sub foo { print STDERR "foo - start\n"; my $text = template("dummy", {} ); print STDERR "foo - done\n"; }
sub bar { print STDERR "bar - start\n"; foo(); print STDERR "bar - done\n"; }
get '/' => sub { print STDERR "before bar\n"; bar(); print STDERR "after bar\n";
return template("index.tt", {} ); }; ==================
prints "bar-start" and "foo-start" but never "foo-done" and "bar-done" .
Using "git bisect" (if I used it correctly), this is the first bad commit: ======== cfda458efb1e6458a25c57469d95cf25b2ec7f75 is the first bad commit commit cfda458efb1e6458a25c57469d95cf25b2ec7f75 Author: Damien Krotkine <dams@cpan.org> Date: Fri Oct 7 11:32:07 2011 +0200
pass, redirect, forward, halt, send_error, send_file, template now intterupt route workflows (no need to return)
:040000 040000 8911d9022331792a8a49c00d8eb758bb6d424f7c a958def44e6f1e764029d9bd27403a1b5cda3248 M lib :040000 040000 47f431b5e310a8870ced9665964088c621a900d8 d708491c4379283a9286f05862ef45b84a2772a1 M t ========
(hehe, after reading the commit message, it's kind of obvious...) .
In any case - is this behavior going to be permanent ? Meaning: "template" can only be used once, and must be the last statement ? I can see why it makes sense for "pass", "direct", "send_error" etc. (and probably for most use cases of "template") - but there are exception, like in my case...
thanks, -gordon
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
On 12/15/2011 09:04 PM, Brian E. Lozier wrote:
I'm glad you sent these emails before I "upgraded," this will definitely break my application as well.
Yes, would happen to me as well ... producing HTML emails from templates is certainly not an uncommon usecase :-/ Regards Racke -- LinuXia Systems => http://www.linuxia.de/ Expert Interchange Consulting and System Administration ICDEVGROUP => http://www.icdevgroup.org/ Interchange Development Team
Hi Assaf, Well, the standard way of doing waht you wish to do is to use these line of codes instead of using template : my $template_engine = engine 'template'; my $html = $template_engine->apply_renderer(...); my $html_with_layout = $template_engine->apply_layout($html); I can see that the new release is causing you a problem, as it breaks something that used to work. I'll see with Sawyer and other core devs what we do. On top of my head what we can do is either : - just amend the documentation, and advertise a bit the potential issue - change back the behaviour of template, and re-release - perform the old behaviour if 'template' is called in a contexte that is anything but 'void', and issue a warning any other idea ? On 15 December 2011 20:18, Assaf Gordon <gordon@cshl.edu> wrote:
Hello,
In my dancer application, I'm using "template" to create documents that are not necessarily displayed as HTML (they are message bodies that will be sent with Dancer::Plugin::Email).
I have one (or more) calls to "template" to create the email text. and the last "template" creates the HTML page.
Conceptual example: ==== get "/hello" => sub { my $name = params->{name}; my $email = params->{email};
## Email to be sent to the user, NOT rendered as HTML. my $msg = template("email_body", { name => $name }, { layout => undef } ) ; my $subject = template("email_subject", { name => $name }, { layout => undef } ) ; email { message => $msg, subject => $subject, to => $email } ;
## The welcome page, sent back to the user return template("welcome", { name => $name, email => $email } ) ; } =====
With Dancer version 1.3079_3, it worked perfectly. After upgrading to 1.3090, the result of the first template is always returned to the user - what changed ? any ideas/suggestions are welcomed.
Thanks, -gordon _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
Hello, why was the old behavior changed? Don't you think the new way with 3 lines of code is too complex? ps: I actively use 'template' to generate config files and emails too. Mostly (but not only) in "use Dancer ':script'" mode. 16.12.2011 3:44, damien krotkine пишет:
Hi Assaf,
Well, the standard way of doing waht you wish to do is to use these line of codes instead of using template :
my $template_engine = engine 'template'; my $html = $template_engine->apply_renderer(...); my $html_with_layout = $template_engine->apply_layout($html);
I can see that the new release is causing you a problem, as it breaks something that used to work.
I'll see with Sawyer and other core devs what we do. On top of my head what we can do is either : - just amend the documentation, and advertise a bit the potential issue - change back the behaviour of template, and re-release - perform the old behaviour if 'template' is called in a contexte that is anything but 'void', and issue a warning
any other idea ?
On 15 December 2011 20:18, Assaf Gordon<gordon@cshl.edu> wrote:
Hello,
In my dancer application, I'm using "template" to create documents that are not necessarily displayed as HTML (they are message bodies that will be sent with Dancer::Plugin::Email).
I have one (or more) calls to "template" to create the email text. and the last "template" creates the HTML page.
Conceptual example: ==== get "/hello" => sub { my $name = params->{name}; my $email = params->{email};
## Email to be sent to the user, NOT rendered as HTML. my $msg = template("email_body", { name => $name }, { layout => undef } ) ; my $subject = template("email_subject", { name => $name }, { layout => undef } ) ; email { message => $msg, subject => $subject, to => $email } ;
## The welcome page, sent back to the user return template("welcome", { name => $name, email => $email } ) ; } =====
With Dancer version 1.3079_3, it worked perfectly. After upgrading to 1.3090, the result of the first template is always returned to the user - what changed ? any ideas/suggestions are welcomed.
Thanks, -gordon _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
-- Best Regards, Nick Knutov http://knutov.com ICQ: 272873706 Voice: +7-904-84-23-130
Heya, I'd also love to know why this change was done. I've got a number of apps that rely on this template behaviour for sending out html emails. Most respectfully and curiously, if the new behaviour is here to stay it would be a lot easier getting on with updating my code if I know why this change was made. Thank you. :) Sarah. On Fri, Dec 16, 2011 at 8:52 AM, Nick Knutov <mail@knutov.com> wrote:
Hello,
why was the old behavior changed?
Don't you think the new way with 3 lines of code is too complex?
ps: I actively use 'template' to generate config files and emails too. Mostly (but not only) in "use Dancer ':script'" mode.
16.12.2011 3:44, damien krotkine пишет:
Hi Assaf,
Well, the standard way of doing waht you wish to do is to use these line of codes instead of using template :
my $template_engine = engine 'template'; my $html = $template_engine->apply_**renderer(...); my $html_with_layout = $template_engine->apply_**layout($html);
I can see that the new release is causing you a problem, as it breaks something that used to work.
I'll see with Sawyer and other core devs what we do. On top of my head what we can do is either : - just amend the documentation, and advertise a bit the potential issue - change back the behaviour of template, and re-release - perform the old behaviour if 'template' is called in a contexte that is anything but 'void', and issue a warning
any other idea ?
On 15 December 2011 20:18, Assaf Gordon<gordon@cshl.edu> wrote:
Hello,
In my dancer application, I'm using "template" to create documents that are not necessarily displayed as HTML (they are message bodies that will be sent with Dancer::Plugin::Email).
I have one (or more) calls to "template" to create the email text. and the last "template" creates the HTML page.
Conceptual example: ==== get "/hello" => sub { my $name = params->{name}; my $email = params->{email};
## Email to be sent to the user, NOT rendered as HTML. my $msg = template("email_body", { name => $name }, { layout => undef } ) ; my $subject = template("email_subject", { name => $name }, { layout => undef } ) ; email { message => $msg, subject => $subject, to => $email } ;
## The welcome page, sent back to the user return template("welcome", { name => $name, email => $email } ) ; } =====
With Dancer version 1.3079_3, it worked perfectly. After upgrading to 1.3090, the result of the first template is always returned to the user - what changed ? any ideas/suggestions are welcomed.
Thanks, -gordon ______________________________**_________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/**cgi-bin/listinfo/dancer-users<http://www.backup-manager.org/cgi-bin/listinfo/dancer-users>
______________________________**_________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/**cgi-bin/listinfo/dancer-users<http://www.backup-manager.org/cgi-bin/listinfo/dancer-users>
-- Best Regards, Nick Knutov http://knutov.com ICQ: 272873706 Voice: +7-904-84-23-130
______________________________**_________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/**cgi-bin/listinfo/dancer-users<http://www.backup-manager.org/cgi-bin/listinfo/dancer-users>
Hey everyone. Thank you for raising this issue! We didn't notice how this change would affect users, and we apologize. Damien has reverted the commit and I'll bet putting out a new release today with the template() keyword being what it was - a way to return rendered output. This is because it is commonly used this way and apparently that's the DWIMish usage of it. Thanks again for providing such fast and helpful feedback, and thank you, dams, for responding to it and working it out so quickly! :) S. On Fri, Dec 16, 2011 at 1:13 AM, Sarah Fuller <sarah@averna.id.au> wrote:
Heya,
I'd also love to know why this change was done. I've got a number of apps that rely on this template behaviour for sending out html emails. Most respectfully and curiously, if the new behaviour is here to stay it would be a lot easier getting on with updating my code if I know why this change was made.
Thank you. :)
Sarah.
On Fri, Dec 16, 2011 at 8:52 AM, Nick Knutov <mail@knutov.com> wrote:
Hello,
why was the old behavior changed?
Don't you think the new way with 3 lines of code is too complex?
ps: I actively use 'template' to generate config files and emails too. Mostly (but not only) in "use Dancer ':script'" mode.
16.12.2011 3:44, damien krotkine пишет:
Hi Assaf,
Well, the standard way of doing waht you wish to do is to use these line of codes instead of using template :
my $template_engine = engine 'template'; my $html = $template_engine->apply_**renderer(...); my $html_with_layout = $template_engine->apply_**layout($html);
I can see that the new release is causing you a problem, as it breaks something that used to work.
I'll see with Sawyer and other core devs what we do. On top of my head what we can do is either : - just amend the documentation, and advertise a bit the potential issue - change back the behaviour of template, and re-release - perform the old behaviour if 'template' is called in a contexte that is anything but 'void', and issue a warning
any other idea ?
On 15 December 2011 20:18, Assaf Gordon<gordon@cshl.edu> wrote:
Hello,
In my dancer application, I'm using "template" to create documents that are not necessarily displayed as HTML (they are message bodies that will be sent with Dancer::Plugin::Email).
I have one (or more) calls to "template" to create the email text. and the last "template" creates the HTML page.
Conceptual example: ==== get "/hello" => sub { my $name = params->{name}; my $email = params->{email};
## Email to be sent to the user, NOT rendered as HTML. my $msg = template("email_body", { name => $name }, { layout => undef } ) ; my $subject = template("email_subject", { name => $name }, { layout => undef } ) ; email { message => $msg, subject => $subject, to => $email } ;
## The welcome page, sent back to the user return template("welcome", { name => $name, email => $email } ) ; } =====
With Dancer version 1.3079_3, it worked perfectly. After upgrading to 1.3090, the result of the first template is always returned to the user - what changed ? any ideas/suggestions are welcomed.
Thanks, -gordon ______________________________**_________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/**cgi-bin/listinfo/dancer-users<http://www.backup-manager.org/cgi-bin/listinfo/dancer-users>
______________________________**_________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/**cgi-bin/listinfo/dancer-users<http://www.backup-manager.org/cgi-bin/listinfo/dancer-users>
-- Best Regards, Nick Knutov http://knutov.com ICQ: 272873706 Voice: +7-904-84-23-130
______________________________**_________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/**cgi-bin/listinfo/dancer-users<http://www.backup-manager.org/cgi-bin/listinfo/dancer-users>
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
participants (7)
-
Assaf Gordon -
Brian E. Lozier -
damien krotkine -
Nick Knutov -
Sarah Fuller -
sawyer x -
Stefan Hornburg (Racke)