Dunce
view release on metacpan or search on metacpan
lib/Dunce/Files.pm view on Meta::CPAN
open() and readdir()) that filehandle will complain if its never
closed, or if its never used.
This module is useful for automated code auditing. Its also useful as
a dunce cap to place on junior programmers, make sure they're not
making silly mistakes.
The list of overridden functions is:
chdir
chmod
chop
chown
chroot
dbmopen
flock
link
mkdir
open
opendir
read
lib/Dunce/Files.pm view on Meta::CPAN
truncate
unlink
write
=cut
# Commonly abused file functions.
use vars qw(@File_Functions);
@File_Functions= qw(
chdir
chmod
chown
chroot
dbmopen
flock
link
mkdir
open
opendir
read
rename
lib/Dunce/Files.pm view on Meta::CPAN
);
}
=pod
A few functions have some additional warnings:
=over 4
=item B<chmod>
Often, people will gratuitiously grant files more permissions than
they really need causing unnecessary security problems. Making
non-program files executable is a common mistake. Unnecessarily
giving world write permission is another. Dunce::Files will throw a
warning if either is detected.
I<Note: It may be worthwhile to split this out into a seperate module>
=cut
override('chmod',
sub {
my $mode = $_[0];
carp "Don't make files executable without a good reason"
if $mode & 0111;
carp "Don't make files writable by others without a good reason"
if $mode & 0003;
my $wantarray = (caller(1))[5];
carp "You didn't check if chmod() succeeded"
unless defined $wantarray;
}
);
=pod
=item B<chop>
chop() works a little differently. Using it in void context is fine,
but if it looks like you're using it to strip newlines it will throw a
lib/Dunce/Files.pm view on Meta::CPAN
=cut
override('dbmopen',
sub {
my $hash = $_[0];
carp "Hash given to dbmopen() already contains data"
if keys %$hash;
my $wantarray = (caller(1))[5];
carp "You didn't check if chmod() succeeded"
unless defined $wantarray;
}
);
=pod
=item B<open>
I<NOT YET IMPLEMENTED>
eval {
local $SIG{__WARN__} = sub { die @_ };
open(FILE, 't/Files.t') || die $!;
1;
};
is( $@, '' );
my $Buh;
eval {
local $SIG{__WARN__} = sub { die @_ };
chmod(0755, 'moo') || do_nothing();
1;
};
like( $@, qr/^Don't make files/, 'chmod' );
#'#
my %hash = (foo => 'bar');
eval {
local $SIG{__WARN__} = sub { die @_ };
dbmopen(%hash, "testingdb", 0644) || do_nothing;
1;
};
like( $@, qr/^Hash given to dbmopen\(\) already contains data/, 'dbmopen' );
( run in 0.302 second using v1.01-cache-2.11-cpan-8d75d55dd25 )