| 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 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use vars qw($VERSION @EXPORT_OK); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | $VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | @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 | 0 | ▶ | sub is_in_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_in_path: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my($prog) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | return $prog if (file_name_is_absolute($prog) and -f $prog and -x $prog); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
file_name_is_absolute($prog) and -f $prog and -x $prog
file_name_is_absolute($prog) and -f $prog
MC/DC0%0/3
file_name_is_absolute($prog) and -f $prog and -x $prog
file_name_is_absolute($prog)
-f $prog
-x $prog
Truth table0%0/4
A and B and C
A= file_name_is_absolute($prog)B= -f $progC= -x $prog
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | require Config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my $sep = $Config::Config{'path_sep'} || ':'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$Config::Config{'path_sep'} || ':'
MC/DC0%0/1
$Config::Config{'path_sep'} || ':'
$Config::Config{'path_sep'}
Truth table0%0/2
A
A= $Config::Config{'path_sep'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | foreach (split(/$sep/o, $ENV{PATH})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($^O eq 'MSWin32') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # maybe use $ENV{PATHEXT} like maybe_command in ExtUtils/MM_Win32.pm? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | return "$_\\$prog" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
-x "$_\\$prog.bat" or -x "$_\\$prog.com" or -x "$_\\$prog.exe" or -x "$_\\$prog.cmd"
-x "$_\\$prog.bat" or -x "$_\\$prog.com" or -x "$_\\$prog.exe"
-x "$_\\$prog.bat" or -x "$_\\$prog.com"
MC/DC0%0/4
-x "$_\\$prog.bat" or -x "$_\\$prog.com" or -x "$_\\$prog.exe" or -x "$_\\$prog.cmd"
-x "$_\\$prog.bat"
-x "$_\\$prog.com"
-x "$_\\$prog.exe"
-x "$_\\$prog.cmd"
Truth table0%0/5
A or B or C or D
A= -x "$_\\$prog.bat"B= -x "$_\\$prog.com"C= -x "$_\\$prog.exe"D= -x "$_\\$prog.cmd"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | if (-x "$_\\$prog.bat" || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | -x "$_\\$prog.com" || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | -x "$_\\$prog.exe" || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | -x "$_\\$prog.cmd"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | return "$_/$prog" if (-x "$_/$prog" && !-d "$_/$prog"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-x "$_/$prog" and not -d "$_/$prog"
MC/DC0%0/2
-x "$_/$prog" and not -d "$_/$prog"
-x "$_/$prog"
not -d "$_/$prog"
Truth table0%0/3
A and not(B)
A= -x "$_/$prog"B= not -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 | 0 | ▶ | sub _save_pwd (&) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_save_pwd: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 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 | ▶ | chdir $pwd or die "Can't chdir back to $pwd: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | die $err if $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # REPO BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # REPO NAME file_name_is_absolute /home/e/eserte/src/repository | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # REPO MD5 89d0fdf16d11771f0f6e82c7d0ebf3a8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | if (eval { require File::Spec; defined &File::Spec::file_name_is_absolute }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | *file_name_is_absolute = \&File::Spec::file_name_is_absolute; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | *file_name_is_absolute = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ($^O eq 'MSWin32') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $r = ($file =~ m;^([a-z]:(/|\\)|\\\\|//);i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $r = ($file =~ m|^/|); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # REPO END | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||