WE/Util/Functions.pm

filter: Statementstmt 40.0% 16 / 40 Branchbran 6.2% 1 / 16 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 1 totaltotal 22.3% 21 / 94 CC 17 SCAR 46.6
CC
17
Cov
22%
is_in_path
182.0
_save_pwd
12.0
__ANON__
6.0
CRAP 105.4
« WebEditor/OldFeatures/Notify.pm ↑ Summary WE/DB/FS.pm »
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
BranchTrueFalseTotal
if file_name_is_absolute($prog) and -f $prog and -x $prog 0 0 0
Condition0%0/6
file_name_is_absolute($prog) and -f $prog and -x $prog
!ll&&!rl&&r
000
file_name_is_absolute($prog) and -f $prog
!ll&&!rl&&r
000
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
ABCresult
0XX0
10X0
1100
1111
30 0 require Config;
31 0 ▶ my $sep = $Config::Config{'path_sep'} || ':';
Condition0%0/2
$Config::Config{'path_sep'} || ':'
l!l
00
MC/DC0%0/1
$Config::Config{'path_sep'} || ':'
$Config::Config{'path_sep'}
Truth table0%0/2
A
A= $Config::Config{'path_sep'}
Aresult
11
00
32 0 foreach (split(/$sep/o, $ENV{PATH})) {
33 0 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
34 # maybe use $ENV{PATHEXT} like maybe_command in ExtUtils/MM_Win32.pm?
35 0 ▶ return "$_\\$prog"
Branch: 1 branch
BranchTrueFalseTotal
if -x "$_\\$prog.bat" or -x "$_\\$prog.com" or -x "$_\\$prog.exe" or -x "$_\\$prog.cmd" 0 0 0
Condition0%0/9
-x "$_\\$prog.bat" or -x "$_\\$prog.com" or -x "$_\\$prog.exe" or -x "$_\\$prog.cmd"
l!l&&r!l&&!r
000
-x "$_\\$prog.bat" or -x "$_\\$prog.com" or -x "$_\\$prog.exe"
l!l&&r!l&&!r
000
-x "$_\\$prog.bat" or -x "$_\\$prog.com"
l!l&&r!l&&!r
000
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"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
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
BranchTrueFalseTotal
if -x "$_/$prog" and not -d "$_/$prog" 0 0 0
Condition0%0/3
-x "$_/$prog" and not -d "$_/$prog"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
chdir $pwd or die "Can't chdir back to ${pwd}: $!" 0 0 0
66 0 ▶ die $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
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
BranchTrueFalseTotal
if (eval { do { require File::Spec; defined &File::Spec::file_name_is_absolute } }) { } 0 1 1
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
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
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__
« WebEditor/OldFeatures/Notify.pm ↑ Summary WE/DB/FS.pm »