package Test::Use;

use strict;
use warnings;

our $VERSION = '0.02';

use Exporter;

our @ISA = qw/Exporter/;
our @EXPORT = qw/all_uses_ok/;

use Test::More;

sub all_uses_ok {
  shift if @_ && $_[0] eq 'except';

  my @exceptions = @_;
  my @modules;

  open my $fh, '<', 'MANIFEST';
READ:
  while(my $file = <$fh>) {
    if (my ($module) = $file =~ m|^lib/(.*)\.pm$|) {
      $module =~ s|/|::|g;

      foreach my $rule (@exceptions) {
        next READ if $module eq $rule || $module =~ /$rule/;
      }

      push @modules, $module;
    }
  }
  close $fh;

  plan tests => scalar @modules;

  foreach my $module (@modules) {
    use_ok($module);
  }
}

1;
__END__

=head1 NAME

Test::Use - do use_ok() for all modules MANIFESTed

=head1 SYNOPSIS

  # basic use
  use strict;
  use Test::Use;

  BEGIN { all_uses_ok(); }

  # if you have modules that'll fail use_ok() for themselves
  use strict;
  use Test::Use;

  BEGIN {
    all_uses_ok except => qw(
      Some::Dependent::Module
      Another::Dependent::Module
      ^Yet::Another::Dependent::.*   # you can use regex
    )
  }

=head1 DESCRIPTION

I'm sick of writing 01_load.t (or something like that) that'll do
use_ok() for every module I write. This module reads MANIFEST to
find modules to be tested and does use_ok() for each of them.

=head1 EXPORTED FUNCTIONS

=head2 all_uses_ok

Does Test::More's use_ok() for every module found in MANIFEST.
Tests only modules under 'lib/' directory. If you have modules
you don't want to test, give the module name(s) or regex rule
for the argument. The word 'except' will be ignored as shown
above.

=head1 SEE ALSO

L<Test::More>

=head1 AUTHOR

Kenichi Ishigaki, E<lt>ishigaki@cpan.orgE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2006 by Kenichi Ishigaki

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut
