summaryrefslogtreecommitdiff
path: root/t/memory.t
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2014-08-21 16:58:41 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2014-08-21 16:58:41 +0000
commit7dd93df1d843cbb36356dbea8071fab21cf04c30 (patch)
tree7433801a3aebd8fd9976ca2ecd94fed7b643c337 /t/memory.t
downloadModule-Reader-tarball-master.tar.gz
Module-Reader-0.002003HEADModule-Reader-0.002003master
Diffstat (limited to 't/memory.t')
-rw-r--r--t/memory.t45
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;