> In which case you will end up with use warnings on the same line as the > shebang line, no? which will look strange in the debugger
Actually I find this pretty idiomatic, look: use warnings; #!/usr/bin/perl -w No? :-) Besides this line is seldom debugged anyway (at least in my experience) because the programmer typically sets a breakpoint with "$DB::single=1;" directly in his/her CGI. The other problem is that I cannot Do The Right Thing while keeping the current API intact. I propose the attached patch as an alternative, but it rips the ModPerl::RegistryCooker->rewrite_shebang() method apart (hopefully nobody depends on it yet, as it is undocumented). > I wonder if it'd be cleaner to use the '#line number filename' > directive. Actually this is what is currently done, but *before* ->rewrite_shebang() fiddles with the first line, which results in an off-by-one. Index: ModPerl-Registry/lib/ModPerl/RegistryCooker.pm =================================================================== --- ModPerl-Registry/lib/ModPerl/RegistryCooker.pm (revision 157426) +++ ModPerl-Registry/lib/ModPerl/RegistryCooker.pm (working copy) @@ -371,7 +371,7 @@ return $rc unless $rc == Apache::OK; # convert the shebang line opts into perl code - $self->rewrite_shebang; + my $shebang = $self->shebang_to_perl; # mod_cgi compat, should compile the code while in its dir, so # relative require/open will work. @@ -397,6 +397,7 @@ "sub handler {", "local \$0 = '$script_name';", $nph, + $shebang, $line, ${ $self->{CODE} }, "\n}"; # last line comment without newline? @@ -553,13 +554,13 @@ } ######################################################################### -# func: rewrite_shebang -# dflt: rewrite_shebang +# func: shebang_to_perl +# dflt: shebang_to_perl # desc: parse the shebang line and convert command line switches # (defined in %switches) into a perl code. # args: $self - registry blessed object -# rtrn: nothing -# efct: the CODE field gets adjusted +# rtrn: a Perl snippet to be put at the beginning of the CODE field +# by caller ######################################################################### my %switches = ( @@ -572,7 +573,7 @@ 'w' => sub { "use warnings;\n" }, ); -sub rewrite_shebang { +sub shebang_to_perl { my $self = shift; my($line) = ${ $self->{CODE} } =~ /^(.*)$/m; my @cmdline = split /\s+/, $line; @@ -588,7 +589,8 @@ $prepend .= $switches{$_}->(); } } - ${ $self->{CODE} } =~ s/^/$prepend/ if $prepend; + + return $prepend; } ######################################################################### -- Dominique QUATRAVAUX Ingénieur senior 01 44 42 00 08 IDEALX
pgptbbWrYBLsh.pgp
Description: PGP signature