Commit 13f46ec6 authored by gregor herrmann's avatar gregor herrmann

Imported Upstream version 0.27

parent 9840ce5e
use strict;
use 5.008;
use Module::Build;
use warnings;
use Module::Build 0.3601;
my $class = Module::Build->subclass(code => <<'EOF');
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=0.27;'."\n");
open(my $out,">",$grammar) || die "cannot write $grammer: $!";
print $out @content;
close $out;
my $build = Module::Build->new(
module_name => 'Module::ExtractUse',
license => 'perl',
requires => {
'perl' => '5.008',
'Parse::RecDescent'=>'1.94',
'Pod::Strip'=>'1.00',
},
build_requires=> {
'Test::More'=>'0',
'Test::Deep'=>'0.087',
'Test::NoWarnings'=>'0',
'Test::Pod'=>'0',
'Test::Pod::Coverage'=>'0',
'UNIVERSAL::require'=>'0',
},
create_makefile_pl=>'passthrough',
# 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: $!";
}
EOF
my %module_build_args = (
'build_requires' => {
'Module::Build' => '0.3601',
'Test::Deep' => '0',
'Test::More' => '0',
'Test::NoWarnings' => '0'
},
'configure_requires' => {
'Module::Build' => '0.3601'
},
'requires' => {
'Carp' => '0',
'Parse::RecDescent' => '1.967009',
'Pod::Strip' => '0',
'perl' => '5.008',
'vars' => '0',
'version' => '0'
},
'dist_abstract' => 'Find out what modules are used',
'dist_author' => [
'Thomas Klausner <domm@cpan.org>'
],
'dist_name' => 'Module-ExtractUse',
'dist_version' => '0.27',
'license' => 'perl',
'module_name' => 'Module::ExtractUse',
'module_name' => 'Module::ExtractUse',
'recursive_test_files' => 1,
);
$build->create_build_script;
my $build = $class->new(%module_build_args);
$build->add_build_element('grammar');
$build->create_build_script;
......@@ -2,14 +2,31 @@
# Changes for Module::ExtractUse
#-----------------------------------------------------------------
TODO:
- autogenerate the grammer during ./Build
- take a look at 'use parent'
0.27 2012-03-23T12:40:44+0100
- fixed 23_universal_require.t for real (RT75342) (reported by
Manoj Kumar and Paul Howarth)
0.26 2012-03-23T08:42:25+0100
- removed Test::NoWarning from a t/23_universal_require.t because
it upsets the (manual) plan if the tests are skipped
0.25 2012-03-22T10:55:42+0100
- autogenerate the grammer during ./Build (based on a patch by
jtbraun@CPAN.org) (RT74879)
- added $VERSION to into Module::ExtractUse::Grammar, suggested
by Manoj Kumar (RT75342)
- specify min verion of Parse::RecDescent (1.967009),
suggested by ANDK@cpan.org (RT75130)
- fix typos reported by gregor herrmann (RT75115)
- switched to Dist::Zilla (all on my own!)
0.24 2012-02-12T14:27:36+0100
- regenerated Grammer to work with new Parse::RecDescent
(thanks to cpan-testers, TMUELLER, KENTNL and paul@city-fan.org
for reporting the problem)
(thanks to cpan-testers, TMUELLER, KENTNL, dirkus@yo****.com and
paul@city****.org for reporting the problem)
0.23 2008-04-26 22:14:28
......
This is the Perl distribution Module-ExtractUse.
Installing Module-ExtractUse is straightforward.
## Installation with cpanm
If you have cpanm, you only need one line:
% cpanm Module::ExtractUse
If you are installing into a system-wide directory, you may need to pass the
"-S" flag to cpanm, which uses sudo to install the module:
% cpanm -S Module::ExtractUse
## Installing with the CPAN shell
Alternatively, if your CPAN shell is set up, you should just be able to do:
% cpan Module::ExtractUse
## Manual installation
As a last resort, you can manually install it. Download the tarball, untar it,
then build it:
% perl Build.PL
% ./Build && ./Build test
Then install it:
% ./Build install
If you are installing into a system-wide directory, you may need to run:
% sudo ./Build install
## Documentation
Module-ExtractUse documentation is available as POD.
You can run perldoc from a shell to read the documentation:
% perldoc Module::ExtractUse
This diff is collapsed.
Build.PL
Changes
example/cpan.pl
lib/Module/ExtractUse.pm
lib/Module/ExtractUse/grammar
lib/Module/ExtractUse/Grammar.pm
Makefile.PL
INSTALL
LICENSE
MANIFEST
META.json
META.yml
README
dist.ini
example/cpan.pl
grammar
lib/Module/ExtractUse.pm
lib/Module/ExtractUse/Grammar.pm
t/01_load.t
t/10_basic.t
t/20_parse_self.t
......@@ -19,4 +22,3 @@ t/25_utf8.t
t/80_failing.t
xt/pod.t
xt/pod_coverage.t
META.json
{
"abstract" : "Find out what modules are used",
"author" : [
"Thomas Klausner <domm@zsi.at>"
"Thomas Klausner <domm@cpan.org>"
],
"dynamic_config" : 1,
"generated_by" : "Module::Build version 0.38, CPAN::Meta::Converter version 2.112150",
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 4.200014, CPAN::Meta::Converter version 2.112150",
"license" : [
"perl_5"
],
......@@ -16,46 +16,40 @@
"prereqs" : {
"build" : {
"requires" : {
"Test::Deep" : "0.087",
"Test::More" : 0,
"Test::NoWarnings" : 0,
"Test::Pod" : 0,
"Test::Pod::Coverage" : 0,
"UNIVERSAL::require" : 0
"Module::Build" : "0.3601"
}
},
"configure" : {
"requires" : {
"Module::Build" : "0.38"
"Module::Build" : "0.3601"
}
},
"runtime" : {
"requires" : {
"Parse::RecDescent" : "1.94",
"Pod::Strip" : "1.00",
"perl" : "5.008"
"Carp" : 0,
"Parse::RecDescent" : "1.967009",
"Pod::Strip" : 0,
"perl" : "5.008",
"vars" : 0,
"version" : 0
}
}
},
"provides" : {
"Module::ExtractUse" : {
"file" : "lib/Module/ExtractUse.pm",
"version" : "0.24"
},
"Module::ExtractUse::Grammar" : {
"file" : "lib/Module/ExtractUse/Grammar.pm",
"version" : 0
},
"Parse::RecDescent::Module::ExtractUse::Grammar" : {
"file" : "lib/Module/ExtractUse/Grammar.pm",
"version" : 0
"test" : {
"requires" : {
"Test::Deep" : 0,
"Test::More" : 0,
"Test::NoWarnings" : 0
}
}
},
"release_status" : "stable",
"resources" : {
"license" : [
"http://dev.perl.org/licenses/"
]
"repository" : {
"type" : "git",
"url" : "git://github.com/domm/Module-ExtractUse.git",
"web" : "http://github.com/domm/Module-ExtractUse"
}
},
"version" : "0.24"
"version" : "0.27"
}
---
abstract: 'Find out what modules are used'
author:
- 'Thomas Klausner <domm@zsi.at>'
- 'Thomas Klausner <domm@cpan.org>'
build_requires:
Test::Deep: 0.087
Module::Build: 0.3601
Test::Deep: 0
Test::More: 0
Test::NoWarnings: 0
Test::Pod: 0
Test::Pod::Coverage: 0
UNIVERSAL::require: 0
configure_requires:
Module::Build: 0.38
dynamic_config: 1
generated_by: 'Module::Build version 0.38, CPAN::Meta::Converter version 2.112150'
Module::Build: 0.3601
dynamic_config: 0
generated_by: 'Dist::Zilla version 4.200014, CPAN::Meta::Converter version 2.112150'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: Module-ExtractUse
provides:
Module::ExtractUse:
file: lib/Module/ExtractUse.pm
version: 0.24
Module::ExtractUse::Grammar:
file: lib/Module/ExtractUse/Grammar.pm
version: 0
Parse::RecDescent::Module::ExtractUse::Grammar:
file: lib/Module/ExtractUse/Grammar.pm
version: 0
requires:
Parse::RecDescent: 1.94
Pod::Strip: 1.00
Carp: 0
Parse::RecDescent: 1.967009
Pod::Strip: 0
perl: 5.008
vars: 0
version: 0
resources:
license: http://dev.perl.org/licenses/
version: 0.24
repository: git://github.com/domm/Module-ExtractUse.git
version: 0.27
# Note: this file was auto-generated by Module::Build::Compat version 0.3800
require 5.008;
unless (eval "use Module::Build::Compat 0.02; 1" ) {
print "This module requires Module::Build to install itself.\n";
require ExtUtils::MakeMaker;
my $yn = ExtUtils::MakeMaker::prompt
(' Install Module::Build now from CPAN?', 'y');
unless ($yn =~ /^y/i) {
die " *** Cannot install without Module::Build. Exiting ...\n";
}
require Cwd;
require File::Spec;
require CPAN;
# Save this 'cause CPAN will chdir all over the place.
my $cwd = Cwd::cwd();
CPAN::Shell->install('Module::Build::Compat');
CPAN::Shell->expand("Module", "Module::Build::Compat")->uptodate
or die "Couldn't install Module::Build, giving up.\n";
chdir $cwd or die "Cannot chdir() back to $cwd: $!";
}
eval "use Module::Build::Compat 0.02; 1" or die $@;
Module::Build::Compat->run_build_pl(args => \@ARGV);
my $build_script = 'Build';
$build_script .= '.com' if $^O eq 'VMS';
exit(0) unless(-e $build_script); # cpantesters convention
require Module::Build;
Module::Build::Compat->write_makefile(build_class => 'Module::Build');
Module/ExtractUse version 0.04
==============================
Module::ExtractUse is basically a 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.
This archive contains the distribution Module-ExtractUse,
version 0.27:
INSTALLATION
Find out what modules are used
To install this module type the following:
This software is copyright (c) 2012 by Thomas Klausner.
perl Makefile.PL
make
make test
make install
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
DEPENDENCIES
This module requires these other modules and libraries:
Parse::RecDescent
Pod::Simple
Test::More (only for the testsuite)
COPYRIGHT AND LICENCE
Copyright (C) 2003 Thomas Klausner
name = Module-ExtractUse
author = Thomas Klausner <domm@cpan.org>
license = Perl_5
copyright_holder = Thomas Klausner
copyright_year = 2012
[GatherDir]
[PruneCruft]
[ManifestSkip]
[MetaYAML]
[License]
[Readme]
[Repository]
[MetaResources]
[CheckChangeLog]
[Manifest]
[TestRelease]
[ConfirmRelease]
[AutoPrereqs]
[VersionFromModule]
[ModuleBuild::Custom]
[PodWeaver]
[InstallGuide]
[MetaJSON]
[@Git]
......@@ -5,57 +5,17 @@ use warnings;
use 5.008;
use Pod::Strip;
use Parse::RecDescent;
use Parse::RecDescent 1.967009;
use Module::ExtractUse::Grammar;
use Carp;
use version; our $VERSION=version->new('0.24');
use version; our $VERSION=version->new('0.27');
# ABSTRACT: Find out what modules are used
#$::RD_TRACE=1;
#$::RD_HINT=1;
=head1 NAME
Module::ExtractUse - Find out what modules are used
=head1 SYNOPSIS
use Module::ExtractUse;
# get a parser
my $p=Module::ExtractUse->new;
# parse from a file
$p->extract_use('/path/to/module.pm');
# or parse from a ref to a string in memory
$p->extract_use(\$string_containg_code);
# use some reporting methods
my $used=$p->used; # $used is a HASHREF
print $p->used('strict') # true if code includes 'use strict'
my @used=$p->array;
my $used=$p->string;
=head1 DESCRIPTION
Module::ExtractUse is basically a 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.
"Usage" is defined by either calling C<use> or C<require>.
=head2 Methods
=cut
=head3 new
my $p=Module::ExtractUse->new;
Returns a parser object
=cut
sub new {
my $class=shift;
......@@ -65,32 +25,6 @@ sub new {
},$class;
}
=head3 extract_use
$p->extract_use('/path/to/module.pm');
$p->extract_use(\$string_containg_code);
Runs the parser.
C<$code_to_parse> can be either a SCALAR, in which case
Module::ExtractUse tries to open the file specified in
$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 splitted on ";"
(semicolon). Each statement (i.e. the stuff between two semicolons) is
checked by a simple regular expression.
If the statement contains either 'use' or 'require', the statment is
handed over to the parser, who then tries to figure out, B<what> is
used or required. The results will be saved in a data structure that
you can examine afterwards.
You can call C<extract_use> several times on different files. It will
count how many files where examined and how often each module was used.
=cut
sub extract_use {
my $self=shift;
......@@ -160,31 +94,7 @@ sub extract_use {
return $self;
}
=head2 Accessor Methods
Those are various ways to get at the result of the parse.
Note that C<extract_use> returns the parser object, so you can say
print $p->extract_use($code_to_parse)->string;
=cut
=head3 used
my $used=$p->used; # $used is a HASHREF
print $p->used('strict') # true if code includes 'use strict'
If called without an argument, returns a reference to an hash of all
used modules. Keys are the names of the modules, values are the number
of times they were used.
If called with an argument, looks up the value of the argument in the
hash and returns the number of times it was found during parsing.
This is the prefered accessor.
=cut
sub used {
my $self=shift;
......@@ -193,16 +103,6 @@ sub used {
return $self->{found};
}
=head3 string
print $p->string($seperator)
Returns a sorted string of all used modules, joined using the value of
C<$seperator> or using a blank space as a default;
Module names are sorted by ascii value (i.e by C<sort>)
=cut
sub string {
my $self=shift;
......@@ -210,25 +110,11 @@ sub string {
return join($sep,sort keys(%{$self->{found}}));
}
=head3 array
my @array = $p->array;
Returns an array of all used modules.
=cut
sub array {
return keys(%{shift->{found}})
}
=head3 arrayref
my $arrayref = $p->arrayref;
Returns a reference to an array of all used modules. Surprise!
=cut
sub arrayref {
my @a=shift->array;
......@@ -236,11 +122,6 @@ sub arrayref {
return;
}
=head3 files
Returns the number of files parsed by the parser object.
=cut
sub files {
return shift->{files};
......@@ -263,7 +144,125 @@ sub _inc_files {
1;
__END__
=pod
=head1 NAME
Module::ExtractUse - Find out what modules are used
=head1 VERSION
version 0.27
=head1 SYNOPSIS
use Module::ExtractUse;
# get a parser
my $p=Module::ExtractUse->new;
# parse from a file
$p->extract_use('/path/to/module.pm');
# or parse from a ref to a string in memory
$p->extract_use(\$string_containg_code);
# use some reporting methods
my $used=$p->used; # $used is a HASHREF
print $p->used('strict') # true if code includes 'use strict'
my @used=$p->array;
my $used=$p->string;
=head1 DESCRIPTION
Module::ExtractUse is basically a 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.
"Usage" is defined by either calling C<use> or C<require>.
=head2 Methods
=head3 new
my $p=Module::ExtractUse->new;
Returns a parser object
=head3 extract_use
$p->extract_use('/path/to/module.pm');
$p->extract_use(\$string_containg_code);
Runs the parser.
C<$code_to_parse> can be either a SCALAR, in which case
Module::ExtractUse tries to open the file specified in
$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 ";"
(semicolon). Each statement (i.e. the stuff between two semicolons) is
checked by a simple regular expression.
If the statement contains either 'use' or 'require', the statment is
handed over to the parser, who then tries to figure out, B<what> is
used or required. The results will be saved in a data structure that
you can examine afterwards.
You can call C<extract_use> several times on different files. It will
count how many files where examined and how often each module was used.
=head2 Accessor Methods
Those are various ways to get at the result of the parse.
Note that C<extract_use> returns the parser object, so you can say
print $p->extract_use($code_to_parse)->string;
=head3 used
my $used=$p->used; # $used is a HASHREF
print $p->used('strict') # true if code includes 'use strict'
If called without an argument, returns a reference to an hash of all
used modules. Keys are the names of the modules, values are the number
of times they were used.
If called with an argument, looks up the value of the argument in the
hash and returns the number of times it was found during parsing.
This is the preferred accessor.
=head3 string
print $p->string($seperator)
Returns a sorted string of all used modules, joined using the value of
C<$seperator> or using a blank space as a default;
Module names are sorted by ascii value (i.e by C<sort>)
=head3 array
my @array = $p->array;
Returns an array of all used modules.
=head3 arrayref
my $arrayref = $p->arrayref;
Returns a reference to an array of all used modules. Surprise!
=head3 files
Returns the number of files parsed by the parser object.
=head1 RE-COMPILING THE GRAMMAR
......@@ -284,21 +283,18 @@ Parse::RecDescent, Module::ScanDeps, Module::Info, Module::CPANTS::Analyse
=head1 AUTHOR
Thomas Klausner <domm@zsi.at>
Thomas Klausner <domm@cpan.org>
=head1 BUGS
=head1 COPYRIGHT AND LICENSE
Please report any bugs or feature requests to
C<bug-module-extractuse@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org>. I will be notified, and then you'll automatically
be notified of progress on your bug as I make changes.
This software is copyright (c) 2012 by Thomas Klausner.
=head1 LICENSE
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
Module::ExtractUse is Copyright (c) 2003-2008, Thomas Klausner.
=cut
You may use and distribute this module according to the same terms
that Perl is distributed under.
=cut
__END__