Perl6-Doc
view release on metacpan or search on metacpan
share/Synopsis/S32-setting-library/IO.pod view on Meta::CPAN
=back
=head2 IO::Pipe
class IO::Pipe does IO::Streamable does IO::Readable does IO::Writable {
...
}
Will need to set IO::Readable.isReadable and IO::Writable.isWriteable depending on opening
method.
=over
=item close()
If the file handle came from a piped open, C<close> will additionally
return C<Failure> (aliased to C<$!>) if one of the other system calls involved fails, or if the
program exits with non-zero status. The exception object will contain any
pertinent information. Closing a pipe
also waits for the process executing on the pipe to complete, in case you
want to look at the output of the pipe afterwards, and
implicitly puts the exit status value into the C<Failure> object if necessary.
=item IO::Pipe.to
method to(Str $command, *%opts --> Bool)
method to(Str *@command, *%opts --> Bool)
Opens a one-way pipe writing to C<$command>. C<IO> redirection for
stderr is specified with C<:err(IO)> or C<< :err<Str> >>. Other C<IO> redirection
is done with feed operators. XXX how to specify "2>&1"?
=item IO::Pipe.from
method from(Str $command, *%opts --> Bool)
method from(Str *@command, *%opts --> Bool)
Opens a one-way pipe reading from $command. C<IO> redirection for
stderr is specified with C<:err(IO)> or C<< :err<Str> >>. Other C<IO> redirection
is done with feed operators. XXX how to specify "2>&1"?
=item IO::Pipe.pair
method pair(--> List of IO::Pipe)
A wrapper for I<pipe(2)>, returns a pair of C<IO> objects representing the
reader and writer ends of the pipe.
($r, $w) = IO::Pipe.pair;
=back
=head1 OS-specific classes
=head2 Unix
=head2 Path::Unix
=over
=item chown
multi chown ($uid = -1, $gid = -1, *@files --> Int)
Changes the owner (and group) of a list of files. The first
two elements of the list must be the numeric uid and gid, in
that order. A value of -1 in either position is interpreted by
most systems to leave that value unchanged. Returns the number
of files successfully changed.
$count = chown $uid, $gid, 'foo', 'bar';
chown $uid, $gid, @filenames;
On systems that support C<fchown>, you might pass file handles
among the files. On systems that don't support C<fchown>, passing
file handles produces a fatal error at run time.
Here's an example that looks up nonnumeric uids in the passwd
file:
$user = prompt "User: ";
$pattern = prompt "Files: ";
($login,$pass,$uid,$gid) = getpwnam($user)
or die "$user not in passwd file";
@ary = glob($pattern); # expand filenames
chown $uid, $gid, @ary;
On most systems, you are not allowed to change the ownership of
the file unless you're the superuser, although you should be
able to change the group to any of your secondary groups. On
insecure systems, these restrictions may be relaxed, but this
is not a portable assumption. On POSIX systems, you can detect
this condition this way:
use POSIX qw(sysconf _PC_CHOWN_RESTRICTED);
$can-chown-giveaway = not sysconf(_PC_CHOWN_RESTRICTED);
=item chmod LIST
X<chmod> X<permission> X<mode>
Changes the permissions of a list of files. The first element of the
list must be the numerical mode, which should probably be an octal
number, and which definitely should I<not> be a string of octal digits:
C<0o644> is okay, C<0644> is not. Returns the number of files
successfully changed.
$count = chmod 0o755, 'foo', 'bar';
chmod 0o755, @executables;
$mode = '0644'; chmod $mode, 'foo'; # !!! sets mode to --w----r-T
$mode = '0o644'; chmod $mode, 'foo'; # this is better
$mode = 0o644; chmod $mode, 'foo'; # this is best
=item stat
=item IO.stat
$node.stat(Bool :$link); # :link does an lstat instead
Returns a stat buffer. If the lstat succeeds, the stat buffer evaluates
to true, and additional file tests may be performed on the value. If
the stat fails, all subsequent tests on the stat buffer also evaluate
to false.
=back
=head2 IO::Socket::Unix
role IO::Socket::Unix does IO::Socket {
has Str $.RemoteAddr, # Remote Address
has Str $.LocalAddr, # Local Address
}
=over
=item new
method new(
Str :$RemoteAddr,
Str :$LocalAddr,
Bool :$Listener, # Passed to IO::Socket.new()
Bool :$Blocking, # Passed to IO::Streamable.new()
Bool :$NoOpen, # Passed to IO::Streamable.new()
--> IO::Socket::Unix
) {...}
=item pair
method pair(Int $domain, Int $type, Int $protocol --> List of IO)
A wrapper for I<socketpair(2)>, returns a pair of C<IO> objects representing the
reader and writer ends of the socket.
use IO::Socket;
( run in 0.513 second using v1.01-cache-2.11-cpan-5511b514fd6 )