| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
############################################################################### |
|
2
|
|
|
|
|
|
|
# Purpose : Hide site-dependent FS policies beneath a well-known interface |
|
3
|
|
|
|
|
|
|
# Author : John Alden |
|
4
|
|
|
|
|
|
|
# Created : March 2005 |
|
5
|
|
|
|
|
|
|
# CVS : $Id: WithinPolicy.pm,v 1.4 2005/06/15 10:40:21 simonf Exp $ |
|
6
|
|
|
|
|
|
|
############################################################################### |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package File::Slurp::WithinPolicy; |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
577
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
37
|
|
|
11
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
51
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use Exporter; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
31
|
|
|
13
|
1
|
|
|
1
|
|
7
|
use Fcntl ':flock'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
103
|
|
|
14
|
1
|
|
|
1
|
|
903
|
use File::Slurp(); |
|
|
1
|
|
|
|
|
43208
|
|
|
|
1
|
|
|
|
|
22
|
|
|
15
|
1
|
|
|
1
|
|
10
|
use File::Policy; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
9
|
|
|
16
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @EXPORT_OK %EXPORT_TAGS @ISA); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
306
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
19
|
|
|
|
|
|
|
@EXPORT_OK = qw(read_file write_file append_file overwrite_file read_dir); |
|
20
|
|
|
|
|
|
|
%EXPORT_TAGS = ('all' => \@EXPORT_OK); |
|
21
|
|
|
|
|
|
|
$VERSION = sprintf"%d.%03d", q$Revision: 1.4 $ =~ /: (\d+)\.(\d+)/; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub read_file { |
|
24
|
8
|
|
|
8
|
0
|
24253
|
File::Policy::check_safe( $_[0], 'r' ); |
|
25
|
8
|
|
|
|
|
41
|
goto &File::Slurp::read_file; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub write_file { |
|
29
|
4
|
|
|
4
|
0
|
1258
|
File::Policy::check_safe( $_[0], 'w' ); |
|
30
|
4
|
|
|
|
|
14
|
goto &File::Slurp::write_file; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub append_file { |
|
34
|
20
|
|
|
20
|
0
|
1003407
|
File::Policy::check_safe( $_[0], 'w' ); |
|
35
|
20
|
|
|
|
|
64
|
goto &File::Slurp::append_file; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub overwrite_file { |
|
39
|
1
|
|
|
1
|
0
|
5688
|
File::Policy::check_safe( $_[0], 'w' ); |
|
40
|
1
|
|
|
|
|
19
|
goto &File::Slurp::overwrite_file; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub read_dir { |
|
44
|
1
|
|
|
1
|
0
|
313
|
File::Policy::check_safe( $_[0], 'r' ); |
|
45
|
1
|
|
|
|
|
9
|
goto &File::Slurp::read_dir; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 NAME |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
File::Slurp::WithinPolicy - Applies filesystem policies to File::Slurp |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
use File::Slurp::WithinPolicy qw(:all); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $text = read_file( 'filename' ); |
|
59
|
|
|
|
|
|
|
my @lines = read_file( 'filename' ); |
|
60
|
|
|
|
|
|
|
write_file( 'filename', $text ); |
|
61
|
|
|
|
|
|
|
append_file( 'filename', $more_text ); |
|
62
|
|
|
|
|
|
|
overwrite_file( 'filename', $text ); |
|
63
|
|
|
|
|
|
|
my @files = read_dir( '/path/to/dir' ); |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This provides the File::Slurp interface within a policy defined by File::Policy. |
|
68
|
|
|
|
|
|
|
By default, File::Policy is a no-op and this behaves identically to File::Slurp. |
|
69
|
|
|
|
|
|
|
System administrators may want to override the default File::Policy implementation to enforce a local filesystem policy |
|
70
|
|
|
|
|
|
|
(see L). |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 read_dir |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
See L |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 read_file |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
See L |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 write_file |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
See L |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 append_file |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
See L |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 overwrite_file |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
See L |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 EXPORTS |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
By default, nothing is exported. |
|
97
|
|
|
|
|
|
|
The C<:all> tag can be used to export everything. |
|
98
|
|
|
|
|
|
|
Individual methods can also be exported. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
L, L |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 VERSION |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$Revision: 1.4 $ on $Date: 2005/06/15 10:40:21 $ by $Author: simonf $ |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 AUTHOR |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
John Alden |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
(c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL. |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |