diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2014-08-21 16:58:41 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2014-08-21 16:58:41 +0000 |
commit | 7dd93df1d843cbb36356dbea8071fab21cf04c30 (patch) | |
tree | 7433801a3aebd8fd9976ca2ecd94fed7b643c337 /t/memory.t | |
download | Module-Reader-tarball-master.tar.gz |
Module-Reader-0.002003HEADModule-Reader-0.002003master
Diffstat (limited to 't/memory.t')
-rw-r--r-- | t/memory.t | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/t/memory.t b/t/memory.t new file mode 100644 index 0000000..d33974e --- /dev/null +++ b/t/memory.t @@ -0,0 +1,45 @@ +use strict; +use warnings; + +use Test::More 0.88; +use Module::Reader qw(:all); + +my $mod_content = do { + open my $fh, '<', 't/lib/TestLib.pm'; + local $/; + <$fh>; +}; + +{ + local @INC = @INC; + unshift @INC, sub { + return unless $_[1] eq 'TestLib.pm'; + if ($] < 5.008) { + my $mod = $mod_content; + return sub { + return 0 unless length $mod; + $mod =~ s/^([^\n]*\n?)//; + $_ = $1; + return 1; + }; + } + open my $fh, '<', \$mod_content; + return $fh; + }; + is module_content('TestLib'), $mod_content, 'correctly load module from sub @INC hook'; + SKIP: { + skip 'found option doesn\'t work with @INC hooks in perl < 5.8', 2 + if $] < 5.008; + require TestLib; + unshift @INC, sub { + return unless $_[1] eq 'TestLib.pm'; + my $content = '1;'; + open my $fh, '<', \$content; + return $fh; + }; + is module_content('TestLib'), '1;', 'loads overridden module from sub @INC hook'; + is module_content('TestLib', { found => \%INC } ), $mod_content, 'found => \%INC loads mod as it was required'; + } +} + +done_testing; |