[dh-make-perl] 01/03: use Text::Balanced's extract_quotelike for parsing quoted strings

Damyan Ivanov dmn at alioth.debian.org
Thu Aug 8 12:06:53 UTC 2013


This is an automated email from the git hooks/post-receive script.

dmn pushed a commit to branch master
in repository dh-make-perl.

commit 9220f236db661f61cf21c2bb09ee384e43a565d3
Author: Damyan Ivanov <dmn at debian.org>
Date:   Thu Aug 8 14:03:11 2013 +0200

    use Text::Balanced's extract_quotelike for parsing quoted strings
    
    Closes: #717025
---
 lib/DhMakePerl/Command/Packaging.pm |   43 +++++++++++++++++++++--------------
 t/dists/Strange-0.1/Makefile.PL     |    2 +-
 2 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/lib/DhMakePerl/Command/Packaging.pm b/lib/DhMakePerl/Command/Packaging.pm
index 9318163..12cff25 100644
--- a/lib/DhMakePerl/Command/Packaging.pm
+++ b/lib/DhMakePerl/Command/Packaging.pm
@@ -34,6 +34,7 @@ use File::Find qw(find);
 use File::Path ();
 use File::Spec::Functions qw(catfile catpath splitpath);
 use Parse::DebianChangelog;
+use Text::Balanced qw(extract_quotelike);
 use Text::Wrap qw(fill);
 use User::pwent;
 
@@ -404,11 +405,10 @@ sub extract_name_ver_from_build {
 		 module_name\1\s*
 		 (=>|,)
 		 \s*
-		 ([\'\"]?)
-		 (\S+)\3/xs
+		 (\S+)/xs
         )
     {
-        $name = $4;
+        $name = $self->unquote($2);
         $name =~ s/::/-/g;
 
         # just in case we need it later
@@ -514,51 +514,42 @@ sub extract_name_ver_from_makefile {
         $file = $fh->getline;
     }
 
-    # Replace q[quotes] by "quotes"
-    $file =~ s/q\[(.+)]/'$1'/g;
-
     # Get the name
     if ($file =~ /([\'\"]?)
 	    DISTNAME\1\s*
 	    (=>|,)
 	    \s*
-	    ([\'\"]?)
-	    (\S+)\3/xs
+	    (\S+)/xs
         )
     {
 
         # Regular MakeMaker
-        $name = $4;
+        $name = $self->unquote($3);
     }
     elsif (
         $file =~ /([\'\"]?)
 		 NAME\1\s*
 		 (=>|,)
 		 \s*
-		 ([\'\"]?)
-		 (\S+)\3/xs
+		 (\S+)\s*,?/xs
         )
     {
 
         # Regular MakeMaker
-        $name = $4;
+        $name = $self->unquote($3);
     }
     elsif (
         $file =~ m{
                         name
                          \s*
-                         \(?                    # Optional open paren
-                             ([\'\"]?)          # Optional open quote
                                  (\S+)          # Quoted name
-                             \1                 # Optional close quote
-                         \)?                    # Optional close paren
                          \s*;
                  }xs
         )
     {
 
         # Module::Install syntax
-        $name = $2;
+        $name = $self->unquote($1);
     }
     $name =~ s/,.*$//;
 
@@ -1605,6 +1596,24 @@ sub backup_file {
     }
 }
 
+=item unquote(I<string>)
+
+Runs its argument through L<Text::Balanced>'s C<extract_quotelike> method and
+returns the extracted content with quotes removed. Dies if C<extract_quotelike>
+can't find quoted string.
+
+=cut
+
+sub unquote {
+    my ( $self, $input ) = @_;
+
+    my $unquoted = (extract_quotelike($input))[5];
+
+    die "Unable to find quoted string in [$input]" unless defined $unquoted;
+
+    return $unquoted;
+}
+
 =back
 
 =cut
diff --git a/t/dists/Strange-0.1/Makefile.PL b/t/dists/Strange-0.1/Makefile.PL
index 5f9529c..e322ba9 100644
--- a/t/dists/Strange-0.1/Makefile.PL
+++ b/t/dists/Strange-0.1/Makefile.PL
@@ -2,6 +2,6 @@ use ExtUtils::MakeMaker;
 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
 # the contents of the Makefile that is written.
 WriteMakefile(
-    'NAME'	=> 'Strange',
+    'NAME'	=> q|Strange|,
     'VERSION_FROM' => 'Strange.pm', # finds $VERSION
 );

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/dh-make-perl.git



More information about the Pkg-perl-cvs-commits mailing list