Commit e070381c authored by Lucas Kanashiro's avatar Lucas Kanashiro

Imported Upstream version 0.341

parents abd0cb34 eef0ef73
......@@ -18,7 +18,7 @@ sub process_grammar_files {
open(my $fh,'<',$grammar) || die "cannot read $grammar: $!";
my @content = <$fh>;
close $fh;
splice(@content,1,0,'our $VERSION=0.33;'."\n");
splice(@content,1,0,'our $VERSION=0.341;'."\n");
open(my $out,">",$grammar) || die "cannot write $grammer: $!";
print $out @content;
close $out;
......@@ -32,13 +32,13 @@ EOF
my %module_build_args = (
'build_requires' => {
'Module::Build' => '0.3601',
'Module::Build' => '0.28',
'Test::Deep' => '0',
'Test::More' => '0',
'Test::NoWarnings' => '0'
},
'configure_requires' => {
'Module::Build' => '0.3601'
'Module::Build' => '0.28'
},
'requires' => {
'Carp' => '0',
......@@ -47,7 +47,6 @@ my %module_build_args = (
'perl' => '5.008',
'strict' => '0',
'vars' => '0',
'version' => '0',
'warnings' => '0'
},
'dist_abstract' => 'Find out what modules are used',
......@@ -56,7 +55,7 @@ my %module_build_args = (
'Kenichi Ishigaki <kishigaki@gmail.com>'
],
'dist_name' => 'Module-ExtractUse',
'dist_version' => '0.33',
'dist_version' => '0.341',
'license' => 'perl',
'module_name' => 'Module::ExtractUse',
'module_name' => 'Module::ExtractUse',
......
......@@ -2,6 +2,18 @@
# Changes for Module::ExtractUse
#-----------------------------------------------------------------
0.341 2016-01-30T22:18:20
- fixed 20_parse_self.t; version.pm is not used anymore (Kenichi Ishigaki)
0.340 2016-01-30T20:42:39
- load_first_existing_class() is now working (Anthony Brummett)
- Class::Load::load_class(), try_load_class() and load_optional_class() are working (Anthony Brummett)
- Detect uses of Module::Runtime (Anthony Brummett)
- include extractuse as provided by Jonathan Yu in example/ (Anthony Brummett)
- Linkify POD modules, mention Module::Extract::Use to resolve RT#45571. (Jeremy Mates)
0.33 2014-04-11T21:04:52+0200
- added base() handling to no (Thomas Klausner)
- support 'no MODULE' etc (for RT-94305) (Kenichi Ishigaki)
......
......@@ -22,7 +22,7 @@ This is free software, licensed under:
Version 1, February 1989
Copyright (C) 1989 Free Software Foundation, Inc.
51 Franklin St, Suite 500, Boston, MA 02110-1335 USA
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
......
# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.020.
Build.PL
Changes
INSTALL
......@@ -6,18 +7,9 @@ MANIFEST
META.json
META.yml
README
_build/auto_features
_build/build_params
_build/cleanup
_build/config_data
_build/features
_build/lib/MyModuleBuilder.pm
_build/magicnum
_build/notes
_build/prereqs
_build/runtime_params
dist.ini
example/cpan.pl
example/extractuse.pl
grammar
lib/Module/ExtractUse.pm
lib/Module/ExtractUse/Grammar.pm
......@@ -30,6 +22,8 @@ t/23_universal_require.t
t/24_version.t
t/25_utf8.t
t/26_pod_encoding.t
t/27_module_runtime.t
t/28_class_load.t
t/80_failing.t
xt/pod.t
xt/pod_coverage.t
......@@ -5,7 +5,7 @@
"Kenichi Ishigaki <kishigaki@gmail.com>"
],
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 4.300028, CPAN::Meta::Converter version 2.120921",
"generated_by" : "Dist::Zilla version 5.020, CPAN::Meta::Converter version 2.142060",
"license" : [
"perl_5"
],
......@@ -17,12 +17,12 @@
"prereqs" : {
"build" : {
"requires" : {
"Module::Build" : "0.3601"
"Module::Build" : "0.28"
}
},
"configure" : {
"requires" : {
"Module::Build" : "0.3601"
"Module::Build" : "0.28"
}
},
"runtime" : {
......@@ -33,7 +33,6 @@
"perl" : "5.008",
"strict" : "0",
"vars" : "0",
"version" : "0",
"warnings" : "0"
}
},
......@@ -50,9 +49,9 @@
"repository" : {
"type" : "git",
"url" : "git://github.com/domm/Module-ExtractUse.git",
"web" : "http://github.com/domm/Module-ExtractUse"
"web" : "https://github.com/domm/Module-ExtractUse"
}
},
"version" : "0.33"
"version" : "0.341"
}
......@@ -4,28 +4,27 @@ author:
- 'Thomas Klausner <domm@cpan.org>'
- 'Kenichi Ishigaki <kishigaki@gmail.com>'
build_requires:
Module::Build: 0.3601
Test::Deep: 0
Test::More: 0
Test::NoWarnings: 0
Module::Build: '0.28'
Test::Deep: '0'
Test::More: '0'
Test::NoWarnings: '0'
configure_requires:
Module::Build: 0.3601
Module::Build: '0.28'
dynamic_config: 0
generated_by: 'Dist::Zilla version 4.300028, CPAN::Meta::Converter version 2.120921'
generated_by: 'Dist::Zilla version 5.020, CPAN::Meta::Converter version 2.142060'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
version: '1.4'
name: Module-ExtractUse
requires:
Carp: 0
Parse::RecDescent: 1.967009
Pod::Strip: 0
perl: 5.008
strict: 0
vars: 0
version: 0
warnings: 0
Carp: '0'
Parse::RecDescent: '1.967009'
Pod::Strip: '0'
perl: '5.008'
strict: '0'
vars: '0'
warnings: '0'
resources:
repository: git://github.com/domm/Module-ExtractUse.git
version: 0.33
version: '0.341'
This archive contains the distribution Module-ExtractUse,
version 0.33:
version 0.341:
Find out what modules are used
......@@ -11,3 +11,5 @@ This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
This README file was generated by Dist::Zilla::Plugin::Readme v5.020.
do{ my $x = {};
$x; }
\ No newline at end of file
do{ my $x = [
{
'ARGV' => []
},
{},
{
'verbose' => undef,
'dist_suffix' => undef,
'PL_files' => undef,
'pollute' => undef,
'metafile2' => 'META.json',
'bindoc_dirs' => [
'blib/script'
],
'conflicts' => {},
'recommends' => {},
'scripts' => undef,
'pod_files' => undef,
'config_dir' => '_build',
'dist_version' => '##{$version##}',
'sign' => undef,
'recurse_into' => [],
'build_bat' => 0,
'extra_linker_flags' => [],
'build_class' => 'MyModuleBuilder',
'prereq_action_types' => [
'requires',
'build_requires',
'test_requires',
'conflicts',
'recommends'
],
'base_dir' => '/home/domm/perl/Module-ExtractUse',
'allow_mb_mismatch' => 0,
'xs_files' => undef,
'destdir' => undef,
'metafile' => 'META.yml',
'mb_version' => '0.4205',
'use_tap_harness' => 0,
'test_file_exts' => [
'.t'
],
'dist_name' => '##{$dist##}',
'has_config_data' => undef,
'install_base' => '/home/domm/.perlbrew/libs/perl-5.16.1@domm',
'module_name' => 'Module::ExtractUse',
'recursive_test_files' => 1,
'libdoc_dirs' => [
'blib/lib',
'blib/arch'
],
'perl' => '/home/domm/perl5/perlbrew/perls/perl-5.16.1/bin/perl',
'dist_author' => undef,
'bundle_inc' => [],
'use_rcfile' => 1,
'configure_requires' => {},
'pureperl_only' => 0,
'extra_manify_args' => undef,
'test_files' => undef,
'dist_abstract' => undef,
'create_readme' => undef,
'prefix_relpaths' => {},
'share_dir' => undef,
'debug' => undef,
'meta_merge' => {},
'get_options' => {},
'dist_version_from' => undef,
'_added_to_INC' => [
'/home/domm/perl/Module-ExtractUse/_build/lib',
'/home/domm/.perlbrew/libs/perl-5.16.1@domm/lib/perl5/x86_64-linux',
'/home/domm/.perlbrew/libs/perl-5.16.1@domm/lib/perl5'
],
'auto_configure_requires' => 1,
'create_license' => undef,
'debugger' => undef,
'html_css' => '',
'cpan_client' => 'cpan',
'mymetafile2' => 'MYMETA.json',
'bundle_inc_preload' => [],
'build_elements' => [
'PL',
'support',
'pm',
'xs',
'share_dir',
'pod',
'script',
'grammar'
],
'release_status' => 'stable',
'needs_compiler' => '',
'orig_dir' => '/home/domm/perl/Module-ExtractUse',
'include_dirs' => [],
'test_requires' => {},
'installdirs' => 'site',
'mymetafile' => 'MYMETA.yml',
'create_makefile_pl' => undef,
'magic_number' => undef,
'dynamic_config' => 1,
'tap_harness_args' => {},
'install_sets' => {},
'install_base_relpaths' => {},
'create_packlist' => 1,
'meta_add' => {},
'requires' => {},
'install_path' => {},
'pm_files' => undef,
'quiet' => undef,
'script_files' => undef,
'extra_compiler_flags' => [],
'build_script' => 'Build',
'original_prefix' => {},
'c_source' => undef,
'program_name' => undef,
'license' => 'unknown',
'autosplit' => undef,
'build_requires' => {},
'allow_pureperl' => 0,
'config' => undef,
'blib' => 'blib',
'prefix' => undef
}
];
$x; }
\ No newline at end of file
do{ my $x = {};
$x; }
\ No newline at end of file
do{ my $x = {};
$x; }
\ No newline at end of file
do{ my $x = {};
$x; }
\ No newline at end of file
package MyModuleBuilder;
use Module::Build;
@ISA = qw(Module::Build);
use File::Copy;
use File::Spec::Functions;
sub process_grammar_files {
my $self = shift;
my $grammar='Grammar.pm';
# precompile grammar
system("$^X -MParse::RecDescent - grammar Module::ExtractUse::Grammar");
# add $VERSION to grammer
open(my $fh,'<',$grammar) || die "cannot read $grammar: $!";
my @content = <$fh>;
close $fh;
splice(@content,1,0,'our $VERSION=##{$version##};'."\n");
open(my $out,">",$grammar) || die "cannot write $grammer: $!";
print $out @content;
close $out;
# move Grammer.pm to right place
my $target = catfile(qw(lib Module ExtractUse),$grammar);
move($grammar, $target) || die "Could not move precompiled $grammar to lib/Module/ExtractUse/Grammer.pm: $!";
}
1;
642008
\ No newline at end of file
do{ my $x = {};
$x; }
\ No newline at end of file
do{ my $x = {
'build_requires' => {},
'test_requires' => {},
'conflicts' => {},
'requires' => {},
'recommends' => {}
};
$x; }
\ No newline at end of file
do{ my $x = {
'install_base' => '/home/domm/.perlbrew/libs/perl-5.16.1@domm'
};
$x; }
\ No newline at end of file
#!/usr/bin/perl
# bin/extractuse
# Extract modules used by this distribution
#
# $Id: extractuse 6744 2009-04-29 14:32:07Z FREQUENCY@cpan.org $
#
# This package and its contents are released by the author into the
# Public Domain, to the full extent permissible by law. For additional
# information, please see the included `LICENSE' file.
use strict;
use warnings;
use Pod::Usage;
=head1 NAME
extractuse - determine what Perl modules are used in a given file
=head1 VERSION
Version 1.0 ($Id: extractuse 6744 2009-04-29 14:32:07Z FREQUENCY@cpan.org $)
=cut
use version; our $VERSION = qv('1.0');
=head1 SYNOPSIS
Usage: extractuse filename [...]
Given a single path referring to a file containing Perl code, this script will
determine the modules included statically. This means that files included
by C<use> and C<require> will be retrieved and listed.
=head1 DESCRIPTION
This script is safe because the Perl code is never executed, only parsed by
C<Module::Extract::Use> or C<Module::ExtractUse>, which are two different
implementations of this idea. This module will prefer C<Module::Extract::Use>
if it is installed, because it uses PPI to do its parsing, rather than its
own separate grammar.
However, one limitation of this script is that only statically included
modules can be found - that is, they have to be C<use>'d or C<require>'d
at runtime, and not inside an eval string, for example. Because eval strings
are completely dynamic, there is no way of determining which modules might
be loaded under different conditions.
=cut
my @files = @ARGV;
my $class = 'Module::Extract::Use';
# if no parameters are passed, give usage information
unless (@files) {
pod2usage(msg => 'Please supply at least one filename to analyze');
exit();
}
eval {
require Module::Extract::Use;
};
if ($@) {
$class = 'Module::ExtractUse';
eval {
require Module::ExtractUse;
};
if ($@) {
print {*STDERR} "No usable module found; exiting...\n";
exit 1;
}
}
eval {
require Module::CoreList;
};
my $corelist = not $@;
foreach my $file (@files) {
my $mlist;
unless (-e $file and -r _) {
printf {*STDERR} "Failed to open file '%s' for reading\n", $file;
next;
}
if ($class eq 'Module::ExtractUse') {
$mlist = Module::ExtractUse->new;
$mlist->extract_use($file);
dumplist($file, $mlist->array);
}
else {
$mlist = Module::Extract::Use->new;
dumplist($file, $mlist->get_modules($file));
}
}
sub dumplist {
my ($file, @mods) = @_;
printf "Modules required by %s:\n", $file;
my $core = 0;
my $extern = 0;
foreach my $name (@mods) {
print ' - ' . $name;
if ($corelist) {
my $ver = Module::CoreList->first_release($name);
if (defined $ver) {
printf ' (first released with Perl %s)', $ver;
$core++;
}
else {
$extern++;
}
}
print "\n";
}
printf "%d module(s) in core, %d external module(s)\n\n", $core, $extern;
}
=head1 AUTHOR
Jonathan Yu E<lt>frequency@cpan.orgE<gt>
=head1 SUPPORT
For support details, please look at C<perldoc Module::Extract::Use> or
C<perldoc Module::ExtractUse> and use the corresponding support methods.
=head1 LICENSE
Copyleft (C) 2009 by Jonathan Yu <frequency@cpan.org>. All rights reversed.
I, the copyright holder of this script, hereby release the entire contents
therein into the public domain. This applies worldwide, to the extent that
it is permissible by law.
In case this is not legally possible, I grant any entity the right to use
this work for any purpose, without any conditions, unless such conditions
are required by law. If not applicable, you may use this script under the
same terms as Perl itself.
=head1 SEE ALSO
L<Module::Extract::Use>,
L<Module::ExtractUse>,
L<Module::ScanDeps>,
=cut
......@@ -45,6 +45,53 @@ token_no: /\bno\s/ no_stuff /[;}]/
no_stuff: (base | version | module)
#----------------------------------------------------------------
# Functions provided by Module::Runtime
#----------------------------------------------------------------
module_runtime_require_module: ( 'Module::Runtime::require_module(' | /\brequire_module\(/ ) <perl_quotelike> ')'
{ $return = $item[2][2] }
module_runtime_use_fcn: ( 'use_module' | 'use_package_optimistically' )
module_runtime_version: ',' /\s*/ version
module_runtime_use: ( ( 'Module::Runtime::' module_runtime_use_fcn '(' ) | ( m/\b/ module_runtime_use_fcn '(' ) ) <perl_quotelike> module_runtime_version(?) ')'
{ $return = $item[2][2] }
token_module_runtime: module_runtime_require_module | module_runtime_use
#-----------------------------------------------------------------
# Functions provided by Class::Load
#-----------------------------------------------------------------
hash_pair: /\S+/ comma ( <perl_quotelike> | /[^\s,}]+/ )
comma_hash_pair: comma hash_pair
hashref: '{' hash_pair comma_hash_pair(s?) '}'
comma_hashref: comma hashref
class_load_functions: 'load_class' | 'try_load_class' | 'load_optional_class'
class_load: ( ( 'Class::Load::' class_load_functions ) | ( /\b/ class_load_functions ) ) '(' <perl_quotelike> comma_hashref(?) ')'
{ $return = $item[3][2] }
first_existing_arg: <perl_quotelike> comma_hashref(?)
{ $return = $item[1][2] }
comma_first_existing_arg: comma first_existing_arg
{ $return = $item{first_existing_arg} }
class_load_first_existing: ( 'Class::Load::load_first_existing_class' | /\bload_first_existing_class/ ) '(' first_existing_arg comma_first_existing_arg(s?) ')'
{ $return = $item{first_existing_arg};
$return .= " " . join(" ", @{$item{'comma_first_existing_arg(s?)'}}) if $item{'comma_first_existing_arg(s?)'};
1;
}
token_class_load: class_load | class_load_first_existing
#-----------------------------------------------------------------
# General Rules
#-----------------------------------------------------------------
......
......@@ -8,7 +8,7 @@ use Pod::Strip;
use Parse::RecDescent 1.967009;
use Module::ExtractUse::Grammar;
use Carp;
use version; our $VERSION=version->new('0.33');
our $VERSION = '0.341';
# ABSTRACT: Find out what modules are used
......@@ -116,7 +116,16 @@ sub extract_use {
# parse it! (using different entry point to save some more
# time)
my $type;
if ($statement=~/\buse/) {
if ($statement=~m/require_module|use_module|use_package_optimistically/) {
$statement=~s/^(.*?)\b(\S+(?:require_module|use_module|use_package_optimistically)\([^)]*\))/$2/;
next if $1 && $1 =~ /->\s*$/;
eval {
my $parser=Module::ExtractUse::Grammar->new();
$result=$parser->token_module_runtime($statement);
};
$type = $statement =~ m/require/ ? 'require' : 'use';
}
elsif ($statement=~/\buse/) {
$statement=~s/^(.*?)use\b/use/;
next if $1 && $1 =~ /->\s*$/;
eval {
......@@ -143,6 +152,15 @@ sub extract_use {
};
$type = 'no';
}
elsif ($statement=~m/load_class|try_load_class|load_first_existing_class|load_optional_class/) {
$statement=~s/^(.*?)\b(\S+(?:load_class|try_load_class|load_first_existing_class|load_optional_class)\([^)]*\))/$2/;
next if $1 && $1 =~ /->\s*$/;
eval {
my $parser=Module::ExtractUse::Grammar->new();
$result = $parser->token_class_load($statement.';');
};
$type = 'require';
}
next unless $result;
......@@ -323,13 +341,15 @@ __END__
=pod
=encoding UTF-8
=head1 NAME
Module::ExtractUse - Find out what modules are used
=head1 VERSION
version 0.33
version 0.341
=head1 SYNOPSIS
......@@ -367,7 +387,7 @@ version 0.33
=head1 DESCRIPTION
Module::ExtractUse is basically a Parse::RecDescent grammar to parse
Module::ExtractUse is basically a L<Parse::RecDescent> grammar to parse
Perl code. It tries very hard to find all modules (whether pragmas,
Core, or from CPAN) used by the parsed code.
......@@ -394,7 +414,7 @@ $code_to_parse. Or a reference to a SCALAR, in which case
Module::ExtractUse assumes the referenced scalar contains the source
code.
The code will be stripped from POD (using Pod::Strip) and split on ";"
The code will be stripped from POD (using L<Pod::Strip>) and split on ";"
(semicolon). Each statement (i.e. the stuff between two semicolons) is
checked by a simple regular expression.
......@@ -524,7 +544,21 @@ Nothing.
=head1 SEE ALSO
Parse::RecDescent, Module::ScanDeps, Module::Info, Module::CPANTS::Analyse
L<Parse::RecDescent>, L<Module::Extract::Use>, L<Module::ScanDeps>, L<Module::Info>, L<Module::CPANTS::Analyse>
=head1 CONTRIBUTORS
=over
=item * L<Anthony Brummett|https://github.com/brummett> implemented support for Module::Runtime and Class::Load while participating in the L<CPAN Pull Request Challenge|http://cpan-prc.org/>
=item * L<Jeremy Mates|https://github.com/thrig> fixed some documentation errors
=item * Jonathan Yu provided a nice script, C<example/extractuse.pl>
=back
If I forgot to mention your contribution, please send an email or open an issue / ticket.
=head1 AUTHORS
......
This diff is collapsed.
......@@ -30,13 +30,13 @@ use Module::ExtractUse;
my $p=Module::ExtractUse->new;
$p->extract_use('lib/Module/ExtractUse.pm');
cmp_deeply($p->arrayref,
bag(qw(strict version warnings Pod::Strip Parse::RecDescent Module::ExtractUse::Grammar Carp 5.008)),
bag(qw(strict warnings Pod::Strip Parse::RecDescent Module::ExtractUse::Grammar Carp 5.008)),
'modules used in this Module::ExtractUsed');
cmp_deeply([$p->arrayref_in_eval],
[],
'optional modules used in this Module::ExtractUsed');
cmp_deeply($p->arrayref_out_of_eval,
bag(qw(strict version warnings Pod::Strip Parse::RecDescent Module::ExtractUse::Grammar Carp 5.008)),
bag(qw(strict warnings Pod::Strip Parse::RecDescent Module::ExtractUse::Grammar Carp 5.008)),
'mandatory modules used in this Module::ExtractUsed');
my $used=$p->used;
......
#!/usr/bin/perl -w
use strict;
use Test::More;
use Test::Deep;
use Test::NoWarnings;
use Module::ExtractUse;
my @tests=
(
#1
['require_module("Some::Module");', [qw(Some::Module)], undef, [qw(Some::Module)]],
['Module::Runtime::require_module("Some::Module");', [qw(Some::Module)], undef, [qw(Some::Module)]],
['use_module("Some::Module");', [qw(Some::Module)], undef, [qw(Some::Module)]],
['Module::Runtime::use_module("Some::Module");', [qw(Some::Module)], undef, [qw(Some::Module)]],
['use_module("Some::Module", 1.23);', [qw(Some::Module)], undef, [qw(Some::Module)]],
['Module::Runtime::use_module("Some::Module", 1.23);', [qw(Some::Module)], undef, [qw(Some::Module)]],
['use_package_optimistically("Some::Module");', [qw(Some::Module)], undef, [qw(Some::Module)]],
['Module::Runtime::use_package_optimistically("Some::Module");', [qw(Some::Module)], undef, [qw(Some::Module)]],
['use_package_optimistically("Some::Module", 1.23);', [qw(Some::Module)], undef, [qw(Some::Module)]],
['Module::Runtime::use_package_optimistically("Some::Module", 1.23);', [qw(Some::Module)], undef, [qw(Some::Module)]],
['$foo->require_module("Some::Module");', undef, undef, undef ],
['$foo->use_module("Some::Module");', undef, undef, undef ],
['$foo->use_package_optimistically("Some::Module");', undef, undef, undef ],
['Other::Namespace::require_module("Some::Module");', undef, undef, undef ],
['use_module("Some::Module", "NotAVersion");', undef, undef, undef ],
['use_module("Some::Module", v1.23, "OtherArg");', undef, undef, undef ],
['use_module($Some::Variable);', undef, undef, undef ],
);
plan tests => (scalar @tests)*3+1;
foreach my $t (@tests) {
my ($code, @expected)=@$t;
my $p=Module::ExtractUse->new;
my $used = $p->extract_use(\$code);
my @used = (
$p->extract_use(\$code)->arrayref || undef,
$p->extract_use(\$code)->arrayref_in_eval || undef,
$p->extract_use(\$code)->arrayref_out_of_eval || undef,
);
for(my $i = 0; $i < @used; ++$i) {
if (ref($expected[$i]) eq 'ARRAY') {
cmp_bag($used[$i]||[],$expected[$i],$i.": ".$code);
} elsif (!defined $expected[$i]) {
is(undef,$used[$i],$i.": ".$code);