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   969588 use warnings;
  24         217  
  24         800  
4 24     24   129 use strict;
  24         43  
  24         463  
5              
6 24     24   7215 use version; our $VERSION = version->declare("v3.3.1");
  24         31964  
  24         148  
7 24     24   2373 use File::Find;
  24         51  
  24         2061  
8 24     24   163 use File::Spec;
  24         47  
  24         710  
9 24     24   2925 use Test::Builder;
  24         248404  
  24         503  
10 24     24   12302 use IPC::Open3 ();
  24         98893  
  24         25714  
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 2991 my ($class, %self) = @_;
42 25         100 my $self = \%self;
43              
44 25         163 $self->{test} = Test::Builder->new();
45              
46 25         298 bless ($self, $class);
47 25         93 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 1865 my ($self, @search) = @_;
62              
63 5         30 my $pm_ok = $self->all_pm_files_ok(@search);
64 5         73 my $pl_ok = $self->all_pl_files_ok(@search);
65              
66 5   100     350 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 624 my ($self, @search) = @_;
82              
83 7         24 my $test = $self->{test};
84              
85 7         29 my $ok = 1;
86 7         48 for my $file ( $self->all_pm_files(@search) ) {
87 11         7452 my $testok = $self->pm_file_compiles($file);
88 11 100       115 $ok = $testok ? $ok : 0;
89 11         504 $test->ok($testok, "$file compiles");
90             }
91 7         7248 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 432 my ($self, @search) = @_;
106              
107 7         34 my $test = $self->{test};
108              
109 7         28 my $ok = 1;
110 7         65 for my $file ( $self->all_pl_files(@search) ) {
111 3         27 my $testok = $self->pl_file_compiles($file);
112 3 100       43 $ok = $testok ? $ok : 0;
113 3         91 $test->ok($testok, "$file compiles");
114             }
115 7         5143 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 380 my ($self, $verbose) = @_;
131              
132 90 100       429 if ( @_ eq 2 ) {
133 5         16 $self->{_verbose} = $verbose;
134             }
135              
136 90         707 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 7886 my ($self, @search) = @_;
156              
157 13 100       51 if ( ! @search ) {
158 5         29 @search = $self->_default_locations('lib');
159             }
160              
161 13         30 my @pm;
162 13         44 for my $file ( $self->_find_files(@search) ) {
163 33 100       105 if ( $self->_perl_module($file) ) {
164 21         62 push @pm, $file;
165             }
166             }
167 13         98 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