blib/lib/DBI/Shell/FindSqlFile.pm

filter: Statementstmt 93.0% 40 / 43 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 75.0% 69 / 92 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/Format.pm ↑ Summary blib/lib/DBI/Shell/Timing.pm »
1 #!/usr/local/bin/perl
2  
3 package DBI::Shell::FindSqlFile;
4  
5 7 our $VERSION = '11.98'; # VERSION
6  
7 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use File::Find ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # Set the variable $File::Find::dont_use_nlink if you're using AFS,
13 # since AFS cheats.
14  
15 # for the convenience of &wanted calls, including -eval statements:
16 7 ▶use vars qw/*name *dir *prune @found $to_find_file $debug/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 *name = *File::Find::name;
18 7 *dir = *File::Find::dir;
19 7 *prune = *File::Find::prune;
20  
21 7 @found = ();
22 7 $to_find_file = undef;
23 7 $debug = 0;
24  
25 8 ▶sub look_for_file {
Subroutine look_for_file: called CC=9 SCAR=24.2
Pod undocumented
26 8 my $self = shift;
27 8 my $file = shift;
28 8 my ($base, $dir, $ext) = fileparse($file,'\..*?');
29  
30 8 $debug = $self->{debug};
31  
32 # print "file $file : concat $dir$base$ext\n";
33  
34 # Work-around to fileparse adding current directory.
35 8 ▶ $dir = undef unless ( $file eq "$dir$base$ext" );
Branch: 1 branch
BranchTrueFalseTotal
unless $file eq "$dir$base$ext" 8 0 8
36  
37 8 ▶ unless ($ext) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ext) 0 8 8
38 0 $ext = q{.sql};
39 }
40 # If a directory is defined, return to caller
41 8 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) 0 8 8
42 0 return ( "$dir$base$ext" );
43 };
44  
45 8 $to_find_file = qq{$base$ext};
46  
47 8 ▶ $self->log("calling find with $to_find_file") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 8 8
48  
49  
50 # Split the sqlpath, then determine if any of the directories are valid.
51 14 ▶ my @search_path = map { -d $_ ? $_ : () } split(/:/,
Branch: 2 branches
BranchTrueFalseTotal
-d $_ ? : 8 6 14
defined $self->{'sqlpath'} ? : 8 0 8
52 defined $self->{sqlpath} ? $self->{sqlpath} : ()
53 8 );
54 # , (exists $ENV{DBISH_SQL_PATH} ? $ENV{DBISH_SQL_PATH} : ()) );
55  
56 $self->log( "search path: " . join( "\n", @search_path ) )
57 8 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 8 8
58  
59 # Traverse desired filesystems
60 8 File::Find::find(
61 {
62 wanted => \&wanted
63 , no_chdir => 1
64 , bydepth => 0
65 },
66 @search_path);
67  
68  
69 8 ▶ return shift @found if @found;
Branch: 1 branch
BranchTrueFalseTotal
if @DBI::Shell::FindSqlFile::found 8 0 8
70  
71 0 return;
72 }
73  
74 200 ▶sub wanted {
Subroutine wanted: called CC=7 SCAR=21.8
Pod undocumented
75 200 ▶ (/^.*$to_find_file\z/is && print "Found $to_find_file file
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
76 $name\n" ) if $debug;
77 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
78 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
79 }
80  
81 7 1;
82  
83 __END__
« blib/lib/DBI/Format.pm ↑ Summary blib/lib/DBI/Shell/Timing.pm »