Re: [BUG] line numbering off-by-one with Apache::DB and RegistryCooker
[prev]
[thread]
[next]
[Date index for 2005/03/17]
Dominique Quatravaux wrote:
>>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? :-)
It may confuse some users who may claim that mod_perl has hijacked and
rewritten their scripts :)
> 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).
As 2.0 is not released yet we can still do minor changes. I doubt anybody
has an overriden version of this particular API.
>>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.
I like your solution, Dominique, since it's even faster than the current
one as it avoids the:
${ $self->{CODE} } =~ s/^/$prepend/ if $prepend;
which forces a memory re-allocation to prepend a string (which can be
pretty big).
Unless someone disagrees we will go with this change.
> 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;
> }
>
> #########################################################################
>
>
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@xxxxxx.xxx http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
 |
(message missing)
|