blib/lib/DBI/Shell/FindSqlFile.pm

filter: Statementstmt 92.8% 39 / 42 Branchbran 63.6% 14 / 22 Conditioncond 50.0% 6 / 12 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 74.7% 68 / 91 CC 15 SCAR 20.8
CC
15
Cov
78%
look_for_file
11.3
wanted
8.8
BEGIN
1.0
CRAP 8.0
« blib/lib/DBI/Shell/Spool.pm ↑ Summary blib/lib/DBI/Shell/Timing.pm »
1 #!/usr/local/bin/perl
2  
3 package DBI::Shell::FindSqlFile;
4  
5 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use File::Find ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Set the variable $File::Find::dont_use_nlink if you're using AFS,
11 # since AFS cheats.
12  
13 # for the convenience of &wanted calls, including -eval statements:
14 7 ▶use vars qw/*name *dir *prune @found $to_find_file $debug/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 *name = *File::Find::name;
16 7 *dir = *File::Find::dir;
17 7 *prune = *File::Find::prune;
18  
19 7 @found = ();
20 7 $to_find_file = undef;
21 7 $debug = 0;
22  
23 sub look_for_file {
24 8 ▶ my $self = shift;
Subroutine look_for_file: called CC=9 SCAR=24.2
Pod undocumented
25 8 my $file = shift;
26 8 my ($base, $dir, $ext) = fileparse($file,'\..*?');
27  
28 8 $debug = $self->{debug};
29  
30 # print "file $file : concat $dir$base$ext\n";
31  
32 # Work-around to fileparse adding current directory.
33 8 ▶ $dir = undef unless ( $file eq "$dir$base$ext" );
Branch: 1 branch
BranchTrueFalseTotal
unless $file eq "$dir$base$ext" 8 0 8
34  
35 8 ▶ unless ($ext) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ext) 0 8 8
36 0 $ext = q{.sql};
37 }
38 # If a directory is defined, return to caller
39 8 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) 0 8 8
40 0 return ( "$dir$base$ext" );
41 };
42  
43 8 $to_find_file = qq{$base$ext};
44  
45 8 ▶ $self->log("calling find with $to_find_file") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 8 8
46  
47  
48 # Split the sqlpath, then determine if any of the directories are valid.
49 14 ▶ my @search_path = map { -d $_ ? $_ : () } split(/:/,
Branch: 2 branches
BranchTrueFalseTotal
-d $_ ? : 8 6 14
defined $self->{'sqlpath'} ? : 8 0 8
50 defined $self->{sqlpath} ? $self->{sqlpath} : ()
51 8 );
52 # , (exists $ENV{DBISH_SQL_PATH} ? $ENV{DBISH_SQL_PATH} : ()) );
53  
54 $self->log( "search path: " . join( "\n", @search_path ) )
55 8 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 8 8
56  
57 # Traverse desired filesystems
58 8 File::Find::find(
59 {
60 wanted => \&wanted
61 , no_chdir => 1
62 , bydepth => 0
63 },
64 @search_path);
65  
66  
67 8 ▶ return shift @found if @found;
Branch: 1 branch
BranchTrueFalseTotal
if @DBI::Shell::FindSqlFile::found 8 0 8
68  
69 0 return;
70 }
71  
72 sub wanted {
73 200 ▶ (/^.*$to_find_file\z/is && print "Found $to_find_file file
Subroutine wanted: called CC=7 SCAR=21.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::Shell::FindSqlFile::debug 0 200 200
Condition16%1/6
$DBI::Shell::FindSqlFile::debug && (/^.*$DBI::Shell::FindSqlFile::to_find_file\z/is && print("Found $DBI::Shell::FindSqlFile::to_find_file file\n\t$DBI::Shell::FindSqlFile::name\n"))
!ll&&!rl&&r
20000
/^.*$DBI::Shell::FindSqlFile::to_find_file\z/is and print "Found $DBI::Shell::FindSqlFile::to_find_file file\n\t$DBI::Shell::FindSqlFile::name\n"
!ll&&!rl&&r
000
MC/DC0%0/3
$DBI::Shell::FindSqlFile::debug && (/^.*$DBI::Shell::FindSqlFile::to_find_file\z/is && print("Found $DBI::Shell::FindSqlFile::to_find_file file\n\t$DBI::Shell::FindSqlFile::name\n"))
$DBI::Shell::FindSqlFile::debug /^.*$DBI::Shell::FindSqlFile::to_find_file\z/is print "Found $DBI::Shell::FindSqlFile::to_find_file file\n\t$DBI::Shell::FindSqlFile::name\n"
Truth table0%0/4
A && B and C
A= $DBI::Shell::FindSqlFile::debugB= /^.*$DBI::Shell::FindSqlFile::to_find_file\z/isC= print "Found $DBI::Shell::FindSqlFile::to_find_file file\n\t$DBI::Shell::FindSqlFile::name\n"
ABCresult
0XX0
10X0
1100
1111
74 $name\n" ) if $debug;
75 200 ▶ /^.*$to_find_file\z/is && push @found, $name;
Branch: 1 branch
BranchTrueFalseTotal
/^.*$DBI::Shell::FindSqlFile::to_find_file\z/is and push @DBI::Shell::FindSqlFile::found, $DBI::Shell::FindSqlFile::name 8 192 200
76 200 ▶ $prune = 1 if ( -d $dir and -d $name and $dir ne $name );
Branch: 1 branch
BranchTrueFalseTotal
if -d $DBI::Shell::FindSqlFile::dir and -d $DBI::Shell::FindSqlFile::name and $DBI::Shell::FindSqlFile::dir ne $DBI::Shell::FindSqlFile::name 40 160 200
Condition83%5/6
-d $DBI::Shell::FindSqlFile::dir and -d $DBI::Shell::FindSqlFile::name and $DBI::Shell::FindSqlFile::dir ne $DBI::Shell::FindSqlFile::name
!ll&&!rl&&r
152840
-d $DBI::Shell::FindSqlFile::dir and -d $DBI::Shell::FindSqlFile::name
!ll&&!rl&&r
015248
MC/DC66%2/3
-d $DBI::Shell::FindSqlFile::dir and -d $DBI::Shell::FindSqlFile::name and $DBI::Shell::FindSqlFile::dir ne $DBI::Shell::FindSqlFile::name
-d $DBI::Shell::FindSqlFile::dir -d $DBI::Shell::FindSqlFile::name $DBI::Shell::FindSqlFile::dir ne $DBI::Shell::FindSqlFile::name
Truth table75%3/4
A and B and C
A= -d $DBI::Shell::FindSqlFile::dirB= -d $DBI::Shell::FindSqlFile::nameC= $DBI::Shell::FindSqlFile::dir ne $DBI::Shell::FindSqlFile::name
ABCresult
0XX0
10X0
1100
1111
77 }
78  
79 7 1;
80  
81 __END__
« blib/lib/DBI/Shell/Spool.pm ↑ Summary blib/lib/DBI/Shell/Timing.pm »