Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (39 sloc) 917 Bytes
#! nqp
IO Methods and Functions
=begin item open
Open file.
=end item
sub open($filename, :$r, :$w, :$a, :$bin) {
my $mode := $w ?? 'w' !! ($a ?? 'wa' !! 'r');
my $handle := pir::new__Ps('FileHandle');
$$filename, $mode);
$handle.encoding($bin ?? 'binary' !! 'utf8');
=begin item close
Close handle
=end item
sub close($handle) {
=begin item slurp
Returns the contents of C<$filename> as a single string.
=end item
our sub slurp ($filename) {
my $handle := open($filename, :r);
my $contents := $handle.readall;
=begin item spew
Write the string value of C<$contents> to C<$filename>.
=end item
our sub spew($filename, $contents) {
my $handle := pir::new__Ps('FileHandle');
$$filename, 'w');
# vim: ft=perl6
Something went wrong with that request. Please try again.