Policy/Default.pm

filter: Statementstmt 100% 22 / 22 Branchbran 50.0% 1 / 2 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 78.7% 37 / 47 CC 5 SCAR 7.3
CC
5
Cov
84%
check_safe
3.1
get_temp_dir
2.5
get_log_dir
2.1
CRAP 2.1
« Policy.pm ↑ Summary Slurp/WithinPolicy.pm »
1 ###############################################################################
2 # Purpose : Default (unrestricted) File I/O policies
3 # Author : John Alden
4 # Created : March 2005
5 # CVS : $Id: Default.pm,v 1.6 2005/05/18 15:57:28 johna Exp $
6 ###############################################################################
7  
8 package File::Policy::Default;
9  
10 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use File::Spec::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use vars qw($VERSION @EXPORT_OK %EXPORT_TAGS @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 @ISA = qw(Exporter);
16 3 @EXPORT_OK = qw(get_temp_dir get_log_dir check_safe);
17 3 %EXPORT_TAGS = ('all' => \@EXPORT_OK);
18 3 $VERSION = sprintf"%d.%03d", q$Revision: 1.6 $ =~ /: (\d+)\.(\d+)/;
19  
20 1 ▶sub get_temp_dir {
Subroutine get_temp_dir: called CC=2 SCAR=9.2
Pod documented
21 1 ▶ return $ENV{TEMP} || File::Spec::Functions::tmpdir();
Condition33%1/3
$ENV{'TEMP'} || File::Spec::Functions::tmpdir()
l!l&&r!l&&!r
100
MC/DC0%0/2
$ENV{'TEMP'} || File::Spec::Functions::tmpdir()
$ENV{'TEMP'} File::Spec::Functions::tmpdir()
Truth table33%1/3
A || B
A= $ENV{'TEMP'}B= File::Spec::Functions::tmpdir()
ABresult
1X1
011
000
22 }
23  
24 1 ▶sub get_log_dir {
Subroutine get_log_dir: called CC=2 SCAR=7.6
Pod documented
25 1 ▶ return $ENV{LOGDIR} || File::Spec::Functions::curdir();
Condition50%1/2
$ENV{'LOGDIR'} || '.'
l!l
10
MC/DC0%0/1
$ENV{'LOGDIR'} || '.'
$ENV{'LOGDIR'}
Truth table50%1/2
A
A= $ENV{'LOGDIR'}
Aresult
11
00
26 }
27  
28 35 ▶sub check_safe {
Subroutine check_safe: called CC=3 SCAR=11.4
Pod documented
29 35 my ($name, $mode) = @_;
30 35 ▶ croak("mode must be r or w") unless($mode eq 'r' || $mode eq 'w');
Branch: 1 branch
BranchTrueFalseTotal
unless $mode eq "r" or $mode eq "w" 0 35 35
Condition66%2/3
$mode eq "r" or $mode eq "w"
l!l&&r!l&&!r
10250
MC/DC0%0/2
$mode eq "r" or $mode eq "w"
$mode eq "r" $mode eq "w"
Truth table66%2/3
A or B
A= $mode eq "r"B= $mode eq "w"
ABresult
1X1
011
000
31 35 return 1;
32 }
33  
34 3 1;
35  
36 =head1 NAME
37  
38 File::Policy::Default - Default policy for file I/O functions
39  
40 =head1 SYNOPSIS
41  
42 use File::Policy;
43 use File::Policy qw/check_safe/; # to import a specific subroutine
44 use File::Policy qw/:all/; # to import all subroutines
45  
46 #Checking I/O policy
47 check_safe($filename, 'r');
48 check_safe($filename, 'w');
49  
50 #Portable directory locations
51 $logdir = get_log_dir();
52 $tmpdir = get_temp_dir();
53  
54 =head1 DESCRIPTION
55  
56 This defines the default (unrestricted) policy for file I/O with modules such as File::Slurp::WithinPolicy.
57 You may replace this default policy with one for your organisation.
58  
59 =head1 FUNCTIONS
60  
61 =over 4
62  
63 =item check_safe
64  
65 check_safe( FILENAME , MODE );
66  
67 Checks a filename is safe - dies if not. MODE is r (read) or w (write).
68 Default is no restrictions on file I/O.
69  
70 =item get_temp_dir
71  
72 $temporary_directory = get_temp_dir();
73  
74 Returns the path to temporary directory from the TEMP environment variable or File::Spec::Functions::tmpdir().
75 Note that any return value will have been cleared of a trailing slash.
76  
77 =item get_log_dir
78  
79 $log_directory = get_log_dir();
80  
81 Returns the path to log directory from the LOGDIR environment variable or the current directory.
82 Note that any return value will have been cleared of a trailing slash.
83  
84 =back
85  
86 =head1 VERSION
87  
88 $Revision: 1.6 $ on $Date: 2005/05/18 15:57:28 $ by $Author: johna $
89  
90 =head1 AUTHOR
91  
92 John Alden <cpan _at_ bbc _dot_ co _dot_ uk>
93  
94 =head1 COPYRIGHT
95  
96 (c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL.
97  
98 See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt
99  
100 =cut
« Policy.pm ↑ Summary Slurp/WithinPolicy.pm »