File Coverage

blib/lib/Test/Compile/Internal.pm
Criterion Covered Total %
statement 152 154 98.7
branch 48 52 92.3
condition 10 12 83.3
subroutine 33 33 100.0
pod 15 15 100.0
total 258 266 96.9


line stmt bran cond sub pod time code
1             package Test::Compile::Internal;
2              
3 24     24   972684 use warnings;
  24         183  
  24         846  
4 24     24   130 use strict;
  24         47  
  24         494  
5              
6 24     24   7293 use version; our $VERSION = version->declare("v3.3.0");
  24         32544  
  24         139  
7 24     24   2343 use File::Find;
  24         73  
  24         2033  
8 24     24   171 use File::Spec;
  24         53  
  24         715  
9 24     24   3047 use Test::Builder;
  24         240007  
  24         530  
10 24     24   12502 use IPC::Open3 ();
  24         98962  
  24         25429  
11              
12             =head1 NAME
13              
14             Test::Compile::Internal - Assert that your Perl files compile OK.
15              
16             =head1 SYNOPSIS
17              
18             use Test::Compile::Internal;
19             my $test = Test::Compile::Internal->new();
20             $test->all_files_ok();
21             $test->done_testing();
22              
23             =head1 DESCRIPTION
24              
25             C is an object oriented tool for testing whether your
26             perl files compile.
27              
28             It is primarily to provide the inner workings of C, but it can
29             also be used directly to test a CPAN distribution.
30              
31             =head1 METHODS
32              
33             =over 4
34              
35             =item C
36              
37             A basic constructor, nothing special.
38             =cut
39              
40             sub new {
41 25     25 1 2896 my ($class, %self) = @_;
42 25         85 my $self = \%self;
43              
44 25         165 $self->{test} = Test::Builder->new();
45              
46 25         319 bless ($self, $class);
47 25         89 return $self;
48             }
49              
50             =item C
51              
52             Looks for perl files and tests them all for compilation errors.
53              
54             If C<@search> is defined then it is taken as an array of files or
55             directories to be searched for perl files, otherwise it searches the default
56             locations you'd expect to find perl files in a perl module - see
57             L and L for details.
58              
59             =cut
60             sub all_files_ok {
61 5     5 1 1871 my ($self, @search) = @_;
62              
63 5         28 my $pm_ok = $self->all_pm_files_ok(@search);
64 5         54 my $pl_ok = $self->all_pl_files_ok(@search);
65              
66 5   100     274 return ( $pm_ok && $pl_ok );
67             }
68              
69              
70             =item C
71              
72             Checks all the perl module files it can find for compilation errors.
73              
74             If C<@search> is defined then it is taken as an array of files or
75             directories to be searched for perl files, otherwise it searches the default
76             locations you'd expect to find perl files in a perl module - see
77             L for details.
78              
79             =cut
80             sub all_pm_files_ok {
81 7     7 1 317 my ($self, @search) = @_;
82              
83 7         30 my $test = $self->{test};
84              
85 7         19 my $ok = 1;
86 7         35 for my $file ( $self->all_pm_files(@search) ) {
87 11         6051 my $testok = $self->pm_file_compiles($file);
88 11 100       122 $ok = $testok ? $ok : 0;
89 11         383 $test->ok($testok, "$file compiles");
90             }
91 7         6688 return $ok;
92             }
93              
94              
95             =item C
96              
97             Checks all the perl program files it can find for compilation errors.
98              
99             If C<@search> is defined then it is taken as an array of directories to
100             be searched for perl files, otherwise it searches some default locations
101             - see L.
102              
103             =cut
104             sub all_pl_files_ok {
105 7     7 1 404 my ($self, @search) = @_;
106              
107 7         44 my $test = $self->{test};
108              
109 7         22 my $ok = 1;
110 7         37 for my $file ( $self->all_pl_files(@search) ) {
111 3         18 my $testok = $self->pl_file_compiles($file);
112 3 100       25 $ok = $testok ? $ok : 0;
113 3         81 $test->ok($testok, "$file compiles");
114             }
115 7         3424 return $ok;
116             }
117              
118              
119             =item C
120              
121             An accessor to get/set the verbosity. The default value (undef) will suppress output
122             unless the compilation fails. This is probably what you want.
123              
124             If C is set to true, you'll get the output from 'perl -c'. If it's set to
125             false, all diagnostic output is suppressed.
126              
127             =cut
128              
129             sub verbose {
130 90     90 1 350 my ($self, $verbose) = @_;
131              
132 90 100       428 if ( @_ eq 2 ) {
133 5         18 $self->{_verbose} = $verbose;
134             }
135              
136 90         619 return $self->{_verbose};
137             }
138              
139             =item C
140              
141             Searches for and returns a list of perl module files - that is, files with a
142             F<.pm> extension.
143              
144             If you provide C<@search>, it'll use that as a list of files to
145             process, or directories to search for perl modules.
146              
147             If you don't provide C, it'll search for perl modules in the F
148             directory (if that directory exists). Otherwise it'll search the F directory.
149              
150             Skips any files in F, F<.svn>, or F<.git> directories.
151              
152             =cut
153              
154             sub all_pm_files {
155 13     13 1 5650 my ($self, @search) = @_;
156              
157 13 100       56 if ( ! @search ) {
158 5         25 @search = $self->_default_locations('lib');
159             }
160              
161 13         24 my @pm;
162 13         55 for my $file ( $self->_find_files(@search) ) {
163 33 100       86 if ( $self->_perl_module($file) ) {
164 21         56 push @pm, $file;
165             }
166             }
167 13         67 return @pm;
168             }
169              
170             =item C
171              
172             Searches for and returns a list of perl script files - that is, any files that
173             either have a case insensitive F<.pl>, F<.psgi> extension, or have no extension
174             but have a perl shebang line.
175              
176             If you provide C<@search>, it'll use that as a list of files to
177             process, or directories to search for perl scripts.
178              
179             If you don't provide C, it'll search for perl scripts in the
180             F and F directories if F exists, otherwise
181             it'll search the F