G'day everyone,

Despite all my chatter, I have some real changes for dh-make-perl.

The attached patches:

        * Avoids doing any work if we're being loaded as a library[1].

        * Adds some simple tests for extracting names and versions from
          Module::Install style makefiles[2].

        * Adds tests for the above.

        * Adds a trivial ./test command for running the (very small)
          test suite.

The patches are exported from git, so they retain meta info such as dates,
times, and commit messages.  If you'd prefer combined mega-patch, let me know.

These patches assume the big perltidy change has already been applied.  They
can also be extracted directly from the master branch of my git repo[3].

Cheerio,

        Paul

[1] Perl allows one to return() when code is being required, which makes
this a trivial one-line change, as opposed to having to wrap everything in a
main sub.

[2] Since Module::Install always writes a META.yml when run by the module
author, this code will hopefully never be needed.

[3] http://github.com/pfenwick/dh-make-perl/

-- 
Paul Fenwick <[EMAIL PROTECTED]> | http://perltraining.com.au/
Director of Training                   | Ph:  +61 3 9354 6001
Perl Training Australia                | Fax: +61 3 9354 2681
>From e430f43199bd99ec7cbb72e0a8ff3a7720b5ef31 Mon Sep 17 00:00:00 2001
From: Paul Fenwick <[EMAIL PROTECTED]>
Date: Tue, 25 Nov 2008 12:30:09 +1100
Subject: [PATCH] Simple patch to avoid doing work if we're being required and not run.

---
 dh-make-perl |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/dh-make-perl b/dh-make-perl
index 834d708..80a2f79 100755
--- a/dh-make-perl
+++ b/dh-make-perl
@@ -115,6 +115,11 @@ $startdir  = getcwd();
 $datadir   = '/usr/share/dh-make-perl';
 $homedir   = "$ENV{HOME}/.dh-make-perl";
 
+# If we're being required rather than called as a main command, then
+# return now without doing any work.  This facilitates easier testing.
+
+return 1 if $0 ne __FILE__;
+
 my ( $perlname, $maindir, $modulepm, $meta );
 my ($pkgname, $srcname,
 
@@ -1858,4 +1863,3 @@ Patches from:
 ... And others who, sadly, we have forgot to add :-/
 
 =cut
-
-- 
1.5.5.GIT

>From d3519ddc93da442b13ce164c2c05adfa6dc52d7f Mon Sep 17 00:00:00 2001
From: Paul Fenwick <[EMAIL PROTECTED]>
Date: Tue, 25 Nov 2008 12:39:23 +1100
Subject: [PATCH] Basic tests for extract_name_ver_from_autodie.

---
 t/extract_name_ver_from_makefile.t    |   18 ++++++++++++++++++
 t/makefiles/module-install-autodie.PL |   28 ++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 0 deletions(-)
 create mode 100644 t/extract_name_ver_from_makefile.t
 create mode 100644 t/makefiles/module-install-autodie.PL

diff --git a/t/extract_name_ver_from_makefile.t b/t/extract_name_ver_from_makefile.t
new file mode 100644
index 0000000..2b3b3e9
--- /dev/null
+++ b/t/extract_name_ver_from_makefile.t
@@ -0,0 +1,18 @@
+#!/usr/bin/perl -w
+use strict;
+use Test::More 'no_plan';
+use FindBin qw($Bin);
+
+require "$Bin/../dh-make-perl";        # Load our code for testing.
+
+my ($name, $ver);
+
+eval {
+  ($name, $ver) = 
+    extract_name_ver_from_makefile("$Bin/makefiles/module-install-autodie.PL");
+};
+
+is($@, "", "Calling extract_name_ver_from_makefile should not die on legit file");
+
+is($name, "autodie", "Module name should be autodie");
+is($ver,  "1.994",   "Module version should be 1.994");
diff --git a/t/makefiles/module-install-autodie.PL b/t/makefiles/module-install-autodie.PL
new file mode 100644
index 0000000..1e67904
--- /dev/null
+++ b/t/makefiles/module-install-autodie.PL
@@ -0,0 +1,28 @@
+#!/usr/bin/perl -w
+use strict;
+use inc::Module::Install;
+
+# This isn't the same as the real autodie makefile, which takes pains
+# to be friendlier to older versions of dh-make-perl.  However it is
+# indicative of what can be found a typical Module::Install file.
+
+name		'autodie';
+
+all_from	'lib/autodie.pm';
+
+version         1.994;
+test_requires	'Test::More';
+author         'Paul Fenwick <[EMAIL PROTECTED]>';
+
+requires	'perl' => '5.8.0';
+
+recommends	'IPC::System::Simple' => '0.12'; # For autodying system()
+
+resources      repository => 'http://github.com/pfenwick/autodie/tree/master';
+resources      bugtracker => 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=autodie';
+resources      license    => 'http://dev.perl.org/licenses/';
+resources	Blog       => 'http://pjf.id.au/blog/toc.html?tag=autodie';
+
+installdirs    'perl';    # This overwrites a core module!
+
+WriteAll;
-- 
1.5.5.GIT

>From a33182a2a090a114033f4d7f772cd445b61213f6 Mon Sep 17 00:00:00 2001
From: Paul Fenwick <[EMAIL PROTECTED]>
Date: Tue, 25 Nov 2008 12:39:38 +1100
Subject: [PATCH] Permissions fix

---
 0 files changed, 0 insertions(+), 0 deletions(-)
 mode change 100644 => 100755 t/extract_name_ver_from_makefile.t

diff --git a/t/extract_name_ver_from_makefile.t b/t/extract_name_ver_from_makefile.t
old mode 100644
new mode 100755
-- 
1.5.5.GIT

>From 63d6c83a91eac9dad924fcd6febe719767ae56ec Mon Sep 17 00:00:00 2001
From: Paul Fenwick <[EMAIL PROTECTED]>
Date: Tue, 25 Nov 2008 12:46:47 +1100
Subject: [PATCH] Updated reexp to extract version from basic Module::Install.

---
 dh-make-perl |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/dh-make-perl b/dh-make-perl
index b481df5..dc0dfdb 100755
--- a/dh-make-perl
+++ b/dh-make-perl
@@ -660,10 +660,19 @@ sub extract_name_ver_from_makefile {
         $vfrom = $4;
 
     }
-    elsif ( $file =~ /version\((\S+)\)/s ) {
+    elsif ( 
+        $file =~ m{
+            \bversion\b\s*                  # The word version
+            \(?\s*                          # Optional open-parens
+            (['"]?)                         # Optional quotes
+            ([\d_.]+)                       # The actual version.
+            \1                              # Optional close-quotes
+            \s*\)?                          # Optional close-parens.
+        }sx 
+    ) {
 
         # Module::Install
-        $ver = $1;
+        $ver = $2;
     }
 
     $dir = dirname($makefile) || './';
-- 
1.5.5.GIT

>From b80ba12236d45e80e4ce643049170364f47d92c0 Mon Sep 17 00:00:00 2001
From: Paul Fenwick <[EMAIL PROTECTED]>
Date: Mon, 24 Nov 2008 20:40:45 +1100
Subject: [PATCH] Trivial test script in lieu of having Makefile.PL to do things for us.

---
 test |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
 create mode 100755 test

diff --git a/test b/test
new file mode 100755
index 0000000..502487c
--- /dev/null
+++ b/test
@@ -0,0 +1,12 @@
+#!/usr/bin/perl -w
+use strict;
+use autodie;
+
+use FindBin qw($Bin);
+
+print "Running tests in $Bin/t\n";
+
+chdir($Bin);
+
+# Multi-arg exec avoids the shell.
+exec( qw(prove -Ilib t/) );
-- 
1.5.5.GIT

>From f075a6b39464b234bd591ea438e19b5dc58c8eeb Mon Sep 17 00:00:00 2001
From: Paul Fenwick <[EMAIL PROTECTED]>
Date: Tue, 25 Nov 2008 12:26:50 +1100
Subject: [PATCH] Updated extract_name_ver_from_makefile to handle M::I recommended syntax.
     * This patch only fixes extraction of names.
     * Version extraction tweaks not made in this commit.

---
 dh-make-perl |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/dh-make-perl b/dh-make-perl
index 834d708..9833458 100755
--- a/dh-make-perl
+++ b/dh-make-perl
@@ -607,13 +607,16 @@ sub extract_name_ver_from_makefile {
         $name = $4;
     }
     elsif (
-        $file =~ /name
-		 \s*
-		 \(
-		     ([\'\"]?)
-		         (\S+)
-		     \1
-		 \);/xs
+        $file =~ m{
+			name
+			 \s*
+			 \(?			# Optional open quote
+			     ([\'\"]?)
+				 (\S+)		# Quoted name
+			     \1
+			 \)?			# Optional close quote
+			 \s*;
+		 }xs
         )
     {
 
@@ -857,6 +860,7 @@ sub extract_depends {
     # fall back to Module::Depends.
 
     eval { %dep_hash = run_depends( 'Module::Depends::Intrusive', $dir ); };
+
     if ($@) {
         warn '=' x 70, "\n";
         warn "First attempt (Module::Depends::Intrusive) at a dependency\n"
-- 
1.5.5.GIT

Reply via email to