File Coverage

blib/lib/IO/Die/chown.pm
Criterion Covered Total %
statement 10 11 90.9
branch 5 6 83.3
condition n/a
subroutine 2 2 100.0
pod 1 1 100.0
total 18 20 90.0


line stmt bran cond sub pod time code
1             package IO::Die;
2              
3 1     1   5 use strict;
  1         2  
  1         140  
4              
5             #NOTE: This will only chown() one thing at a time. It refuses to support
6             #multiple chown() operations within the same call. This is in order to provide
7             #reliable error reporting.
8             #
9             #You, of course, can still do: IO::Die->chown() for @items;
10             #
11             sub chown {
12 5     5 1 1647 my ( $NS, $uid, $gid, $target, @too_many_args ) = @_;
13              
14             #This is here because it’s impossible to do reliable error-checking when
15             #you operate on >1 filesystem node at once.
16 5 100       25 die "Only one path at a time!" if @too_many_args;
17              
18 4         17 local ( $!, $^E );
19              
20 4 100       102 my $ok = CORE::chown( $uid, $gid, $target ) or do {
21 2 50       7 if ( __is_a_fh($target) ) {
22 0         0 $NS->__THROW( 'Chown', uid => $uid, gid => $gid );
23             }
24              
25 2         9 $NS->__THROW( 'Chown', uid => $uid, gid => $gid, path => $target );
26             };
27              
28 2         10 return $ok;
29             }
30              
31             1;