Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template code does not display in debugger running under mod_perl #21

Open
jayrifkinsv opened this issue Jul 10, 2023 · 1 comment
Open

Comments

@jayrifkinsv
Copy link

When using recent versions of Text::Template in a mod_perl environment and running the perl debugger via Apache::DB, if you break inside a template, the current line of code in the template does not display in the debugger, nor do other lines if you try debugger commands such as v, l, or w. Additionally, the line numbering in the debugger is off by 2.

Both of these issues seem to be due to the inclusion of the comment $fi_lcomment in $fi_progtext. The offset in the line numbering is due to the 2 carriage returns in $fi_progtext. I don't know how including the comment causes the template code not to display, but if we revert that line to an earlier version without the comment, the display in the debugger works fine. Therefore, I suggest the following patch, which detects whether the debugger is running and includes or excludes the comment accordingly:

--- latest - template code does not display in debugger under mod_perl
+++ suggested version - template code does display in debugger under mod_perl
@@ -304,8 +304,12 @@
     } elsif ($fi_type eq 'PROG') {
       no strict;
       my $fi_lcomment = "#line $fi_lineno $fi_filename";
-      my $fi_progtext =
-        "package $fi_eval_package; $fi_prepend;\n$fi_lcomment\n$fi_text;";
+      # This allows the perl debugger to show lines of template code and the correct line number
+      my $fi_progtext
+        = $^P ? "package $fi_eval_package; $fi_prepend; $fi_text;"
+              : "package $fi_eval_package; $fi_prepend;\n$fi_lcomment\n$fi_text;"
+              ;
+
       my $fi_res;
       my $fi_eval_err = '';
       if ($fi_safe) {

This fix works well for the debugger, which already displays the current line and the filename, so no functionality is lost.

Thanks,
Jay

@mschout
Copy link
Owner

mschout commented Aug 1, 2023

Good catch thanks! I'll try to get it into a release soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants