File Coverage

blib/lib/Test/Compile/Internal.pm
Criterion Covered Total %
statement 152 153 99.3
branch 50 56 89.2
condition 10 15 66.6
subroutine 33 33 100.0
pod 15 15 100.0
total 260 272 95.5


line stmt bran cond sub pod time code
1             package Test::Compile::Internal;
2              
3 24     24   956341 use warnings;
  24         189  
  24         846  
4 24     24   140 use strict;
  24         44  
  24         483  
5              
6 24     24   7156 use version; our $VERSION = version->declare("v3.2.2");
  24         31744  
  24         160  
7 24     24   2304 use File::Find;
  24         57  
  24         1991  
8 24     24   163 use File::Spec;
  24         49  
  24         810  
9 24     24   2780 use Test::Builder;
  24         243742  
  24         502  
10 24     24   12324 use IPC::Open3 ();
  24         97315  
  24         25094  
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 2867 my ($class, %self) = @_;
42 25         69 my $self = \%self;
43              
44 25         182 $self->{test} = Test::Builder->new();
45              
46 25         305 bless ($self, $class);
47 25         82 return $self;
48             }
49              
50             =item C
51              
52             Looks for perl files and tests them all for compilation errors.
53              
54             If C<@dirs> is defined then it is taken as an array of files or directories to be
55             searched for perl files, otherwise it searches the default locations you'd expect to find
56             perl files in a perl module - see L and L
57             for details.
58              
59             =cut
60             sub all_files_ok {
61 4     4 1 623 my ($self, @dirs) = @_;
62              
63 4         18 my $pm_ok = $self->all_pm_files_ok(@dirs);
64 4         75 my $pl_ok = $self->all_pl_files_ok(@dirs);
65              
66 4 100 66     116 if ( $pm_ok && $pl_ok ) {
67 3         341 return 1;
68             }
69             }
70              
71              
72             =item C
73              
74             Checks all the perl module files it can find for compilation errors.
75              
76             If C<@dirs> is defined then it is taken as an array of files or directories to
77             be searched for perl files, otherwise it searches some default locations
78             - see L.
79              
80             =cut
81             sub all_pm_files_ok {
82 6     6 1 291 my ($self, @dirs) = @_;
83              
84 6         23 my $test = $self->{test};
85              
86 6         14 my $ok = 1;
87 6         44 for my $file ( $self->all_pm_files(@dirs) ) {
88 10         6980 my $testok = $self->pm_file_compiles($file);
89 10 50       115 $ok = $testok ? $ok : 0;
90 10         364 $test->ok($testok, "$file compiles");
91             }
92 6         6594 return $ok;
93             }
94              
95              
96             =item C
97              
98             Checks all the perl program files it can find for compilation errors.
99              
100             If C<@dirs> is defined then it is taken as an array of directories to
101             be searched for perl files, otherwise it searches some default locations
102             - see L.
103              
104             =cut
105             sub all_pl_files_ok {
106 6     6 1 382 my ($self, @dirs) = @_;
107              
108 6         33 my $test = $self->{test};
109              
110 6         28 my $ok = 1;
111 6         40 for my $file ( $self->all_pl_files(@dirs) ) {
112 3         26 my $testok = $self->pl_file_compiles($file);
113 3 100       17 $ok = $testok ? $ok : 0;
114 3         84 $test->ok($testok, "$file compiles");
115             }
116 6         4585 return $ok;
117             }
118              
119              
120             =item C
121              
122             An accessor to get/set the verbosity. The default value (undef) will suppress output
123             unless the compilation fails. This is probably what you want.
124              
125             If C is set to true, you'll get the output from 'perl -c'. If it's set to
126             false, all diagnostic output is suppressed.
127              
128             =cut
129              
130             sub verbose {
131 82     82 1 381 my ($self, $verbose) = @_;
132              
133 82 100       381 if ( @_ eq 2 ) {
134 5         23 $self->{verbose} = $verbose;
135             }
136              
137 82         530 return $self->{verbose};
138             }
139              
140             =item C
141              
142             Searches for and returns a list of perl module files - that is, files with a F<.pm>
143             extension.
144              
145             If you provide a list of C<@dirs>, it'll use that as a list of files to process, or
146             directories to search for perl modules.
147              
148             If you don't provide C, it'll search for perl modules in the F directory,
149             if that directory exists, otherwise it'll search the F directory.
150              
151             Skips any files in F, F<.svn>, or F<.git> directories.
152              
153             =cut
154              
155             sub all_pm_files {
156 12     12 1 5139 my ($self, @dirs) = @_;
157              
158 12 100       63 @dirs = @dirs ? @dirs : $self->_default_locations('lib');
159              
160 12         30 my @pm;
161 12         47 for my $file ( $self->_find_files(@dirs) ) {
162 31 100       79 if ( $self->_perl_module($file) ) {
163 19         45 push @pm, $file;
164             }
165             }
166 12         49 return @pm;
167             }
168              
169             =item C
170              
171             Searches for and returns a list of perl script files - that is, any files that either
172             have a case insensitive F<.pl>, F<.psgi> extension, or have no extension but have a perl shebang line.
173              
174             If you provide a list of C<@dirs>, it'll use that as a list of files to process, or
175             directories to search for perl scripts.
176              
177             If you don't provide C, it'll search for perl scripts in the F
178             and F directories if F exists, otherwise it'll search the F