Unicos hint tweak.
[p5sagit/p5-mst-13.2.git] / lib / filetest.pm
CommitLineData
5ff3f7a4 1package filetest;
2
3=head1 NAME
4
5filetest - Perl pragma to control the filetest permission operators
6
7=head1 SYNOPSIS
3cb6de81 8
5ff3f7a4 9 $can_perhaps_read = -r "file"; # use the mode bits
10 {
11 use filetest 'access'; # intuit harder
12 $can_really_read = -r "file";
13 }
14 $can_perhaps_read = -r "file"; # use the mode bits again
15
16=head1 DESCRIPTION
17
18This pragma tells the compiler to change the behaviour of the filetest
80d06f2d 19permissions operators, the C<-r> C<-w> C<-x> C<-R> C<-W> C<-X>
20(see L<perlfunc>).
5ff3f7a4 21
22The default behaviour to use the mode bits as returned by the stat()
23family of calls. This, however, may not be the right thing to do if
24for example various ACL (access control lists) schemes are in use.
25For such environments, C<use filetest> may help the permission
26operators to return results more consistent with other tools.
27
28Each "use filetest" or "no filetest" affects statements to the end of
29the enclosing block.
30
31There may be a slight performance decrease in the filetests
32when C<use filetest> is in effect, because in some systems
33the extended functionality needs to be emulated.
34
6ca796d8 35B<NOTE>: using the file tests for security purposes is a lost cause
80d06f2d 36from the start: there is a window open for race conditions (who is to
37say that the permissions will not change between the test and the real
38operation?). Therefore if you are serious about security, just try
39the real operation and test for its success. Think atomicity.
5ff3f7a4 40
41=head2 subpragma access
42
43Currently only one subpragma, C<access> is implemented. It enables
44(or disables) the use of access() or similar system calls. This
45extended filetest functionality is used only when the argument of the
46operators is a filename, not when it is a filehandle.
47
48=cut
49
d5448623 50$filetest::hint_bits = 0x00400000;
51
5ff3f7a4 52sub import {
53 if ( $_[1] eq 'access' ) {
d5448623 54 $^H |= $filetest::hint_bits;
5ff3f7a4 55 } else {
56 die "filetest: the only implemented subpragma is 'access'.\n";
57 }
58}
59
60sub unimport {
61 if ( $_[1] eq 'access' ) {
d5448623 62 $^H &= ~$filetest::hint_bits;
5ff3f7a4 63 } else {
64 die "filetest: the only implemented subpragma is 'access'.\n";
65 }
66}
67
681;