Module-Reader-0.002001/000755 000765 000024 00000000000 12244177410 014644 5ustar00gknopstaff000000 000000 Module-Reader-0.002001/Changes000644 000765 000024 00000000554 12244177305 016146 0ustar00gknopstaff000000 000000 - fix module NAME in Makefile.PL
- minor doc corrections
- fix in-memory file test on perl 5.6
0.002000 Feb 11, 2013
- Improve documentation.
- Add 'found' option for always loading from specific files.
0.001002 Feb 2, 2013
- fix copyright attribution
0.001001 Feb 1, 2013
- fix version number format
0.001000 Feb 1, 2013
- initial version
Module-Reader-0.002001/lib/000755 000765 000024 00000000000 12244177407 015420 5ustar00gknopstaff000000 000000 Module-Reader-0.002001/Makefile.PL000644 000765 000024 00000002416 12241476163 016625 0ustar00gknopstaff000000 000000 { require 5.006 }
use strict;
use ExtUtils::MakeMaker 6.30;
my %WriteMakefileArgs = (
NAME => 'Module::Reader',
AUTHOR => 'Graham Knop ',
LICENSE => 'perl',
ABSTRACT_FROM => 'lib/Module/Reader.pm',
VERSION_FROM => 'lib/Module/Reader.pm',
PREREQ_PM => {
($] < 5.008 ? ('IO::String' => 0) : ()),
'Scalar::Util' => 0,
},
BUILD_REQUIRES => {
'Test::More' => 0.88,
},
CONFIGURE_REQUIRES => {
'ExtUtils::MakeMaker' => 6.30,
},
META_MERGE => {
resources => {
repository => 'git://github.com/haarg/Module-Reader.git',
homepage => 'http://github.com/haarg/Module-Reader',
},
requires => {
perl => 5.006,
},
}
);
unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) {
my $br = delete $WriteMakefileArgs{BUILD_REQUIRES};
my $pp = $WriteMakefileArgs{PREREQ_PM};
for my $mod ( keys %$br ) {
if ( exists $pp->{$mod} ) {
$pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod};
}
else {
$pp->{$mod} = $br->{$mod};
}
}
}
delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
unless eval { ExtUtils::MakeMaker->VERSION(6.52) };
WriteMakefile(%WriteMakefileArgs);
Module-Reader-0.002001/MANIFEST000644 000765 000024 00000000456 12244177410 016002 0ustar00gknopstaff000000 000000 Changes
lib/Module/Reader.pm
Makefile.PL
MANIFEST This list of files
MANIFEST.SKIP
t/00-load.t
t/lib/TestLib.pm
t/main.t
t/memory.t
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
Module-Reader-0.002001/MANIFEST.SKIP000644 000765 000024 00000001511 12241476163 016544 0ustar00gknopstaff000000 000000 # Avoid version control files.
\bRCS\b
\bCVS\b
\bSCCS\b
,v$
\B\.svn\b
\B\.git\b
\B\.gitignore\b
\b_darcs\b
\B\.cvsignore$
# Avoid VMS specific MakeMaker generated files
\bDescrip.MMS$
\bDESCRIP.MMS$
\bdescrip.mms$
# Avoid Makemaker generated and utility files.
\bMANIFEST\.bak
\bMakefile$
\bblib/
\bMakeMaker-\d
\bpm_to_blib\.ts$
\bpm_to_blib$
\bblibdirs\.ts$ # 6.18 through 6.25 generated this
# Avoid Module::Build generated and utility files.
\bBuild$
\b_build/
\bBuild.bat$
\bBuild.COM$
\bBUILD.COM$
\bbuild.com$
# Avoid temp and backup files.
~$
\.old$
\#$
\b\.#
\.bak$
\.tmp$
\.#
\.rej$
# Avoid OS-specific files/dirs
# Mac OSX metadata
\B\.DS_Store
# Mac OSX SMB mount metadata files
\B\._
# Avoid Devel::Cover and Devel::CoverX::Covered files.
\bcover_db\b
\bcovered\b
# Avoid MYMETA files
^MYMETA\.
\bModule-Reader-
Module-Reader-0.002001/META.json000644 000765 000024 00000002110 12244177410 016257 0ustar00gknopstaff000000 000000 {
"abstract" : "Read the source of a module like perl does",
"author" : [
"Graham Knop "
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 6.82, CPAN::Meta::Converter version 2.132830",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "Module-Reader",
"no_index" : {
"directory" : [
"t",
"inc"
]
},
"prereqs" : {
"build" : {
"requires" : {
"Test::More" : "0.88"
}
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "6.3"
}
},
"runtime" : {
"requires" : {
"Scalar::Util" : "0",
"perl" : "5.006"
}
}
},
"release_status" : "stable",
"resources" : {
"homepage" : "http://github.com/haarg/Module-Reader",
"repository" : {
"url" : "git://github.com/haarg/Module-Reader.git"
}
},
"version" : "0.002001"
}
Module-Reader-0.002001/META.yml000644 000765 000024 00000001170 12244177410 016114 0ustar00gknopstaff000000 000000 ---
abstract: 'Read the source of a module like perl does'
author:
- 'Graham Knop '
build_requires:
Test::More: 0.88
configure_requires:
ExtUtils::MakeMaker: 6.3
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 6.82, CPAN::Meta::Converter version 2.132830'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: Module-Reader
no_index:
directory:
- t
- inc
requires:
Scalar::Util: 0
perl: 5.006
resources:
homepage: http://github.com/haarg/Module-Reader
repository: git://github.com/haarg/Module-Reader.git
version: 0.002001
Module-Reader-0.002001/t/000755 000765 000024 00000000000 12244177407 015115 5ustar00gknopstaff000000 000000 Module-Reader-0.002001/t/00-load.t000644 000765 000024 00000000173 12241476163 016435 0ustar00gknopstaff000000 000000 use strict;
use Test::More tests => 1;
require_ok('Module::Reader')
|| BAIL_OUT("Stopping due to compile failure!");
Module-Reader-0.002001/t/lib/000755 000765 000024 00000000000 12244177407 015663 5ustar00gknopstaff000000 000000 Module-Reader-0.002001/t/main.t000644 000765 000024 00000000504 12241476163 016223 0ustar00gknopstaff000000 000000 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, 't/lib';
is module_content('TestLib'), $mod_content, 'correctly load module from disk';
}
done_testing;
Module-Reader-0.002001/t/memory.t000644 000765 000024 00000002321 12241476163 016606 0ustar00gknopstaff000000 000000 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;
Module-Reader-0.002001/t/lib/TestLib.pm000644 000765 000024 00000000025 12241476163 017562 0ustar00gknopstaff000000 000000 package TestLib;
1;
Module-Reader-0.002001/lib/Module/000755 000765 000024 00000000000 12244177407 016645 5ustar00gknopstaff000000 000000 Module-Reader-0.002001/lib/Module/Reader.pm000644 000765 000024 00000010132 12244177331 020376 0ustar00gknopstaff000000 000000 package Module::Reader;
BEGIN { require 5.006 }
use strict;
use warnings;
our $VERSION = '0.002001';
$VERSION = eval $VERSION;
use base 'Exporter';
our @EXPORT_OK = qw(module_content module_handle);
our %EXPORT_TAGS = (all => [@EXPORT_OK]);
use File::Spec;
use Scalar::Util qw(blessed reftype openhandle);
use Carp;
use constant _OPEN_STRING => $] >= 5.008;
BEGIN {
require IO::String
if !_OPEN_STRING;
}
sub module_content {
my $module = _get_module(@_);
if (ref $module) {
local $/;
return scalar <$module>;
}
else {
return $module;
}
}
sub module_handle {
my $module = _get_module(@_);
if (ref $module) {
return $module;
}
elsif (_OPEN_STRING) {
open my $fh, '<', \$module;
return $fh;
}
else {
return IO::String->new($module);
}
}
sub _get_module {
my ($package, @inc) = @_;
(my $module = "$package.pm") =~ s{::}{/}g;
my $opts = ref $_[-1] && ref $_[-1] eq 'HASH' && pop @inc || {};
if (!@inc) {
@inc = @INC;
}
if (my $found = $opts->{found}) {
if (my $full_module = $found->{$module}) {
if (ref $full_module) {
@inc = $full_module;
}
elsif (-f $full_module) {
open my $fh, '<', $full_module
or die "Couldn't open ${full_module} for ${module}: $!";
return $fh;
}
}
}
for my $inc (@inc) {
if (!ref $inc) {
my $full_module = File::Spec->catfile($inc, $module);
next unless -f $full_module;
open my $fh, '<', $full_module
or die "Couldn't open ${full_module} for ${module}: $!";
return $fh;
}
my @cb = ref $inc eq 'ARRAY' ? $inc->[0]->($inc, $module)
: blessed $inc ? $inc->INC($module)
: $inc->($inc, $module);
next
unless ref $cb[0];
my $fh;
if (reftype $cb[0] eq 'GLOB' && openhandle $cb[0]) {
$fh = shift @cb;
}
if (ref $cb[0] eq 'CODE') {
my $cb = shift @cb;
# require docs are wrong, perl sends 0 as the first param
my @params = (0, @cb ? $cb[0] : ());
my $module = '';
while (1) {
local $_ = $fh ? <$fh> : '';
$_ = ''
if !defined;
last if !$cb->(@params);
$module .= $_;
}
return $module;
}
elsif ($fh) {
return $fh;
}
}
croak "Can't find module $module";
}
1;
__END__
=head1 NAME
Module::Reader - Read the source of a module like perl does
=head1 SYNOPSIS
use Module::Reader qw(:all);
my $io = module_handle('My::Module');
my $content = module_content('My::Module');
my $io = module_handle('My::Module', @search_dirs);
my $io = module_handle('My::Module', @search_dirs, { found => \%INC });
=head1 DESCRIPTION
Reads the content of perl modules the same way perl does. This
includes reading modules available only by L<@INC hooks|perlfunc/require>, or filtered
through them.
=head1 EXPORTS
=head2 module_handle( $module_name, @search_dirs, \%options )
Returns an IO handle to the given module. Searches the directories
specified, or L<@INC|perlvar/@INC> if none are.
=head3 Options
=over 4
=item found
A reference to a hash like L<%INC|perlvar/%INC> with module file names (in the
style 'F') as keys and full file paths as values.
Modules listed in this will be used in preference to searching
through directories.
=back
=head2 module_content( $module_name, @search_dirs, \%options )
Returns the content of the given module. Accepts the same options as C.
=head1 AUTHOR
haarg - Graham Knop (cpan:HAARG)
=head2 CONTRIBUTORS
None yet.
=head1 COPYRIGHT
Copyright (c) 2013 the Module::Reader L and L
as listed above.
=head1 LICENSE
This library is free software and may be distributed under the same terms
as perl itself.
=cut