Debian Codegraph @

lib/Module/Install/AuthorTests.pm

raw
1 package Module::Install::AuthorTests;
2
3 use 5.005;
4 use strict;
5 use Module::Install::Base;
6 use Carp ();
7
8 =head1 NAME
9
10 Module::Install::AuthorTests - designate tests only run by module authors
11
12 =head1 VERSION
13
14 0.002
15
16 =cut
17
18 use vars qw{$VERSION $ISCORE @ISA};
19 BEGIN {
20 $VERSION = '0.002';
21 $ISCORE = 1;
22 @ISA = qw{Module::Install::Base};
23 }
24
25 =head1 COMMANDS
26
27 This plugin adds the following Module::Install commands:
28
29 =head2 author_tests
30
31 author_tests('xt');
32
33 This declares that the test files found in the directory F<./xt> should be run
34 only if the module is being built by an author. For an explanation, see below.
35
36 You may declare multiple test directories by passing a list of tests. Since
37 tests are not recursive by default, it should be safe to use a subdirectory of
38 F<./t> for author tests, like:
39
40 author_tests('t/author');
41
42 =cut
43
44 sub author_tests {
45 my ($self, @dirs) = @_;
46 _add_author_tests($self, \@dirs, 0);
47 }
48
49 =head2 recursive_author_tests
50
51 recursive_author_tests('xt');
52
53 This acts like C<author_tests>, but will look for tests in directories below
54 F<./xt> as well as in the directory itself.
55
56 =cut
57
58 sub recursive_author_tests {
59 my ($self, @dirs) = @_;
60 _add_author_tests($self, \@dirs, 1);
61 }
62
63 sub _wanted {
64 my $href = shift;
65 sub { /\.t$/ and -f $_ and $href->{$File::Find::dir} = 1 }
66 }
67
68 sub _add_author_tests {
69 my ($self, $dirs, $recurse) = @_;
70 return unless $Module::Install::AUTHOR;
71
72 my @tests = $self->tests ? (split / /, $self->tests) : 't/*.t';
73
74 # XXX: pick a default, later -- rjbs, 2008-02-24
75 my @dirs = @$dirs ? @$dirs : Carp::confess "no dirs given to author_tests";
76 @dirs = grep { -d } @dirs;
77
78 if ($recurse) {
79 require File::Find;
80 my %test_dir;
81 File::Find::find(_wanted(\%test_dir), @dirs);
82 $self->tests( join ' ', @tests, map { "$_/*.t" } sort keys %test_dir );
83 } else {
84 $self->tests( join ' ', @tests, map { "$_/*.t" } sort @dirs );
85 }
86 }
87
88 =head1 HOW IT WORKS
89
90 "Is this being run by an author?" is determined internally by Module::Install,
91 but at the time of the writing of this version it's determined by the existence
92 of a directory called F<.author> in F<./inc>. (On VMS, it's F<_author>.) This
93 directory is created when Module::Install's F<Makefile.PL> is run in a
94 directory where no F<./inc> directory exists.
95
96 =head1 BUGS
97
98 Please report any bugs or feature requests through the web interface at
99 L<http://rt.cpan.org>. I will be notified, and then you'll automatically be
100 notified of progress on your bug as I make changes.
101
102 =head1 COPYRIGHT
103
104 Copyright 2008, Ricardo SIGNES. This program is free software; you can
105 redistribute it and/or modify it under the same terms as Perl itself.
106
107 =cut
108
109 1;