Skip Menu |

This queue is for tickets about the Module-ExtractUse CPAN distribution.

Report information
The Basics
Id: 7012
Status: resolved
Priority: 0/
Queue: Module-ExtractUse

People
Owner: Nobody in particular
Requestors: schwern [...] pobox.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.10
Fixed in: (no value)



Subject: uses preceded by a comment can be ignored.
Sometimes uses following a comment are ignored. BEGIN { # Only use Apache::DBI on dev. if (-f '/var/run/httpd-dev01') { # Must be loaded before DBI. require Apache::DBI; Apache::DBI->import(); } } The problem is this # to keep parsing time short, split code in statements # (I know that this is not very exact, patches welcome!) my @statements=split(/;/,$podless); Comments don't end in a semicolon so you wind up with "# Must be loaded before DBI. require Apache::DBI" as a single statement. Simplest way to fix this, filter out comments. Patch and tests attached.
--- ExtractUse.pm 2004/07/19 21:19:10 1.1 +++ ExtractUse.pm 2004/07/19 21:21:03 @@ -38,6 +38,9 @@ $pod_parser->parse_file($module); } + # Strip obvious comments. + $podless =~ s/^\s*#.*$//mg; + # to keep parsing time short, split code in statements # (I know that this is not very exact, patches welcome!) my @statements=split(/;/,$podless); --- /dev/null 2004-07-02 11:16:41.000000000 -0400 +++ t/comment.t 2004-07-19 17:16:34.000000000 -0400 @@ -0,0 +1,52 @@ +#!/usr/bin/perl -w + +use strict; +use Test::More tests => 7; + +use Module::ExtractUse; + +my $p = Module::ExtractUse->new; + + +# The original problem code +is $p->extract_use(\(<<'CODE'))->string, 'Apache::DBI'; +BEGIN { + # Only use Apache::DBI on dev. + if (-f '/var/run/httpd-dev01') { + # Must be loaded before DBI. + require Apache::DBI; + Apache::DBI->import(); + } +} +CODE + + +is $p->extract_use(\(<<'CODE'))->string, 'Apache::DBI'; +# require Apache::DBI +require Apache::DBI +CODE + +is $p->extract_use(\(<<'CODE'))->string, ''; +# require Apache::DBI +# require Apache::DBI +CODE + +is $p->extract_use(\(<<'CODE'))->string, 'Apache::DBI'; +# foo +require Apache::DBI +CODE + +is $p->extract_use(\(<<'CODE'))->string, 'Apache::DBI'; +# use some Apache::DBI, yo +require Apache::DBI +CODE + +is $p->extract_use(\(<<'CODE'))->string, 'Apache::DBI'; +# require Apache::DBI +use Apache::DBI +CODE + +is $p->extract_use(\(<<'CODE'))->string, 'Apache::DBI'; +# yo, require Apache::DBI +require Apache::DBI +CODE --- MANIFEST 2004/07/19 21:22:16 1.1 +++ MANIFEST 2004/07/19 21:22:21 @@ -8,6 +8,7 @@ t/1.t t/2.t t/3.t +t/comment.t t/failing.t eg/cpan.pl