File-DataClass
view release on metacpan or search on metacpan
lib/File/DataClass/IO.pm view on Meta::CPAN
$perms //= $self->_perms; # uncoverable condition false
CORE::chmod $perms, $self->name;
return $self;
}
sub chomp {
$_[ 0 ]->_chomp( TRUE ); return $_[ 0 ];
}
sub chown {
my ($self, $uid, $gid) = @_;
(defined $uid and defined $gid)
or $self->$_throw( Unspecified, [ 'user or group id' ] );
1 == CORE::chown $uid, $gid, $self->name
or $self->$_throw( 'Path [_1 chown failed to [_2]/[_3]',
[ $self->name, $uid, $gid ] );
return $self;
}
sub clear {
${ $_[ 0 ]->buffer } = NUL; return $_[ 0 ];
}
sub close {
my $self = shift; $self->is_open or return $self;
lib/File/DataClass/IO.pm view on Meta::CPAN
Changes the permission on the file to the selected value. Permission values
can be either octal or string
=head2 chomp
$io = io( 'path_to_file' )->chomp;
Causes input lines to be chomped when L</getline> or L</getlines> are called
=head2 chown
$io = io( 'path_to_file' )->chown( $uid, $gid );
Changes user and group ownership
=head2 clear
$io->clear
Set the contents of the internal buffer to the null string
=head2 close
};
SKIP: {
is_ntfs and skip 'Unix ownership and permissions not applicable', 1;
subtest 'Ownership' => sub {
$io = io( [ qw( t output print.t ) ] );
my $uid = $io->stat->{uid}; my $gid = $io->stat->{gid};
eval { $io->chown( undef, $gid ) };
like $EVAL_ERROR, qr{ \Qnot specified\E }mx,
'Uid must be defined in chown';
eval { $io->chown( $uid, undef ) };
like $EVAL_ERROR, qr{ \Qnot specified\E }mx,
'Gid must be defined in chown';
is blessed( $io->chown( $uid, $gid ) ), 'File::DataClass::IO', 'Chown';
eval { $io->chown( 65.534, $gid ) };
$EFFECTIVE_USER_ID != 0 and
like $EVAL_ERROR, qr{ \Qchown failed\E }mx, 'Chown failure';
};
subtest 'Permissions' => sub {
$io = io();
ok !$io->is_executable, 'Not executable - no name';
ok !$io->is_link, 'Not a link - no name';
ok !$io->is_readable, 'Not readable - no name';
ok !$io->is_writable, 'Not writable - no name';
$io = io( [ qw( t output print.t ) ] ); $io->print( 'one' );
ok $io->is_readable, 'Readable';
( run in 1.868 second using v1.01-cache-2.11-cpan-5511b514fd6 )