lib/Microarray/Utilities/Filesystem.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 45 CC 7 SCAR 31.2
CC
7
Cov
0%
DirectoryIsValid
42.0
EnsureTrailingSlash
6.0
BEGIN
2.0
CRAP 22.7
1 package Microarray::Utilities::Filesystem;
2  
3 use strict;
4 use File::Basename;
5  
6  
7 use vars qw (@ISA @EXPORT_OK);
8 use Exporter;
9 @ISA = ('Exporter');
10 @EXPORT_OK = qw( DirectoryIsValid EnsureTrailingSlash);
11  
12 # License information (the MIT license)
13  
14 # Copyright (c) 2003 Christian Rees, Janos Demeter, John Matese, Gavin
15 # Sherlock; Stanford University
16  
17 # Permission is hereby granted, free of charge, to any person
18 # obtaining a copy of this software and associated documentation files
19 # (the "Software"), to deal in the Software without restriction,
20 # including without limitation the rights to use, copy, modify, merge,
21 # publish, distribute, sublicense, and/or sell copies of the Software,
22 # and to permit persons to whom the Software is furnished to do so,
23 # subject to the following conditions:
24  
25 # The above copyright notice and this permission notice shall be
26 # included in all copies or substantial portions of the Software.
27  
28 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
32 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
33 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 # SOFTWARE.
36  
37  
38 ###############################################################################
39 sub DirectoryIsValid {
40 ###############################################################################
41 # this subroutine takes a single argument, a directory path, and
42 # simply returns it if it passes that validation rules below
43  
44 my $dir = shift;
45  
46 return(0) unless (-d $dir); # Fail (Skip) everything but directories that are
47 return(0) unless (-r $dir); # readable and
48 return(0) unless (-x $dir); # executable.
49 return(0) if $dir =~ m/RCS/; # skip RCS directories
50 return(0) if $dir =~ m/CVS/; # skip CVS directories
51  
52 return 1; # return the directory name, validated as true
53  
54 }
55  
56  
57 ###############################################################################
58 sub EnsureTrailingSlash {
59 ###############################################################################
60 # this subroutine takes a single argument, a string represent a file
61 # path, and simply ensures that is has a trailing slash (adds it if
62 # necessary)
63  
64 my $path = shift;
65  
66 if ($path !~ /\/$/){
67  
68 $path .= '/';
69  
70 }
71  
72 return $path; # return the filepath
73  
74 }
75  
76  
77 1; # to make perl happy