Module-Extract-Use-1.054/0000755000076500000240000000000014777035177014112 5ustar brianstaffModule-Extract-Use-1.054/LICENSE0000644000076500000240000002170414777035174015120 0ustar brianstaffThe Module::Extract::Use module is licensed under under the Artistic License 2.0. Artistic License 2.0 Copyright (c) 2000-2006, The Perl Foundation. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 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 (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed. (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Module-Extract-Use-1.054/Changes0000644000076500000240000000466314777035174015413 0ustar brianstaffRevision history for Perl module Module::Extract::Use 1.054 2025-04-13T22:28:12Z * require a newer version.pm for v5.10.1 tests 1.053 2024-08-17T06:37:31Z * changing over to BRIANDFOY and updating email, etc 1.052 2024-02-05T21:29:59Z * refresh distro, update email addresses 1.051 2022-01-09T18:16:19Z * Fix up t/rt/79273.t regression, GitHub #7 1.049 2022-01-08T21:24:03Z * No code changes. Fix a link in the README.pod. 1.047 2020-04-26T13:06:59Z * extract_modules now has a -e switch to exclude core modules 1.046 2020-04-26T12:46:56Z * Small pod fix 1.045 2019-12-19T12:19:24Z * Fix test for extracting modules from parent and base 1.044 2019-12-18T02:38:56Z * Bump this to a user release. 1.043_02 2019-12-17T12:55:00Z * Small fixes 1.043_01 2019-12-17T12:29:57Z * handle a couple of new cases: - include the modules specified by parent or base - find the require's in expressions, like `my $r = require Foo` 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.054/corpus/0000755000076500000240000000000014777035175015423 5ustar brianstaffModule-Extract-Use-1.054/corpus/PackageImports.pm0000644000076500000240000000044314777035174020672 0ustar brianstaffuse 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.054/corpus/state_require.pm0000644000076500000240000000023314777035174020632 0ustar brianstaff sub do_it { state $rc = require ConfigReader::Simple; } my $rc = require Mojo::Util; my %data = ( require => 42, # Should not report '=>'. ); 1; Module-Extract-Use-1.054/corpus/PackageVersion.pm0000644000076500000240000000017614777035174020665 0ustar brianstaffuse 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.054/corpus/Repeated.pm0000644000076500000240000000025314777035174017511 0ustar brianstaffpackage 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.054/corpus/RT79273.pm0000644000076500000240000000020414777035174016715 0ustar brianstaff# https://rt.cpan.org/Ticket/Display.html?id=79273 package Controller; use parent 'CGI::Snapp'; use Capture::Tiny 'capture'; 1; Module-Extract-Use-1.054/MANIFEST0000644000076500000240000000106514777035177015245 0ustar brianstaffChanges corpus/PackageImports.pm corpus/PackageVersion.pm corpus/Repeated.pm corpus/RT79273.pm corpus/state_require.pm examples/extract_modules INSTALL.SKIP lib/Module/Extract/Use.pm LICENSE Makefile.PL MANIFEST This list of files MANIFEST.SKIP README.pod SECURITY.md t/get_modules.t t/hooks.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.054/t/0000755000076500000240000000000014777035175014353 5ustar brianstaffModule-Extract-Use-1.054/t/pod.t0000644000076500000240000000020114777035174015312 0ustar brianstaffuse 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.054/t/load.t0000644000076500000240000000030514777035174015454 0ustar brianstaffBEGIN { @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.054/t/imports.t0000755000076500000240000000721014777035174016237 0ustar brianstaff#!/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 [ { 'direct' => 1, 'pragma' => '', 'version' => undef, 'imports' => [], 'module' => 'URI', 'content' => 'use URI;', }, { 'direct' => 1, 'content' => 'use CGI qw(:standard);', 'pragma' => '', 'version' => undef, 'imports' => [ ':standard' ], 'module' => 'CGI' }, { 'direct' => 1, 'content' => 'use LWP::Simple 1.23 qw(getstore);', 'pragma' => '', 'version' => '1.23', 'imports' => [ 'getstore' ], 'module' => 'LWP::Simple' }, { 'direct' => 1, 'content' => 'use File::Basename (\'basename\', \'dirname\');', 'pragma' => '', 'version' => undef, 'imports' => [ 'basename', 'dirname' ], 'module' => 'File::Basename' }, { 'direct' => 1, 'content' => 'use File::Spec::Functions qw(catfile rel2abs);', 'pragma' => '', 'version' => undef, 'imports' => [ 'catfile', 'rel2abs' ], 'module' => 'File::Spec::Functions' }, { 'direct' => 1, 'content' => 'use autodie \':open\';', 'pragma' => 'autodie', 'version' => undef, 'imports' => [ ':open' ], 'module' => 'autodie' }, { 'direct' => 1, 'content' => 'use strict q\'refs\';', 'pragma' => 'strict', 'version' => undef, 'imports' => [ 'refs' ], 'module' => 'strict' }, { 'direct' => 1, 'content' => 'use warnings q;', 'pragma' => 'warnings', 'version' => undef, 'imports' => [ 'redefine' ], 'module' => 'warnings' }, { 'direct' => 1, 'content' => 'use Buster "brush";', 'pragma' => '', 'version' => undef, 'imports' => [ 'brush' ], 'module' => 'Buster' }, { 'direct' => 1, 'content' => 'use Mimi qq{string};', 'pragma' => '', 'version' => undef, 'imports' => [ 'string' ], 'module' => 'Mimi' } ]; } Module-Extract-Use-1.054/t/versions.t0000755000076500000240000000330514777035174016413 0ustar brianstaff#!/usr/bin/perl use strict; use Test::More 1.0; 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 ); my $first = $details->[0]; foreach my $key ( keys %$first ) { can_ok( $first, $key ); } is( $first->direct, 1 ); like( $first->content, qr/\Ause\b/ ); ok( ! $first->pragma ); is( $first->version, '1.23' ); is( $first->module, 'HTTP::Size' ); is_deeply( $details, expected() ); } sub expected { return [ { 'direct' => 1, 'content' => 'use HTTP::Size 1.23;', 'pragma' => '', 'version' => '1.23', 'imports' => [], 'module' => 'HTTP::Size' }, { 'direct' => 1, 'content' => 'use YAML::Syck 1.54 qw(LoadFile);', 'pragma' => '', 'version' => '1.54', 'imports' => [ qw(LoadFile) ], 'module' => 'YAML::Syck' }, { 'direct' => 1, 'content' => 'use LWP::Simple 6.1 qw(getstore);', 'pragma' => '', 'version' => '6.1', 'imports' => [ qw(getstore) ], 'module' => 'LWP::Simple' } ]; } done_testing(); Module-Extract-Use-1.054/t/rt/0000755000076500000240000000000014777035175015000 5ustar brianstaffModule-Extract-Use-1.054/t/rt/79273.t0000755000076500000240000000236414777035174015667 0ustar brianstaff#!/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, 3, 'There are the right number of hits' ); is_deeply( $details, expected(), 'The data structures match' ); } sub expected { return [ { 'direct' => 1, 'content' => q(use parent 'CGI::Snapp';), 'pragma' => 'parent', 'version' => undef, 'imports' => [qw(CGI::Snapp)], 'module' => 'parent' }, { 'direct' => 1, 'content' => q(use Capture::Tiny 'capture';), 'pragma' => '', 'version' => undef, 'imports' => [qw(capture)], 'module' => 'Capture::Tiny' }, { 'direct' => 0, 'content' => 'use parent \'CGI::Snapp\';', 'pragma' => '', 'version' => undef, 'imports' => [], 'module' => 'CGI::Snapp' }, ]; } Module-Extract-Use-1.054/t/get_modules.t0000644000076500000240000000537114777035174017054 0ustar brianstaff#!/usr/bin/perl use strict; use Test::More 1.0; use File::Basename; use File::Spec::Functions qw(catfile); my $class = "Module::Extract::Use"; use_ok( $class ); my $extor = $class->new; subtest setup => sub { isa_ok( $extor, $class ); can_ok( $extor, 'get_modules' ); }; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Try it with a file that doesn't exist, should fail subtest missing => sub { 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 a file that doesn't exist, should fail subtest non_perl => sub { my $non_perl = 'corpus'; ok( -e $non_perl, "Non-perl file is actually missing" ); my $result = $extor->get_modules( $non_perl ); is( $result, 0, "Non-perl file returns 0 in scalar context" ); my @results = $extor->get_modules( $non_perl ); is( scalar @results, 0, "Non-perl file returns empty list in list context" ); }; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Try it with this file subtest this_file => sub { 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 subtest repeated => sub { 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)] ); }; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # subtest rt79273 => sub { my $file = catfile( qw(corpus RT79273.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(CGI::Snapp Capture::Tiny parent)] ); }; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # subtest expression => sub { my $file = catfile( qw(corpus state_require.pm) ); ok( -e $file, "Test file [$file] is there" ); my @modules = sort { $a cmp $b } $extor->get_modules( $file ); is( scalar @modules, 2 ); is_deeply( \@modules, [qw(ConfigReader::Simple Mojo::Util)] ); }; done_testing(); Module-Extract-Use-1.054/t/test_manifest0000644000076500000240000000011214777035174017134 0ustar brianstaffload.t pod.t pod_coverage.t get_modules.t imports.t versions.t rt/79273.t Module-Extract-Use-1.054/t/pod_coverage.t0000644000076500000240000000027114777035174017174 0ustar brianstaffuse 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.054/xt/0000755000076500000240000000000014777035175014543 5ustar brianstaffModule-Extract-Use-1.054/xt/changes.t0000644000076500000240000000020314777035174016332 0ustar brianstaffuse Test::More; eval 'use Test::CPAN::Changes'; plan skip_all => 'Test::CPAN::Changes required for this test' if $@; changes_ok(); Module-Extract-Use-1.054/README.pod0000644000076500000240000001157514777035174015561 0ustar brianstaff=pod =encoding utf8 =for HTML =for HTML =for HTML =for HTML =for HTML Coverage Status =for HTML =for HTML =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 at L. 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: L If you find a problem, file a ticket in the L. There are also backup repositories hosted on other services. These reflect the state of the main repo and exist only for redundancy: =over 4 =item * L =item * L =item * L =back =head2 GitHub Attestations This distribution now uses L, which allow you to verify that the archive file you have was made from the official repo. You need a GitHub account and the L. # download the distro file from GitHub, MetaCPAN, or a CPAN mirror $ gh auth login ...follow instructions... $ gh attestation verify Module-Extract-Use-1.23.tar.gz --owner briandfoy =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, briandfoy@pobox.com =cut Module-Extract-Use-1.054/MANIFEST.SKIP0000644000076500000240000000213514777035174016006 0ustar brianstaff #!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 \.?appveyor.yml \.releaserc \.lwpcookies Module-.* \bMANIFEST\s\d \bChanges\s\d \.icloud$ \A\.github\b \.gitattributes\b \.appveyor Module-Extract-Use-1.054/examples/0000755000076500000240000000000014777035175015726 5ustar brianstaffModule-Extract-Use-1.054/examples/extract_modules0000644000076500000240000001246714777035174021064 0ustar brianstaff#!/usr/bin/perl use v5.10; use open qw(:std :utf8); use strict; use warnings; use Pod::Usage; use Getopt::Std qw(getopts); =encoding utf8 =head1 NAME extract_modules - determine which Perl modules a given file uses =cut our $VERSION = '1.104'; =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" ] # print the modules list as a basic cpanfile # https://metacpan.org/pod/cpanfile $ extract_modules -c filename [...] requires 'Getopt::Std', '1.23'; requires 'Module::CoreList'; requires 'Pod::Usage'; requires 'open'; requires 'strict'; requires '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. =head2 Command-line options =over 4 =item * -c cpanfile output =item * -e exclude core modules =item * -j JSON output =item * -l succint list, one module per line =item * -0 succint list, modules null separated (for xargs -0) =cut run(@ARGV) unless caller; sub run { my @args = @_; getopts('ecjl0', \my %opts); # if no parameters are passed, give usage information unless( @args ) { pod2usage( msg => 'Please supply at least one filename to analyze' ); exit; } use Data::Dumper; my( $object, $method, $sub ); my @classes = qw( Module::Extract::Use Module::ExtractUse ); my %methods = ( 'Module::Extract::Use' => [ 'get_modules_with_details', sub { [ $_[0]->module, $_[0]->version ]; } ], 'Module::ExtractUse' => [ 'extract_use', sub { say Dumper( \@_ ); [ $_[0], undef ]; } ], ); foreach my $module ( @classes ) { eval "require $module"; next if $@; ( $object, $method, $sub ) = ( $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 ( @args ) { unless ( -r $file ) { printf STDERR "Could not read $file\n"; next; } my @modules = $object->$method( $file ); my $ref = ref $modules[0] ? $modules[0] : \@modules; push @Grand_modules, map { $sub->( $_ ) } @$ref; # remove core modules @Grand_modules = grep { ! defined Module::CoreList->first_release( $_->[0] ) } @Grand_modules if $opts{e}; next if $opts{j} || $opts{l} || $opts{0} || $opts{c}; # do these after # Handle this here because we want the filename long_list( $file, @Grand_modules ) } # Handle these options after going through all the files if( $opts{l} or $opts{0} ) { short_list( \%opts, @Grand_modules ) } elsif( $opts{j} ) { json_list( \%opts, @Grand_modules ) } elsif( $opts{c} ) { cpan_file( \%opts, @Grand_modules ) } } sub short_list { state $Seen = {}; my $opts = shift; my $glue = $opts->{0} ? "\000" : "\n"; print join( $glue, grep( { ! $Seen->{$_}++ } sort map { $_->[0] } @_ ), '' ); } sub json_list { state $Seen = {}; my $opts = shift; my $glue = $opts->{0} ? "\000" : "\n"; print "[\n\t", join( ",\n\t", map { qq("$_") } grep { ! $Seen->{$_}++ } sort map { $_->[0] } @_ ), "\n]\n"; } sub cpan_file { state $Seen = {}; my $opts = shift; foreach my $module ( @_ ) { printf "requires '%s'", $module->[0]; printf ", '%s'", $module->[1] if defined $module->[1]; print ";\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 $tuple ( @modules ) { my( $module, $version ) = @$tuple; 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; } } =back =head1 AUTHORS Jonathan Yu C<< >> brian d foy C<< >> =head1 COPYRIGHT & LICENSE Copyright © 2009-2024, 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.054/META.yml0000664000076500000240000000167114777035176015371 0ustar brianstaff--- abstract: 'Discover the modules a module explicitly uses' author: - 'brian d foy ' build_requires: Test::More: '1' Test::Output: '0' version: '0.86' configure_requires: ExtUtils::MakeMaker: '6.64' File::Spec::Functions: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010' 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: - t - inc - 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 version: '1.054' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Module-Extract-Use-1.054/lib/0000755000076500000240000000000014777035175014656 5ustar brianstaffModule-Extract-Use-1.054/lib/Module/0000755000076500000240000000000014777035175016103 5ustar brianstaffModule-Extract-Use-1.054/lib/Module/Extract/0000755000076500000240000000000014777035175017515 5ustar brianstaffModule-Extract-Use-1.054/lib/Module/Extract/Use.pm0000644000076500000240000001610714777035174020613 0ustar brianstaffuse v5.10; package Module::Extract::Use; use strict; use warnings; no warnings; our $VERSION = '1.054'; =encoding utf8 =head1 NAME Module::Extract::Use - Discover 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 or are in the import lists for L or L. The module can handle the conventional inclusion of modules with either C or C as the statement: use Foo; require Foo; use Foo 1.23; use Foo qw(this that); It now finds C as an expression, which is useful to lazily load a module once (and may be faster): sub do_something { state $rc = require Foo; ... } Additionally, it finds module names used with C and C, either of which establish an inheritance relationship: use parent qw(Foo); use base qw(Foo); In the case of namespaces found in C or C, the value of the C method is false. In all other cases, it is true. You can then skip those namespaces: my $details = $extor->get_modules_with_details( $file ); foreach my $detail ( @$details ) { next unless $detail->direct; ... } This module does not discover runtime machinations to load something, such as string evals: eval "use Foo"; my $bar = 'Bar'; eval "use $bar"; If you want that, you might consider L (a confusingly similar name). =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 the empty list 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 ); my @modules = map { $_->module } @$details; @modules; } =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 direct - false if the module name came from parent or base 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; } # this handles the # use Foo; # use Bar; my $regular_modules = $self->_regular_load( $Document ); # this handles # use parent qw(...) my $isa_modules = $self->_isa_load( $regular_modules ); # this handles # my $rc = require Foo; my $expression_loads = $self->_expression_load( $Document ); my @modules = map { @$_ } $regular_modules, $isa_modules, $expression_loads ; return \@modules; } sub _regular_load { my( $self, $Document ) = @_; my $modules = $Document->find( sub { $_[1]->isa( 'PPI::Statement::Include' ) } ); return [] unless $modules; my %Seen; my @modules = grep { ! $Seen{ $_->{module} }++ && $_->{module} } map { my $hash = bless { direct => 1, content => $_->content, pragma => $_->pragma, module => $_->module, imports => [ $self->_list_contents( $_->arguments ) ], version => eval{ $_->module_version->literal || ( undef ) }, }, 'Module::Extract::Use::Item'; } @$modules; \@modules; } sub _isa_load { my( $self, $modules ) = @_; my @isa_modules = map { my $m = $_; map { bless { content => $m->content, pragma => '', direct => 0, module => $_, imports => [], version => undef, }, 'Module::Extract::Use::Item'; } @{ $m->imports }; } grep { $_->module eq 'parent' or $_->module eq 'base' } @$modules; \@isa_modules; } sub _expression_load { my( $self, $Document ) = @_; my $in_statements = $Document->find( sub { my $sib; $_[1]->isa( 'PPI::Token::Word' ) && $_[1]->content eq 'require' && ( $sib = $_[1]->snext_sibling() ) && $sib->isa( 'PPI::Token::Word' ) } ); return [] unless $in_statements; my @modules = map { bless { content => $_->parent->content, pragma => undef, direct => 1, module => $_->snext_sibling->content, imports => [], version => undef, }, 'Module::Extract::Use::Item'; } @$in_statements; \@modules; } BEGIN { package Module::Extract::Use::Item; sub direct { $_[0]->{direct} } sub content { $_[0]->{content} } 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 =head1 SEE ALSO L, L =head1 SOURCE AVAILABILITY The source code is in Github: https://github.com/briandfoy/module-extract-use =head1 AUTHOR brian d foy, C<< >> =head1 COPYRIGHT AND LICENSE Copyright © 2008-2025, brian d foy C<< >>. All rights reserved. This project is under the Artistic License 2.0. =cut 1; Module-Extract-Use-1.054/Makefile.PL0000644000076500000240000000554714777035174016074 0ustar brianstaffpackage 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' => 'artistic_2', 'AUTHOR' => 'brian d foy ', 'CONFIGURE_REQUIRES' => { 'ExtUtils::MakeMaker' => '6.64', 'File::Spec::Functions' => '0', }, 'BUILD_REQUIRES' => { }, 'TEST_REQUIRES' => { 'Test::More' => '1', 'Test::Output' => '0', 'version' => '0.86', }, '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, 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.054/INSTALL.SKIP0000644000076500000240000000015614777035174015707 0ustar brianstaffREADME\.pod README.* # things that might be in local directories after fooling # around with them \.DS_Store Module-Extract-Use-1.054/SECURITY.md0000644000076500000240000000231514777035174015701 0ustar brianstaff# Security Policy for Module::Extract::Use ## Reporting security issues **Do not report security problems on public forums or in repository issues.** Privately report vulnerabilities to the maintainers listed at the end of this document. Include as many details as possible to reproduce the issue, including code samples or test cases. Check that your report does not expose any of your sensitive data, such as passwords, tokens, or other secrets. You do not need to have a solution or fix. Depending on the issue, CPANSec may be notified. Depending on the issue, CPANSec may be notified. You can also privately report issues to the CPAN Security Group (CPANSec) . This is especially important if you think a vulnerability is being actively exploited. CPANSec may report the issue to the relevant authorities. See [Report a Security Issue](https://security.metacpan.org/docs/report.html). ## Response to reports The maintainers aim to respond to all reports within one day, but this may be affected by life and other things that happen to people who maintain open source code. A new release will be provided as soon as possible. ## Maintainers * brian d foy, Module-Extract-Use-1.054/META.json0000664000076500000240000000321314777035177015534 0ustar brianstaff{ "abstract" : "Discover the modules a module explicitly uses", "author" : [ "brian d foy " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010", "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" : [ "t", "inc", "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" : "1", "Test::Output" : "0", "version" : "0.86" } } }, "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", "web" : "https://github.com/briandfoy/module-extract-use" } }, "version" : "1.054", "x_serialization_backend" : "JSON::PP version 4.16" }