| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # -*- perl -*- | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # | 
| 4 |  |  |  |  |  |  | # $Id: Functions.pm,v 1.3 2004/04/07 16:08:28 eserte Exp $ | 
| 5 |  |  |  |  |  |  | # Author: Slaven Rezic | 
| 6 |  |  |  |  |  |  | # | 
| 7 |  |  |  |  |  |  | # Copyright (C) 2003 Slaven Rezic. All rights reserved. | 
| 8 |  |  |  |  |  |  | # This package is free software; you can redistribute it and/or | 
| 9 |  |  |  |  |  |  | # modify it under the same terms as Perl itself. | 
| 10 |  |  |  |  |  |  | # | 
| 11 |  |  |  |  |  |  | # Mail: slaven@rezic.de | 
| 12 |  |  |  |  |  |  | # WWW:  http://www.rezic.de/eserte/ | 
| 13 |  |  |  |  |  |  | # | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | package WE::Util::Functions; | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 3 |  |  | 3 |  | 14 | use strict; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 105 |  | 
| 18 | 3 |  |  | 3 |  | 15 | use vars qw($VERSION @EXPORT_OK); | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 234 |  | 
| 19 |  |  |  |  |  |  | $VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/); | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 3 |  |  | 3 |  | 13 | use base qw(Exporter); | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 1839 |  | 
| 22 |  |  |  |  |  |  | @EXPORT_OK = qw(is_in_path file_name_is_absolute _save_pwd); | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | # REPO BEGIN | 
| 25 |  |  |  |  |  |  | # REPO NAME is_in_path /home/e/eserte/src/repository | 
| 26 |  |  |  |  |  |  | # REPO MD5 81c0124cc2f424c6acc9713c27b9a484 | 
| 27 |  |  |  |  |  |  | sub is_in_path { | 
| 28 | 0 |  |  | 0 | 0 |  | my($prog) = @_; | 
| 29 | 0 | 0 | 0 |  |  |  | return $prog if (file_name_is_absolute($prog) and -f $prog and -x $prog); | 
|  |  |  | 0 |  |  |  |  | 
| 30 | 0 |  |  |  |  |  | require Config; | 
| 31 | 0 |  | 0 |  |  |  | my $sep = $Config::Config{'path_sep'} || ':'; | 
| 32 | 0 |  |  |  |  |  | foreach (split(/$sep/o, $ENV{PATH})) { | 
| 33 | 0 | 0 |  |  |  |  | if ($^O eq 'MSWin32') { | 
| 34 |  |  |  |  |  |  | # maybe use $ENV{PATHEXT} like maybe_command in ExtUtils/MM_Win32.pm? | 
| 35 | 0 | 0 | 0 |  |  |  | return "$_\\$prog" | 
|  |  |  | 0 |  |  |  |  | 
|  |  |  | 0 |  |  |  |  | 
| 36 |  |  |  |  |  |  | if (-x "$_\\$prog.bat" || | 
| 37 |  |  |  |  |  |  | -x "$_\\$prog.com" || | 
| 38 |  |  |  |  |  |  | -x "$_\\$prog.exe" || | 
| 39 |  |  |  |  |  |  | -x "$_\\$prog.cmd"); | 
| 40 |  |  |  |  |  |  | } else { | 
| 41 | 0 | 0 | 0 |  |  |  | return "$_/$prog" if (-x "$_/$prog" && !-d "$_/$prog"); | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  | } | 
| 44 | 0 |  |  |  |  |  | undef; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  | # REPO END | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | =head2 _save_pwd(sub { ... }) | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | =for category File | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | Save the current directory and assure that outside the block the old | 
| 53 |  |  |  |  |  |  | directory will still be valid. | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | =cut | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | sub _save_pwd (&) { | 
| 58 | 0 |  |  | 0 |  |  | my $code = shift; | 
| 59 | 0 |  |  |  |  |  | require Cwd; | 
| 60 | 0 |  |  |  |  |  | my $pwd = Cwd::cwd(); | 
| 61 | 0 |  |  |  |  |  | eval { | 
| 62 | 0 |  |  |  |  |  | $code->(); | 
| 63 |  |  |  |  |  |  | }; | 
| 64 | 0 |  |  |  |  |  | my $err = $@; | 
| 65 | 0 | 0 |  |  |  |  | chdir $pwd or die "Can't chdir back to $pwd: $!"; | 
| 66 | 0 | 0 |  |  |  |  | die $err if $err; | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | # REPO BEGIN | 
| 70 |  |  |  |  |  |  | # REPO NAME file_name_is_absolute /home/e/eserte/src/repository | 
| 71 |  |  |  |  |  |  | # REPO MD5 89d0fdf16d11771f0f6e82c7d0ebf3a8 | 
| 72 |  |  |  |  |  |  | BEGIN { | 
| 73 | 3 | 50 |  | 3 |  | 7 | if (eval { require File::Spec; defined &File::Spec::file_name_is_absolute }) { | 
|  | 3 |  |  |  |  | 17 |  | 
|  | 3 |  |  |  |  | 19 |  | 
| 74 | 0 |  |  |  |  | 0 | *file_name_is_absolute = \&File::Spec::file_name_is_absolute; | 
| 75 |  |  |  |  |  |  | } else { | 
| 76 |  |  |  |  |  |  | *file_name_is_absolute = sub { | 
| 77 | 0 |  |  | 0 |  |  | my $file = shift; | 
| 78 | 0 |  |  |  |  |  | my $r; | 
| 79 | 0 | 0 |  |  |  |  | if ($^O eq 'MSWin32') { | 
| 80 | 0 |  |  |  |  |  | $r = ($file =~ m;^([a-z]:(/|\\)|\\\\|//);i); | 
| 81 |  |  |  |  |  |  | } else { | 
| 82 | 0 |  |  |  |  |  | $r = ($file =~ m|^/|); | 
| 83 |  |  |  |  |  |  | } | 
| 84 | 0 |  |  |  |  |  | $r; | 
| 85 | 3 |  |  |  |  | 79 | }; | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  | # REPO END | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | 1; | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | __END__ |