Test::Dependencies::Light - Light style for checking for dependencies.


Test-Dependencies documentation Contained in the Test-Dependencies distribution.

Index


Code Index:

NAME

Top

Test::Dependencies::Light - Light style for checking for dependencies.

SYNOPSIS

Top

You shouldn't have to include this module yourself. Look at the 'style' option of Test::Dependencies.

This module exports exactly one function.

EXPORTED FUNCTIONS

Top

get_modules_used_in_file

Returns an array ref of all the modules that the passed file uses. This style determines this list by opening the file, stripping out any POD, and using regular expressions to try and find use statements.

AUTHOR

Top

* Jesse Vincent <jesse at bestpractical.com>
* Alex Vandiver <alexmv at bestpractical.com>
* Zev Benjamin <zev at cpan.org>

Please report any bugs or feature requests to bug-test-dependencies at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Dependencies. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Test::Dependencies::Light

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Test-Dependencies

* CPAN Ratings

http://cpanratings.perl.org/d/Test-Dependencies

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Dependencies

* Search CPAN

http://search.cpan.org/dist/Test-Dependencies

LICENCE AND COPYRIGHT

Top


Test-Dependencies documentation Contained in the Test-Dependencies distribution.
package Test::Dependencies::Light;

use warnings;
use strict;
use Pod::Strip;

use Exporter 'import';

our @EXPORT = qw/get_modules_used_in_file/;

sub get_modules_used_in_file {
  my $file = shift;
  my ($fh, $code);
  my %used;

  local $/;
  open $fh, $file or return undef;
  my $data = <$fh>;
  close $fh;
  my $p = Pod::Strip->new;
  $p->output_string(\$code);
  $p->parse_string_document($data);
  $used{$1}++ while $code =~ /^\s*use\s+([\w:]+)/gm;
  while ($code =~ m{^\s*use\s+base\s+(?:qw.|(?:(?:['"]|q.|qq.)))([\w\s:]+)}gm) {
    $used{$_}++ for split ' ', $1;
  }

  return [keys %used];
}

1;