Author: dagolden
Date: Tue Oct 27 14:00:28 2009
New Revision: 13436

Modified:
   Module-Build/trunk/lib/Module/Build/ModuleInfo.pm
   Module-Build/trunk/t/moduleinfo.t

Log:
first-cut at 'package NAME VERSION' parsing

Modified: Module-Build/trunk/lib/Module/Build/ModuleInfo.pm
==============================================================================
--- Module-Build/trunk/lib/Module/Build/ModuleInfo.pm   (original)
+++ Module-Build/trunk/lib/Module/Build/ModuleInfo.pm   Tue Oct 27 14:00:28 2009
@@ -15,6 +15,7 @@
 use IO::File;
 use Module::Build::Version;
 
+my $V_NUM_REGEXP = qr{v?[0-9._]+};  # crudely, a v-string or decimal
 
 my $PKG_REGEXP  = qr{   # match a package declaration
   ^[\s\{;]*             # intro chars on a line
@@ -22,6 +23,8 @@
   \s+                   # whitespace
   ([\w:]+)              # a package name
   \s*                   # optional whitespace
+  ($V_NUM_REGEXP)?        # optional version number 
+  \s*                   # optional whitesapce
   ;                     # semicolon line terminator
 }x;
 
@@ -221,10 +224,10 @@
          $self->_parse_version_expression( $line );
 
       if ( $line =~ $PKG_REGEXP ) {
-       $pkg = $1;
-       push( @pkgs, $pkg ) unless grep( $pkg eq $_, @pkgs );
-       $vers{$pkg} = undef unless exists( $vers{$pkg} );
-       $need_vers = 1;
+        $pkg = $1;
+        push( @pkgs, $pkg ) unless grep( $pkg eq $_, @pkgs );
+        $vers{$pkg} = (defined $2 ? $2 : undef)  unless exists( $vers{$pkg} );
+        $need_vers = defined $2 ? 0 : 1;
 
       # VERSION defined with full package spec, i.e. $Module::VERSION
       } elsif ( $vers_fullname && $vers_pkg ) {

Modified: Module-Build/trunk/t/moduleinfo.t
==============================================================================
--- Module-Build/trunk/t/moduleinfo.t   (original)
+++ Module-Build/trunk/t/moduleinfo.t   Tue Oct 27 14:00:28 2009
@@ -4,7 +4,7 @@
 
 use strict;
 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
-use MBTest tests => 80;
+use MBTest tests => 82;
 
 blib_load('Module::Build::ModuleInfo');
 
@@ -174,13 +174,18 @@
   $Simple::VERSION = '1.230';
   $Simple::VERSION = eval $Simple::VERSION;
 ---
+  <<'---', # package NAME VERSION
+  package Simple 1.23;
+---
 );
 
 my( $i, $n ) = ( 1, scalar( @modules ) );
 foreach my $module ( @modules ) {
  SKIP: {
     skip( "No our() support until perl 5.6", 2 )
-       if $] < 5.006 && $module =~ /\bour\b/;
+        if $] < 5.006 && $module =~ /\bour\b/;
+    skip( "No package NAME VERSION support until perl 5.11.1", 2 )
+        if $] < 5.011001 && $module =~ /package\s+[\w\:\']+\s+v?[0-9._]+/;
 
     $dist->change_file( 'lib/Simple.pm', $module );
     $dist->regen;
@@ -190,9 +195,11 @@
     my $pm_info = Module::Build::ModuleInfo->new_from_file( $file );
 
     # Test::Builder will prematurely numify objects, so use this form
+    my $errs;
     ok( $pm_info->version eq '1.23',
-       "correct module version ($i of $n)" );
-    is( $warnings, '', 'no warnings from parsing' );
+        "correct module version ($i of $n)" ) or $errs++;
+    is( $warnings, '', 'no warnings from parsing' ) or $errs++;
+    diag "Module contents:\n$module" if $errs;
     $i++;
   }
 }
@@ -393,7 +400,7 @@
   is( $pm_info->name, 'Simple', 'found default package' );
   is( $pm_info->version, '0.01', 'version for default package' );
   my @packages = $pm_info->packages_inside;
-  is_deeply(\...@packages, ['Simple']);
+  is_deeply(\...@packages, ['Simple'], 'packages inside');
 }
 
 {
@@ -410,7 +417,7 @@
   is( $pm_info->name, 'Simple', 'found default package' );
   is( $pm_info->version, '0.60.128', 'version for default package' );
   my @packages = $pm_info->packages_inside;
-  is_deeply([sort @packages], ['Simple', 'Simple::Simon']);
+  is_deeply([sort @packages], ['Simple', 'Simple::Simon'], 'packages inside');
   is( $pm_info->version('Simple::Simon'), '0.61.129', 'version for embedded 
package' );
 }
 

Reply via email to