| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 8 | ▶ | unless ($ext) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $ext = q{.sql}; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | # If a directory is defined, return to caller | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | ▶ | if ($dir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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"))
/^.*$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"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | $name\n" ) if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 200 | ▶ | /^.*$to_find_file\z/is && push @found, $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 200 | ▶ | $prune = 1 if ( -d $dir and -d $name and $dir ne $name ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
-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 and -d $DBI::Shell::FindSqlFile::name
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
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||||||||||||||||||||||