Perl/Analysis/Static/Files.pm

filter: Statementstmt 86.6% 26 / 30 Branchbran 50.0% 5 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 2 totaltotal 74.0% 37 / 50 CC 6 SCAR 11.9
CC
6
Cov
78%
_is_perl_file
6.6
files
3.0
ignoredir_filter
2.0
CRAP 3.3
« Perl/Analysis/Static/Filter/StringLike.pm ↑ Summary Perl/Analysis/Static/Analysis/Declaration/Variable.pm »
1 package Perl::Analysis::Static::Files;
2 {
3 1 $Perl::Analysis::Static::Files::VERSION = '0.004'; # TRIAL
4 }
5  
6 # ABSTRACT: tools for files
7  
8 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use English qw( -no_match_vars ); # Avoids regex performance penalty
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Next;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # stolen from ack, added .build
14 1 our %ignore_dirs = (
15 '.bzr' => 'Bazaar',
16 '.cdv' => 'Codeville',
17 '~.dep' => 'Interface Builder',
18 '~.dot' => 'Interface Builder',
19 '~.nib' => 'Interface Builder',
20 '~.plst' => 'Interface Builder',
21 '.git' => 'Git',
22 '.hg' => 'Mercurial',
23 '.pc' => 'quilt',
24 '.svn' => 'Subversion',
25 '.build' => 'Dist::Zilla',
26 blib => 'Perl module building',
27 CVS => 'CVS',
28 RCS => 'RCS',
29 SCCS => 'SCCS',
30 _darcs => 'darcs',
31 _sgbak => 'Vault/Fortress',
32 'autom4te.cache' => 'autoconf',
33 'cover_db' => 'Devel::Cover',
34 _build => 'Module::Build',
35 );
36  
37 # stolen from ack
38 0 ▶sub ignoredir_filter {
Subroutine ignoredir_filter: not called CC=1 SCAR=6.9
Pod undocumented
39 0 return !exists $ignore_dirs{$_};
40 }
41  
42 1 ▶sub files {
Subroutine files: called CC=3 SCAR=11.1
Pod undocumented
43 1 my ($dir) = @_;
44  
45 0 ▶ my $descend_filter = sub { $_ !~ /^\.$/ };
Subroutine __ANON__: not called CC=1 SCAR=1.2
46  
47 # yes, this might be overhead since we don't use the iterator.
48 # meybe we'll use it later or we might just use File::Find
49 1 my $files =
50 File::Next::files( { descend_filter => \&ignoredir_filter }, $dir );
51  
52 1 my @files;
53 1 ▶ while ( defined( my $file = $files->() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $file = &$files())) 6 1 7
54 6 ▶ push @files, $file if _is_perl_file($file);
Branch: 1 branch
BranchTrueFalseTotal
if _is_perl_file($file) 6 0 6
55 }
56 1 return \@files;
57 }
58  
59 6 ▶sub _is_perl_file {
Subroutine _is_perl_file: called CC=4 SCAR=18.9
60 6 my ($file) = @_;
61 6 ▶ return 1 if $file =~ m{\.t$};
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /\.t$/ 0 6 6
62 6 ▶ return 1 if $file =~ m{\.pl$};
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /\.pl$/ 6 0 6
63 0 ▶ return 1 if $file =~ m{\.pm$};
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /\.pm$/ 0 0 0
64  
65 # TODO: check if shebang line is some perl invocation
66 0 return;
67 }
68  
69 1 1;
70  
71 __END__
« Perl/Analysis/Static/Filter/StringLike.pm ↑ Summary Perl/Analysis/Static/Analysis/Declaration/Variable.pm »