use strict;
use lib 't/lib';
+use IO::File;
use MBTest;
# parse various module $VERSION lines
'v1.2_3' => <<'---', # package NAME VERSION
package Simple v1.2_3;
---
+ '1.23' => <<'---', # trailing crud
+ package Simple;
+ our $VERSION;
+ $VERSION = '1.23-alpha';
+---
+ '1.23' => <<'---', # trailing crud
+ package Simple;
+ our $VERSION;
+ $VERSION = '1.23b';
+---
+ '1.234' => <<'---', # multi_underscore
+ package Simple;
+ our $VERSION;
+ $VERSION = '1.2_3_4';
+---
+ '0' => <<'---', # non-numeric
+ package Simple;
+ our $VERSION;
+ $VERSION = 'onetwothree';
+---
);
my %modules = reverse @modules;
-plan tests => 37 + 2 * keys( %modules );
+plan tests => 39 + 2 * keys( %modules );
require_ok('Module::Metadata');
+# class method C<find_module_by_name>
+my $module = Module::Metadata->find_module_by_name(
+ 'Module::Metadata' );
+ok( -e $module, 'find_module_by_name() succeeds' );
+
+#########################
+
my $tmp = MBTest->tmpdir;
use DistGen;
$dist->chdir_in;
-#########################
-
-# class method C<find_module_by_name>
-my $module = Module::Metadata->find_module_by_name(
- 'Module::Metadata' );
-ok( -e $module, 'find_module_by_name() succeeds' );
-
# fail on invalid module name
my $pm_info = Module::Metadata->new_from_module(
$pm_info = Module::Metadata->new_from_file( $file );
ok( defined( $pm_info ), 'new_from_file() succeeds' );
+# construct from filehandle
+my $handle = IO::File->new($file);
+$pm_info = Module::Metadata->new_from_handle( $handle, $file );
+ok( defined( $pm_info ), 'new_from_handle() succeeds' );
+$pm_info = Module::Metadata->new_from_handle( $handle );
+is( $pm_info, undef, "new_from_handle() without filename returns undef" );
+
+
# construct from module name, using custom include path
$pm_info = Module::Metadata->new_from_module(
$dist->name, inc => [ 'lib', @INC ] );