| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #!/usr/local/bin/perl | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | package DBI::Shell::FindSqlFile; | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | our $VERSION = '11.96_03'; # TRIAL VERSION | 
| 6 |  |  |  |  |  |  | $VERSION = eval $VERSION; | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 7 |  |  | 7 |  | 51 | use strict; | 
|  | 7 |  |  |  |  | 15 |  | 
|  | 7 |  |  |  |  | 234 |  | 
| 9 | 7 |  |  | 7 |  | 37 | use File::Find (); | 
|  | 7 |  |  |  |  | 15 |  | 
|  | 7 |  |  |  |  | 113 |  | 
| 10 | 7 |  |  | 7 |  | 39 | use File::Basename; | 
|  | 7 |  |  |  |  | 15 |  | 
|  | 7 |  |  |  |  | 872 |  | 
| 11 | 7 |  |  | 7 |  | 50 | use File::Spec; | 
|  | 7 |  |  |  |  | 15 |  | 
|  | 7 |  |  |  |  | 206 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | # Set the variable $File::Find::dont_use_nlink if you're using AFS, | 
| 14 |  |  |  |  |  |  | # since AFS cheats. | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | # for the convenience of &wanted calls, including -eval statements: | 
| 17 | 7 |  |  | 7 |  | 44 | use vars qw/*name *dir *prune @found $to_find_file $debug/; | 
|  | 7 |  |  |  |  | 12 |  | 
|  | 7 |  |  |  |  | 3668 |  | 
| 18 |  |  |  |  |  |  | *name   = *File::Find::name; | 
| 19 |  |  |  |  |  |  | *dir    = *File::Find::dir; | 
| 20 |  |  |  |  |  |  | *prune  = *File::Find::prune; | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | @found = (); | 
| 23 |  |  |  |  |  |  | $to_find_file = undef; | 
| 24 |  |  |  |  |  |  | $debug = 0; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub look_for_file { | 
| 27 | 8 |  |  | 8 | 0 | 23 | my $self = shift; | 
| 28 | 8 |  |  |  |  | 20 | my $file = shift; | 
| 29 | 8 |  |  |  |  | 508 | my ($base, $dir, $ext) = fileparse($file,'\..*?'); | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 8 |  |  |  |  | 40 | $debug = $self->{debug}; | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | # print "file $file : concat $dir$base$ext\n"; | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | # Work-around to fileparse adding current directory. | 
| 36 | 8 | 50 |  |  |  | 40 | $dir = undef unless ( $file eq "$dir$base$ext" ); | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 8 | 50 |  |  |  | 25 | unless ($ext) { | 
| 39 | 0 |  |  |  |  | 0 | $ext = q{.sql}; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  | # If a directory is defined, return to caller | 
| 42 | 8 | 50 |  |  |  | 27 | if ($dir) { | 
| 43 | 0 |  |  |  |  | 0 | return ( "$dir$base$ext" ); | 
| 44 |  |  |  |  |  |  | }; | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 8 |  |  |  |  | 25 | $to_find_file = qq{$base$ext}; | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 8 | 50 |  |  |  | 37 | $self->log("calling find with $to_find_file") if $self->{debug}; | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | # Split the sqlpath, then determine if any of the directories are valid. | 
| 52 | 14 | 100 |  |  |  | 317 | my @search_path = map { -d $_ ? $_ : () } split(/:/, | 
| 53 |  |  |  |  |  |  | defined $self->{sqlpath} ? $self->{sqlpath} : () | 
| 54 | 8 | 50 |  |  |  | 73 | ); | 
| 55 |  |  |  |  |  |  | # ,  (exists $ENV{DBISH_SQL_PATH} ?  $ENV{DBISH_SQL_PATH} : ()) ); | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | $self->log( "search path: " . join( "\n", @search_path ) ) | 
| 58 | 8 | 50 |  |  |  | 54 | if $self->{debug}; | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | # Traverse desired filesystems | 
| 61 | 8 |  |  |  |  | 1093 | File::Find::find( | 
| 62 |  |  |  |  |  |  | { | 
| 63 |  |  |  |  |  |  | wanted 	=> \&wanted | 
| 64 |  |  |  |  |  |  | , no_chdir 	=> 1 | 
| 65 |  |  |  |  |  |  | , bydepth	=> 0 | 
| 66 |  |  |  |  |  |  | }, | 
| 67 |  |  |  |  |  |  | @search_path); | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 8 | 50 |  |  |  | 118 | return shift @found if @found; | 
| 71 |  |  |  |  |  |  |  | 
| 72 | 0 |  |  |  |  | 0 | return; | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | sub wanted { | 
| 76 | 208 | 50 | 0 | 208 | 0 | 602 | (/^.*$to_find_file\z/is && print "Found $to_find_file file | 
| 77 |  |  |  |  |  |  | $name\n" ) if $debug; | 
| 78 | 208 | 100 |  |  |  | 874 | /^.*$to_find_file\z/is && push @found, $name; | 
| 79 | 208 | 100 | 66 |  |  | 7938 | $prune = 1 if ( -d $dir and -d $name and $dir ne $name ); | 
|  |  |  | 100 |  |  |  |  | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | 1; | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | __END__ |