mostly done
git-svn-id: svn://127.0.0.1/Perl/File::Permissions::Unix/trunk@487 0c1c3402-1be1-de11-8092-0022686faf23
This commit is contained in:
parent
a4661aeb6b
commit
2fe5a03f1f
|
@ -8,7 +8,7 @@ WriteMakefile(
|
|||
VERSION_FROM => 'lib/File/Permissions/Unix.pm',
|
||||
ABSTRACT_FROM => 'lib/File/Permissions/Unix.pm',
|
||||
($ExtUtils::MakeMaker::VERSION >= 6.3002
|
||||
? ('LICENSE'=> 'perl')
|
||||
? ('LICENSE'=> 'perl')
|
||||
: ()),
|
||||
PL_FILES => {},
|
||||
PREREQ_PM => {
|
||||
|
@ -16,4 +16,4 @@ WriteMakefile(
|
|||
},
|
||||
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
|
||||
clean => { FILES => 'File-Permissions-Unix-*' },
|
||||
);
|
||||
);
|
||||
|
|
|
@ -1,16 +1,7 @@
|
|||
File-Permissions-Unix
|
||||
|
||||
The README is used to introduce the module and provide instructions on
|
||||
how to install the module, any machine dependencies it may have (for
|
||||
example C compilers and installed libraries) and any other information
|
||||
that should be provided before the module is installed.
|
||||
|
||||
A README file is required for CPAN modules since CPAN extracts the README
|
||||
file from a module distribution so that people browsing the archive
|
||||
can use it to get an idea of the module's uses. It is usually a good idea
|
||||
to provide version information here so that people can decide whether
|
||||
fixes for the module are worth downloading.
|
||||
|
||||
Provides a object orient representation of file system
|
||||
permissions.
|
||||
|
||||
INSTALLATION
|
||||
|
||||
|
|
|
@ -2,52 +2,250 @@ package File::Permissions::Unix;
|
|||
|
||||
use warnings;
|
||||
use strict;
|
||||
use base 'Error::Helper';
|
||||
|
||||
=head1 NAME
|
||||
|
||||
File::Permissions::Unix - The great new File::Permissions::Unix!
|
||||
File::Permissions::Unix - A simple object oriented interface to handling file permissions.
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
Version 0.01
|
||||
Version 0.0.0
|
||||
|
||||
=cut
|
||||
|
||||
our $VERSION = '0.01';
|
||||
|
||||
our $VERSION = '0.0.0';
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
Quick summary of what the module does.
|
||||
|
||||
Perhaps a little code snippet.
|
||||
|
||||
use File::Permissions::Unix;
|
||||
|
||||
my $foo=File::Permissions::Unix->new('0640');
|
||||
|
||||
#chmods a /tmp/foo with 0640
|
||||
$foo->chmod('/tmp/foo');
|
||||
|
||||
my $foo = File::Permissions::Unix->new();
|
||||
...
|
||||
#do the same thing as above, but check if it worked
|
||||
$foo->chmod('/tmp/foo');
|
||||
if( $foo->error ){
|
||||
warn('error:'.$foo->error.': '.$foo->errorString);
|
||||
}
|
||||
|
||||
=head1 EXPORT
|
||||
#copies the mode from /tmp/foo to /tmp/bar
|
||||
$foo->setModeFromFile('/tmp/foo');
|
||||
$foo->chmod('/tmp/bar');
|
||||
|
||||
A list of functions that can be exported. You can delete this section
|
||||
if you don't export anything, such as for a purely object-oriented module.
|
||||
#prints the current mode
|
||||
print $foo->getMode."\n";
|
||||
|
||||
=head1 SUBROUTINES/METHODS
|
||||
=head1 METHODS
|
||||
|
||||
=head2 function1
|
||||
=head2 new
|
||||
|
||||
This initiates the object.
|
||||
|
||||
One arguement is accepted. It is the mode
|
||||
to intialize the object with. If not specified
|
||||
it defaults to '0644'.
|
||||
|
||||
my $foo=File::Permissions::Unix->new($mode);
|
||||
if( $foo->error ){
|
||||
warn('error:'.$foo->error.': '.$foo->errorString);
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub function1 {
|
||||
sub new{
|
||||
my $mode=$_[1];
|
||||
|
||||
if ( ! defined( $mode ) ){
|
||||
$mode='0644';
|
||||
}
|
||||
|
||||
my $self={
|
||||
mode=>$mode,
|
||||
perror=>undef,
|
||||
error=>undef,
|
||||
errorString=>'',
|
||||
};
|
||||
|
||||
# make sure it is a valid mode
|
||||
if ( $self->{mode} !~ /^[01246][01234567][01234567][01234567]$/ ){
|
||||
$self->{error}=1;
|
||||
$self->{perror}=1;
|
||||
$self->{errorString}='';
|
||||
return $self;
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
=head2 function2
|
||||
=head2 chmod
|
||||
|
||||
This chmods a file with the current mode.
|
||||
|
||||
One argument is required and it the file/directory/etc in question.
|
||||
|
||||
$foo->chmod($file);
|
||||
if( $foo->error ){
|
||||
warn('error:'.$foo->error.': '.$foo->errorString);
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub function2 {
|
||||
sub chmod{
|
||||
my $self=$_[0];
|
||||
my $file=$_[1];
|
||||
|
||||
$self->errorblank;
|
||||
if ( $self->error ){
|
||||
return undef;
|
||||
}
|
||||
|
||||
#make sure the file is defined
|
||||
if( ! defined( $file ) ){
|
||||
$self->{error}=2;
|
||||
$self->{errorString}='No file specified';
|
||||
return undef;
|
||||
}
|
||||
|
||||
#make sure the item exists
|
||||
if ( ! -e $file ){
|
||||
$self->{error}=3;
|
||||
$self->{errorString}='"'.$file.'" does not exist';
|
||||
return undef;
|
||||
}
|
||||
|
||||
#try to chmod the file
|
||||
if( ! chmod( oct($self->{mode}), $file )){
|
||||
$self->{error}=4;
|
||||
$self->{errorString}='Unable to chmod "'.$file.'" with "'.$self->{mode}.'"';
|
||||
return undef;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 getMode
|
||||
|
||||
This returns the current mode.
|
||||
|
||||
my $mode=$foo->getMode;
|
||||
|
||||
=cut
|
||||
|
||||
sub getMode{
|
||||
my $self=$_[0];
|
||||
|
||||
$self->errorblank;
|
||||
if ( $self->error ){
|
||||
return undef;
|
||||
}
|
||||
|
||||
return $self->{mode};
|
||||
}
|
||||
|
||||
=head2 setMode
|
||||
|
||||
This changes the currently set mode.
|
||||
|
||||
One argument is accepted and it is the current mode.
|
||||
|
||||
$foo->setMode('0640')';
|
||||
if($foo->error){
|
||||
warn('error:'.$foo->error.': '.$foo->errorString);
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub setMode{
|
||||
my $self=$_[0];
|
||||
my $mode=$_[1];
|
||||
|
||||
$self->errorblank;
|
||||
if ( $self->error ){
|
||||
return undef;
|
||||
}
|
||||
|
||||
# make sure it is a valid mode
|
||||
if ( $mode !~ /^[01246][01234567][01234567][01234567]$/ ){
|
||||
$self->{error}=1;
|
||||
$self->{errorString}='';
|
||||
return $self;
|
||||
}
|
||||
|
||||
$self->{mode}=$mode;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 setModeFromFile
|
||||
|
||||
This sets the current mode from a file.
|
||||
|
||||
One argument is required and it the file/directory/etc in question.
|
||||
|
||||
$foo->setModeFromFile($file);
|
||||
if( $foo->error ){
|
||||
warn('error:'.$foo->error.': '.$foo->errorString);
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub setModeFromFile{
|
||||
my $self=$_[0];
|
||||
my $file=$_[1];
|
||||
|
||||
$self->errorblank;
|
||||
if ( $self->error ){
|
||||
return undef;
|
||||
}
|
||||
|
||||
#make sure the file is defined
|
||||
if( ! defined( $file ) ){
|
||||
$self->{error}=2;
|
||||
$self->{errorString}='No file specified';
|
||||
return undef;
|
||||
}
|
||||
|
||||
#make sure the item exists
|
||||
if ( ! -e $file ){
|
||||
$self->{error}=3;
|
||||
$self->{errorString}='"'.$file.'" does not exist';
|
||||
return undef;
|
||||
}
|
||||
|
||||
#stat the file and get it
|
||||
my $mode = (stat($file))[2] & 07777;
|
||||
$mode=sprintf("%04o", $mode);
|
||||
|
||||
$self->{mode}=$mode;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head1 ERROR CODES
|
||||
|
||||
=head2 1
|
||||
|
||||
Invalid mode.
|
||||
|
||||
This means it did not match the regexp below.
|
||||
|
||||
/^[01246][01234567][01234567][01234567]$/
|
||||
|
||||
=head2 2
|
||||
|
||||
No file specified.
|
||||
|
||||
=head2 3
|
||||
|
||||
The file does not exist.
|
||||
|
||||
=head2 4
|
||||
|
||||
Failed to chmod the file.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
|
||||
|
|
Loading…
Reference in New Issue