Module-Extract-Use-1.043/000755 000765 000024 00000000000 13044773753 015363 5ustar00brianstaff000000 000000 Module-Extract-Use-1.043/Changes000644 000765 000024 00000003076 13044773747 016667 0ustar00brianstaff000000 000000 Revision history for Perl module Module::Extract::Use 1.043 2017-02-03T03:24:02Z * Clarified license (GitHub issue #3 https://github.com/briandfoy/module-extract-use/issues/3) 1.042 2017-02-01T02:46:27Z * The -l and -j options work on the list of namespaces from all files together instead of the list per file. Otherwise strict and warnings always show up multiple times! 1.041 2017-02-01T01:58:04Z * Add JSON and simple list outputs for examples/extract_modules 1.04 - 2014-01-04 * Get rid of MYMETA * Update test data structures for latest behavior 1.03 - 2012-08-02 * Note the "pragma" field in the module details (RT 78728) 1.02 - 2011-11-01 * Adjusted no_index. No code changes. 1.01 - 2011-03-30 * Promote to a stable version * Some files moved around, and I updated the copyright statements for downstream ease. 0.18 - 2011-03-21 Implemented get_modules_with_details to extract the version and import lists for a use(). 0.16 - 2009-06-10 * Small distro cleanups and new META_MERGE hotness. No need to upgrade. 0.15 - 2009-05-31 * Debian wants the man pages, so I guess I'll make them after all 0.14 - 2009-05-20 * Adjust PPI bits to look for 'require' bits too * Add extract_modules example from Jonathan Yu 0.13 - 2008-10-29 * Only return unique elements, so remove the duplicates from the return list 0.12 - 2008-10-29 * No more carping. Check the value of $object->error after a call to see if anything bad happened. 0.11 - 2008-10-28 * Bump to a release version 0.10_01 - 2008-08-15 * First release of a module to pull out the package names Module-Extract-Use-1.043/corpus/000755 000765 000024 00000000000 13044773752 016675 5ustar00brianstaff000000 000000 Module-Extract-Use-1.043/examples/000755 000765 000024 00000000000 13044773752 017200 5ustar00brianstaff000000 000000 Module-Extract-Use-1.043/INSTALL.SKIP000644 000765 000024 00000000156 13044773747 017166 0ustar00brianstaff000000 000000 README\.pod README.* # things that might be in local directories after fooling # around with them \.DS_Store Module-Extract-Use-1.043/lib/000755 000765 000024 00000000000 13044773752 016130 5ustar00brianstaff000000 000000 Module-Extract-Use-1.043/LICENSE000644 000765 000024 00000017354 13044773747 016405 0ustar00brianstaff000000 000000 The Module::Extract::Use module is licensed under under the Artistic License 2.0. Artistic License 2.0 Copyright (c) 2000-2006, The Perl Foundation. http://www.perlfoundation.org/artistic_license_2_0 Preamble This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software. You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package. If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement. Definitions "Copyright Holder" means the individual(s) or organization(s) named in the copyright notice for the entire Package. "Contributor" means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder's procedures. "You" and "your" means any person who would like to copy, distribute, or modify the Package. "Package" means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version. "Distribute" means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization. "Distributor Fee" means any fee that you charge for Distributing this Package or providing support for this Package to another party. It does not mean licensing fees. "Standard Version" refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder. "Modified Version" means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder. "Original License" means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future. "Source" form means the source code, documentation source, and configuration files for the Package. "Compiled" form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form. Permission for Use and Modification Without Distribution (1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version. Permissions for Redistribution of the Standard Version (2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers. At your discretion, such verbatim copies may or may not include a Compiled form of the Package. (3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder. The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License. Distribution of Modified Versions of the Package as Source (4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following: (a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version. (b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version. (c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under (i) the Original License or (ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form of the Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed. Distribution of Compiled Forms of the Standard Version or Modified Versions without the Source (5) You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version. Such instructions must be valid at the time of your distribution. If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license. (6) You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version. Aggregating or Linking the Package (7) You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package. Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation. (8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package. Items That are Not Considered Part of a Modified Version (9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version. In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license. General Provisions (10) Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. (11) If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. (12) This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. (13) This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation Module-Extract-Use-1.043/Makefile.PL000644 000765 000024 00000005516 13044773747 017347 0ustar00brianstaff000000 000000 package Module::Extract::Use; use strict; use warnings; =encoding utf8 =head1 The build file for Module::Extract::Use This build file is a modulino; it works as both a build script and a module. To build the distribution, run this file normally: % perl Makefile.PL But, it's more interesting than that. You can load it with C and call C to get the data structure it passes to C: my $package = require '/path/to/Makefile.PL'; my $arguments = $package->arguments; Note that C-ing a file makes an entry in C<%INC> for exactly that name. If you try to C another file with the same name, even from a different path, C thinks it has already loaded the file. As such, I recommend you always require the full path to the file. The return value of the C is a package name (in this case, the name of the main module. Use that to call the C method. Even if this distribution needs a higher version of Perl, this bit only needs v5.8. You can play with the data structure with a primitive Perl. =cut use File::Spec::Functions qw(catfile); my $module = __PACKAGE__; ( my $dist = $module ) =~ s/::/-/g; my $github = 'https://github.com/briandfoy/module-extract-use'; my $main_file = catfile( 'lib', split /::/, "$module.pm" ); my %WriteMakefile = ( 'MIN_PERL_VERSION' => '5.010', 'NAME' => $module, 'ABSTRACT_FROM' => $main_file, 'VERSION_FROM' => 'lib/Module/Extract/Use.pm', 'LICENSE' => 'artistic2', 'AUTHOR' => 'brian d foy ', 'CONFIGURE_REQUIRES' => { 'ExtUtils::MakeMaker' => '6.64', 'File::Spec::Functions' => '0', }, 'BUILD_REQUIRES' => { }, 'TEST_REQUIRES' => { 'Test::More' => '0.94', 'Test::Output' => '0', }, 'PREREQ_PM' => { 'Getopt::Std' => '0', 'PPI' => '0', }, 'META_MERGE' => { 'meta-spec' => { version => 2 }, keywords => [ qw( ppi parsing static-analysis modules ) ], resources => { repository => { type => 'git', url => "$github.git", web => $github, }, bugtracker => { web => "$github/issues", }, homepage => $github, }, no_index => { dir => [ qw(corpus) ], directory => [ qw(corpus) ], }, }, clean => { FILES => "$dist-*" }, ); sub arguments { \%WriteMakefile } do_it() unless caller; sub do_it { require File::Spec; my $MM ='ExtUtils::MakeMaker'; my $MM_version = eval{ "$MM " . $WriteMakefile{'CONFIGURE_REQUIRES'}{'ExtUtils::MakeMaker'} } || "$MM 6.64"; eval "use $MM_version; 1" or die "Could not load $MM_version: $@"; eval "use Test::Manifest 1.21" if -e File::Spec->catfile( qw(t test_manifest) ); my $arguments = arguments(); my $minimum_perl = $arguments->{MIN_PERL_VERSION} || '5.008'; eval "require $minimum_perl;" or die $@; WriteMakefile( %$arguments ); } no warnings; __PACKAGE__; Module-Extract-Use-1.043/MANIFEST000644 000765 000024 00000001007 13044773753 016512 0ustar00brianstaff000000 000000 Changes corpus/PackageImports.pm corpus/PackageVersion.pm corpus/Repeated.pm corpus/RT79273.pm examples/extract_modules INSTALL.SKIP lib/Module/Extract/Use.pm LICENSE Makefile.PL MANIFEST This list of files MANIFEST.SKIP README.pod t/get_modules.t t/imports.t t/load.t t/pod.t t/pod_coverage.t t/rt/79273.t t/test_manifest t/versions.t xt/changes.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Module-Extract-Use-1.043/MANIFEST.SKIP000644 000765 000024 00000002011 13044773747 017256 0ustar00brianstaff000000 000000 #!start included /usr/local/perls/perl-5.18.1/lib/5.18.1/ExtUtils/MANIFEST.SKIP # 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\. #!end included /usr/local/perls/perl-5.18.1/lib/5.18.1/ExtUtils/MANIFEST.SKIP \.travis\.yml \.releaserc \.lwpcookies Module-.* Module-Extract-Use-1.043/META.json000664 000765 000024 00000003126 13044773753 017010 0ustar00brianstaff000000 000000 { "abstract" : "Pull out the modules a module explicitly uses", "author" : [ "brian d foy " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.1001, CPAN::Meta::Converter version 2.150005", "keywords" : [ "ppi", "parsing", "static-analysis", "modules" ], "license" : [ "artistic_2" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Module-Extract-Use", "no_index" : { "directory" : [ "corpus" ] }, "prereqs" : { "build" : { "requires" : {} }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.64", "File::Spec::Functions" : "0" } }, "runtime" : { "requires" : { "Getopt::Std" : "0", "PPI" : "0", "perl" : "5.010" } }, "test" : { "requires" : { "Test::More" : "0.94", "Test::Output" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/briandfoy/module-extract-use/issues" }, "homepage" : "https://github.com/briandfoy/module-extract-use", "repository" : { "type" : "git", "url" : "https://github.com/briandfoy/module-extract-use.git", "web" : "https://github.com/briandfoy/module-extract-use" } }, "version" : "1.043", "x_serialization_backend" : "JSON::PP version 2.27300" } Module-Extract-Use-1.043/META.yml000664 000765 000024 00000001631 13044773752 016636 0ustar00brianstaff000000 000000 --- abstract: 'Pull out the modules a module explicitly uses' author: - 'brian d foy ' build_requires: Test::More: '0.94' Test::Output: '0' configure_requires: ExtUtils::MakeMaker: '6.64' File::Spec::Functions: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.1001, CPAN::Meta::Converter version 2.150005' keywords: - ppi - parsing - static-analysis - modules license: artistic_2 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Module-Extract-Use no_index: directory: - corpus requires: Getopt::Std: '0' PPI: '0' perl: '5.010' resources: bugtracker: https://github.com/briandfoy/module-extract-use/issues homepage: https://github.com/briandfoy/module-extract-use repository: https://github.com/briandfoy/module-extract-use.git version: '1.043' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Module-Extract-Use-1.043/README.pod000644 000765 000024 00000006236 13044773747 017036 0ustar00brianstaff000000 000000 =pod =encoding utf8 =head1 The Module::Extract::Use module This is the I for the L Perl module. You're probably looking at this because you don't know where else to find what you're looking for. Read this once and you might never have to read one again for any Perl module. =head2 Documentation To read about L, look at the embedded documentation in the module itself. Inside the distribution, you can format it with L: % perldoc lib/Module/Extract/Use.pm If you have already installed the module, you can specify the module name instead of the file location: % perldoc Module::Extract::Use You can read the documentation and inspect the meta data on one of the CPAN web interfaces, such as L or L: =over 4 =item * L =item * L =back The standard module documentation has example uses in the SYNOPSIS section, but you can also look in the I directory (if it's there), or look at the test files in I. =head2 Installation You can install this module with a CPAN client, which will resolve and install the dependencies: % cpan Module::Extract::Use % cpanm Module::Extract::Use You can also install directly from the distribution directory, which will also install the dependencies: % cpan . % cpanm . You could install just this module manually: % perl Makefile.PL % make % make test % make install You probably don't want to do that unless you're fiddling with the module and only want to run the tests without installing anything. =head2 Source location The meta data, such as the source repository and bug tracker, is in I or the I files it creates. You can find that on those CPAN web interfaces, but you can also look at files directly in the source repository: =over 4 =item * L =back If you find a problem, file a ticket in the L: =over 4 =item * L =back =head2 Getting help Although I'm happy to hear from module users in private email, that's the best way for me to forget to do something. Besides the issue trackers, you can find help at L or L, both of which have many competent Perlers who can answer your question, almost in real time. They might not know the particulars of this module, but they can help you diagnose your problem. You might like to read L. =head2 Copyright and License You should have received a I file, but the license is also noted in the module files. About the only thing you can't do is pretend that you wrote code that you didn't. =head2 Good luck! Enjoy, brian d foy, bdfoy@cpan.org =cut Module-Extract-Use-1.043/t/000755 000765 000024 00000000000 13044773752 015625 5ustar00brianstaff000000 000000 Module-Extract-Use-1.043/xt/000755 000765 000024 00000000000 13044773752 016015 5ustar00brianstaff000000 000000 Module-Extract-Use-1.043/xt/changes.t000644 000765 000024 00000000203 13044773747 017611 0ustar00brianstaff000000 000000 use Test::More; eval 'use Test::CPAN::Changes'; plan skip_all => 'Test::CPAN::Changes required for this test' if $@; changes_ok(); Module-Extract-Use-1.043/t/get_modules.t000644 000765 000024 00000002722 13044773747 020330 0ustar00brianstaff000000 000000 #!/usr/bin/perl use strict; use Test::More tests => 16; use File::Basename; use File::Spec::Functions qw(catfile); my $class = "Module::Extract::Use"; use_ok( $class ); my $extor = $class->new; isa_ok( $extor, $class ); can_ok( $extor, 'get_modules' ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Try it with a file that doesn't exist, should fail { my $not_there = 'not_there'; ok( ! -e $not_there, "Missing file is actually missing" ); $extor->get_modules( $not_there ); like( $extor->error, qr/does not exist/, "Missing file give right error" ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Try it with this file { my $test = $0; ok( -e $test, "Test file is there" ); my %modules = map { $_, 1 } $extor->get_modules( $test ); ok( ! $extor->error, "No error for parseable file [$test]"); foreach my $module ( qw(Test::More File::Basename File::Spec::Functions strict) ) { ok( exists $modules{$module}, "Found $module" ); } foreach my $module ( qw(Foo Bar::Baz) ) { ok( ! exists $modules{$module}, "Didn't find $module" ); } } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Try it with a file that has repeated use lines # I should only get unique names { my $file = catfile( qw(corpus Repeated.pm) ); ok( -e $file, "Test file [$file] is there" ); my @modules = sort { $a cmp $b } $extor->get_modules( $file ); is( scalar @modules, 3 ); is_deeply( \@modules, [qw(constant strict warnings)] ); } Module-Extract-Use-1.043/t/imports.t000755 000765 000024 00000006671 13044773747 017530 0ustar00brianstaff000000 000000 #!/usr/bin/perl use strict; use Test::More tests => 6; use File::Basename; use File::Spec::Functions qw(catfile); my $class = "Module::Extract::Use"; use_ok( $class ); my $extor = $class->new; isa_ok( $extor, $class ); can_ok( $extor, 'get_modules_with_details' ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Try it with a file that has repeated use lines # I should only get unique names { my $file = catfile( qw(corpus PackageImports.pm) ); ok( -e $file, "Test file [$file] is there" ); my $details = $extor->get_modules_with_details( $file ); is( scalar @$details, 10, 'There are the right number of hits' ); #diag( Dumper( $details ) ); use Data::Dumper; is_deeply( $details, expected(), 'The data structures match' ); } sub expected { return [ { 'pragma' => '', 'version' => undef, 'imports' => [], 'module' => 'URI', 'content' => 'use URI;', }, { 'content' => 'use CGI qw(:standard);', 'pragma' => '', 'version' => undef, 'imports' => [ ':standard' ], 'module' => 'CGI' }, { 'content' => 'use LWP::Simple 1.23 qw(getstore);', 'pragma' => '', 'version' => '1.23', 'imports' => [ 'getstore' ], 'module' => 'LWP::Simple' }, { 'content' => 'use File::Basename (\'basename\', \'dirname\');', 'pragma' => '', 'version' => undef, 'imports' => [ 'basename', 'dirname' ], 'module' => 'File::Basename' }, { 'content' => 'use File::Spec::Functions qw(catfile rel2abs);', 'pragma' => '', 'version' => undef, 'imports' => [ 'catfile', 'rel2abs' ], 'module' => 'File::Spec::Functions' }, { 'content' => 'use autodie \':open\';', 'pragma' => 'autodie', 'version' => undef, 'imports' => [ ':open' ], 'module' => 'autodie' }, { 'content' => 'use strict q\'refs\';', 'pragma' => 'strict', 'version' => undef, 'imports' => [ 'refs' ], 'module' => 'strict' }, { 'content' => 'use warnings q;', 'pragma' => 'warnings', 'version' => undef, 'imports' => [ 'redefine' ], 'module' => 'warnings' }, { 'content' => 'use Buster "brush";', 'pragma' => '', 'version' => undef, 'imports' => [ 'brush' ], 'module' => 'Buster' }, { 'content' => 'use Mimi qq{string};', 'pragma' => '', 'version' => undef, 'imports' => [ 'string' ], 'module' => 'Mimi' } ]; } Module-Extract-Use-1.043/t/load.t000644 000765 000024 00000000306 13044773747 016734 0ustar00brianstaff000000 000000 BEGIN { @classes = qw(Module::Extract::Use); } use Test::More tests => scalar @classes; foreach my $class ( @classes ) { print "Bail out! $class did not compile\n" unless use_ok( $class ); } Module-Extract-Use-1.043/t/pod.t000644 000765 000024 00000000201 13044773747 016571 0ustar00brianstaff000000 000000 use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Module-Extract-Use-1.043/t/pod_coverage.t000644 000765 000024 00000000271 13044773747 020453 0ustar00brianstaff000000 000000 use Test::More; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@; all_pod_coverage_ok(); Module-Extract-Use-1.043/t/rt/000755 000765 000024 00000000000 13044773752 016252 5ustar00brianstaff000000 000000 Module-Extract-Use-1.043/t/test_manifest000644 000765 000024 00000000112 13044773747 020413 0ustar00brianstaff000000 000000 load.t pod.t pod_coverage.t get_modules.t imports.t versions.t rt/79273.t Module-Extract-Use-1.043/t/versions.t000755 000765 000024 00000002645 13044773747 017700 0ustar00brianstaff000000 000000 #!/usr/bin/perl use strict; use Test::More tests => 6; use File::Basename; use File::Spec::Functions qw(catfile); my $class = "Module::Extract::Use"; use_ok( $class ); my $extor = $class->new; isa_ok( $extor, $class ); can_ok( $extor, 'get_modules_with_details' ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Try it with a file that has repeated use lines # I should only get unique names { my $file = catfile( qw(corpus PackageVersion.pm) ); ok( -e $file, "Test file [$file] is there" ); my $details = $extor->get_modules_with_details( $file ); is( scalar @$details, 3 ); #diag( Dumper( $details ) ); use Data::Dumper; is_deeply( $details, expected() ); print Dumper( $details ), "\n"; use Data::Dumper; } sub expected { return [ { 'content' => 'use HTTP::Size 1.23;', 'pragma' => '', 'version' => '1.23', 'imports' => [], 'module' => 'HTTP::Size' }, { 'content' => 'use YAML::Syck 1.54 qw(LoadFile);', 'pragma' => '', 'version' => '1.54', 'imports' => [ qw(LoadFile) ], 'module' => 'YAML::Syck' }, { 'content' => 'use LWP::Simple 6.1 qw(getstore);', 'pragma' => '', 'version' => '6.1', 'imports' => [ qw(getstore) ], 'module' => 'LWP::Simple' } ]; } Module-Extract-Use-1.043/t/rt/79273.t000755 000765 000024 00000002237 13044773747 017145 0ustar00brianstaff000000 000000 #!/usr/bin/perl use strict; use Test::More tests => 6; use File::Basename; use File::Spec::Functions qw(catfile); my $class = "Module::Extract::Use"; use_ok( $class ); my $extor = $class->new; isa_ok( $extor, $class ); can_ok( $extor, 'get_modules_with_details' ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Try it with a file that has repeated use lines # I should only get unique names { my $file = catfile( qw(corpus RT79273.pm) ); ok( -e $file, "Test file [$file] is there" ); my $details = $extor->get_modules_with_details( $file ); is( scalar @$details, 2, 'There are the right number of hits' ); is_deeply( $details, expected(), 'The data structures match' ); } sub expected { return [ { 'content' => 'use parent \'CGI::Snapp\';', 'pragma' => 'parent', 'version' => undef, 'imports' => [qw(CGI::Snapp)], 'module' => 'parent' }, { 'content' => 'use Capture::Tiny \'capture\';', 'pragma' => '', 'version' => undef, 'imports' => [qw(capture)], 'module' => 'Capture::Tiny' }, ]; } Module-Extract-Use-1.043/lib/Module/000755 000765 000024 00000000000 13044773752 017355 5ustar00brianstaff000000 000000 Module-Extract-Use-1.043/lib/Module/Extract/000755 000765 000024 00000000000 13044773752 020767 5ustar00brianstaff000000 000000 Module-Extract-Use-1.043/lib/Module/Extract/Use.pm000644 000765 000024 00000011412 13044773747 022064 0ustar00brianstaff000000 000000 package Module::Extract::Use; use strict; use warnings; no warnings; use subs qw(); use vars qw($VERSION); $VERSION = '1.043'; =encoding utf8 =head1 NAME Module::Extract::Use - Pull out the modules a module explicitly uses =head1 SYNOPSIS use Module::Extract::Use; my $extor = Module::Extract::Use->new; my @modules = $extor->get_modules( $file ); if( $extor->error ) { ... } my $details = $extor->get_modules_with_details( $file ); foreach my $detail ( @$details ) { printf "%s %s imports %s\n", $detail->module, $detail->version, join ' ', @{ $detail->imports } } =head1 DESCRIPTION Extract the names of the modules used in a file using a static analysis. Since this module does not run code, it cannot find dynamic uses of modules, such as C. It only reports modules that the file loads directly. Modules loaded with C or C, for instance, will will be in the import list for those pragmas but won't have separate entries in the data this module returns. =cut =over 4 =item new Makes an object. The object doesn't do anything just yet, but you need it to call the methods. =cut sub new { my $class = shift; my $self = bless {}, $class; $self->init; $self; } =item init Set up the object. You shouldn't need to call this yourself. =cut sub init { $_[0]->_clear_error; } =item get_modules( FILE ) Returns a list of namespaces explicity use-d in FILE. Returns undef if the file does not exist or if it can't parse the file. Each used namespace is only in the list even if it is used multiple times in the file. The order of the list does not correspond to anything so don't use the order to infer anything. =cut sub get_modules { my( $self, $file ) = @_; $self->_clear_error; my $details = $self->get_modules_with_details( $file ); return unless defined $details; my @modules = map { $_->{module} } @$details; } =item get_modules_with_details( FILE ) Returns a list of hash references, one reference for each namespace explicitly use-d in FILE. Each reference has keys for: namespace - the namespace, always defined version - defined if a module version was specified imports - an array reference to the import list pragma - true if the module thinks this namespace is a pragma Each used namespace is only in the list even if it is used multiple times in the file. The order of the list does not correspond to anything so don't use the order to infer anything. =cut sub get_modules_with_details { my( $self, $file ) = @_; $self->_clear_error; my $modules = $self->_get_ppi_for_file( $file ); return unless defined $modules; $modules; } sub _get_ppi_for_file { my( $self, $file ) = @_; unless( -e $file ) { $self->_set_error( ref( $self ) . ": File [$file] does not exist!" ); return; } require PPI; my $Document = eval { PPI::Document->new( $file ) }; unless( $Document ) { $self->_set_error( ref( $self ) . ": Could not parse file [$file]" ); return; } my $modules = $Document->find( sub { $_[1]->isa( 'PPI::Statement::Include' ) && ( $_[1]->type eq 'use' || $_[1]->type eq 'require' ) } ); return unless $modules; my %Seen; my @modules = grep { ! $Seen{ $_->{module} }++ && $_->{module} } map { my $hash = bless { content => $_->content, pragma => $_->pragma, module => $_->module, imports => [ $self->_list_contents( $_->arguments ) ], version => eval{ $_->module_version->literal || ( undef ) }, }, 'Module::Extract::Use::Item'; } @$modules; return \@modules; } BEGIN { package Module::Extract::Use::Item; sub pragma { $_[0]->{pragma} } sub module { $_[0]->{module} } sub imports { $_[0]->{imports} } sub version { $_[0]->{version} } } sub _list_contents { my( $self, $node ) = @_; eval { if( ! defined $node ) { return; } elsif( $node->isa( 'PPI::Token::QuoteLike::Words' ) ) { ( $node->literal ) } elsif( $node->isa( 'PPI::Structure::List' ) ) { my $nodes = $node->find( sub{ $_[1]->isa( 'PPI::Token::Quote' ) } ); map { $_->string } @$nodes; } elsif( $node->isa( 'PPI::Token::Quote' ) ) { ( $node->string ); } }; } =item error Return the error from the last call to C. =cut sub _set_error { $_[0]->{error} = $_[1]; } sub _clear_error { $_[0]->{error} = '' } sub error { $_[0]->{error} } =back =head1 TO DO =over 4 =item * Make it recursive, so it scans the source for any module that it finds. =back =head1 SEE ALSO L =head1 SOURCE AVAILABILITY The source code is in Github: git://github.com/briandfoy/module-extract-use.git =head1 AUTHOR brian d foy, C<< >> =head1 COPYRIGHT AND LICENSE Copyright © 2008-2017, brian d foy C<< >>. All rights reserved. This project is under the Artistic License 2.0. =cut 1; Module-Extract-Use-1.043/examples/extract_modules000644 000765 000024 00000007513 13044773747 022337 0ustar00brianstaff000000 000000 #!/usr/bin/perl use v5.10; use open qw(:std :utf8); use strict; use warnings; use Pod::Usage; use Getopt::Std qw(getopts); =head1 NAME extract_modules - determine which Perl modules a given file uses =cut our $VERSION = '1.101'; getopts('jl0', \my %opts); =head1 SYNOPSIS Given Perl files, extract and report the Perl modules included with C or C. # print a verbose text listing $ extract_modules filename [...] Modules required by examples/extract_modules: - Getopt::Std (first released with Perl 5) - Module::CoreList (first released with Perl 5.008009) - Pod::Usage (first released with Perl 5.006) - strict (first released with Perl 5) - warnings (first released with Perl 5.006) 5 module(s) in core, 0 external module(s) # print a succint list, one module per line $ extract_modules -l filename [...] Getopt::Std Module::CoreList Pod::Usage open strict warnings # print a succinct list, modules separated by null bytes # you might like this with xargs -0 $ extract_modules -0 filename [...] Getopt::StdModule::CoreListPod::Usageopenstrictwarnings # print the modules list as JSON $ extract_modules -j filename [...] [ "Getopt::Std", "Module::CoreList", "Pod::Usage", "open", "strict", "warnings" ] =head1 DESCRIPTION This script does not execute the code in the files it examines. It uses the C or C modules which statically analyze the source without compiling or running it. These modules cannot discover modules loaded dynamically through a string eval. =cut # if no parameters are passed, give usage information unless( @ARGV ) { pod2usage( msg => 'Please supply at least one filename to analyze' ); exit; } my( $object, $method ); my @classes = qw( Module::Extract::Use Module::ExtractUse ); my %methods = qw( Module::Extract::Use get_modules Module::ExtractUse extract_use ); foreach my $module ( @classes ) { eval "require $module"; next if $@; ( $object, $method ) = ( $module->new, $methods{$module} ); } die "No usable file scanner module found; exiting...\n" . "Install one of these modules to make this program work:\n" . join( "\n\t", sort keys %methods ) . "\n" unless defined $object; my @Grand_modules; foreach my $file ( @ARGV ) { unless ( -r $file ) { printf STDERR "Could not read $file\n"; next; } my @modules = $object->$method( $file ); push @Grand_modules, @modules; next if $opts{j} || $opts{l} || $opts{0}; # do these after long_list( $file, @modules ) } # Handle these options after going through all the files if( $opts{l} or $opts{0} ) { short_list( @Grand_modules ) } elsif( $opts{j} ) { json_list( @Grand_modules ) } sub short_list { state $Seen = {}; my $glue = $opts{0} ? "\000" : "\n"; print join( $glue, grep( { ! $Seen->{$_}++ } sort @_), '' ); } sub json_list { state $Seen = {}; my $glue = $opts{0} ? "\000" : "\n"; print "[\n\t", join( ",\n\t", map { qq("$_") } grep { ! $Seen->{$_}++ } sort @_ ), "\n]\n"; } BEGIN { my $corelist = eval { require Module::CoreList }; sub long_list { my( $file, @modules ) = @_; printf "Modules required by %s:\n", $file; my( $core, $extern ) = ( 0, 0 ); foreach my $module ( @modules ) { printf " - $module%s\n", $corelist ? do { my $v = Module::CoreList->first_release( $module ); $core++ if $v; $v ? " (first released with Perl $v)" : ''; } : do { $extern++; '' } } printf "%d module(s) in core, %d external module(s)\n\n", $core, $extern; } } =head1 AUTHORS Jonathan Yu C<< >> brian d foy C<< >> =head1 COPYRIGHT & LICENSE Copyright © 2009-2017, brian d foy . All rights reserved. You can use this script under the same terms as Perl itself. =head1 SEE ALSO L, L, L, =cut Module-Extract-Use-1.043/corpus/PackageImports.pm000644 000765 000024 00000000443 13044773747 022151 0ustar00brianstaff000000 000000 use URI; use CGI qw(:standard); use LWP::Simple 1.23 qw(getstore); use File::Basename ('basename', 'dirname'); use File::Spec::Functions qw(catfile rel2abs); use autodie ':open'; use strict q'refs'; use warnings q; use Buster "brush"; use Mimi qq{string}; my $cat = 'Buster'; 1; Module-Extract-Use-1.043/corpus/PackageVersion.pm000644 000765 000024 00000000176 13044773747 022144 0ustar00brianstaff000000 000000 use HTTP::Size 1.23; use 5.013; use YAML::Syck 1.54 qw(LoadFile); use LWP::Simple 6.1 qw(getstore); my $cat = 'Buster'; 1; Module-Extract-Use-1.043/corpus/Repeated.pm000644 000765 000024 00000000253 13044773747 020770 0ustar00brianstaff000000 000000 package Local::Repeated; use strict; use warnings; no warnings; use warnings; use strict; use constant; package Foo; use warnings; { no strict; } use warnings; 1;Module-Extract-Use-1.043/corpus/RT79273.pm000644 000765 000024 00000000204 13044773747 020174 0ustar00brianstaff000000 000000 # https://rt.cpan.org/Ticket/Display.html?id=79273 package Controller; use parent 'CGI::Snapp'; use Capture::Tiny 'capture'; 1;