| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 8 | ▶ | unless ($ext) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $ext = q{.sql}; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # If a directory is defined, return to caller | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 8 | ▶ | if ($dir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | $name\n" ) if $debug; | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 200 | ▶ | /^.*$to_find_file\z/is && push @found, $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||||||||||||||||||||||||