Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Removed a bunch of deprecated I/O constructs
  • Loading branch information
hoelzro committed Sep 4, 2015
1 parent 686e9aa commit 03b5a0a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 238 deletions.
143 changes: 32 additions & 111 deletions src/core/IO/Handle.pm
Expand Up @@ -2,42 +2,15 @@ my class IO::Path { ... }
my class IO::Special { ... }
my class Proc { ... }

# Will be removed together with pipe() and open(:p).
my class Proc::Status {
has $.exitcode = -1; # distinguish uninitialized from 0 status
has $.pid;
has $.signal;

method exit {
DEPRECATED('Proc::Status.exitcode', |<2015.03 2015.09>);
$!exitcode;
}

proto method status(|) { * }
multi method status($new_status) {
$!exitcode = $new_status +> 8;
$!signal = $new_status +& 0xFF;
}
multi method status(Proc::Status:D:) { ($!exitcode +< 8) +| $!signal }
multi method Numeric(Proc::Status:D:) { $!exitcode }
multi method Bool(Proc::Status:D:) { $!exitcode == 0 }
}

my class IO::Handle does IO {
has $.path;
has $!PIO;
has int $.ins;
has $.chomp is rw = Bool::True;
has $.nl = "\n";
has int $!pipe;

method pipe(IO::Handle:D: |c) {
DEPRECATED('shell() or run() with :in, :out or :err', |<2015.06 2015.09>);
self.open(:p, :nodepr, |c);
}

method open(IO::Handle:D:
:$p, :$r, :$w, :$x, :$a, :$update,
:$r, :$w, :$x, :$a, :$update,
:$rw, :$rx, :$ra,
:$mode is copy,
:$create is copy,
Expand All @@ -52,8 +25,6 @@ my class IO::Handle does IO {
) {

$mode //= do {
when so $p { 'pipe' }

when so ($r && $w) || $rw { $create = True; 'rw' }
when so ($r && $x) || $rx { $create = $exclusive = True; 'rw' }
when so ($r && $a) || $ra { $create = $append = True; 'rw' }
Expand Down Expand Up @@ -100,68 +71,48 @@ my class IO::Handle does IO {
fail (X::IO::Directory.new(:$!path, :trying<open>))
if $!path.e && $!path.d;

if $mode eq 'pipe' {
DEPRECATED('shell(...)/run(...) with :in, :out or :err', |<2015.06 2015.09>, :what(':p for pipe')) unless $nodepr;
$!pipe = 1;

$!PIO := nqp::syncpipe();
nqp::shell(
nqp::unbox_s($!path.Str),
nqp::unbox_s($*CWD.Str),
CLONE-HASH-DECONTAINERIZED(%*ENV),
nqp::null(), $!PIO, nqp::null(),
nqp::const::PIPE_INHERIT_IN + nqp::const::PIPE_CAPTURE_OUT + nqp::const::PIPE_INHERIT_ERR
);
my $llmode = do given $mode {
when 'ro' { 'r' }
when 'wo' { '-' }
when 'rw' { '+' }
default { die "Unknown mode '$_'" }
}
else {
my $llmode = do given $mode {
when 'ro' { 'r' }
when 'wo' { '-' }
when 'rw' { '+' }
default { die "Unknown mode '$_'" }
}

$llmode = join '', $llmode,
$create ?? 'c' !! '',
$append ?? 'a' !! '',
$truncate ?? 't' !! '',
$exclusive ?? 'x' !! '';
$llmode = join '', $llmode,
$create ?? 'c' !! '',
$append ?? 'a' !! '',
$truncate ?? 't' !! '',
$exclusive ?? 'x' !! '';

#?if !moar
# don't use new modes on anything but MoarVM
# TODO: check what else can be made to work on Parrot
# cf io/utilities.c, Parrot_io_parse_open_flags()
# platform/generic/io.c, convert_flags_to_unix()
# platform/win32/io.c, convert_flags_to_win32 ()
$llmode = do given $llmode {
when 'r' { 'r' }
when '-ct' { 'w' }
when '-ca' { 'wa' }
default {
die "Backend { $*VM.name
} does not support opening files in mode '$llmode'";
}
# don't use new modes on anything but MoarVM
# TODO: check what else can be made to work on Parrot
# cf io/utilities.c, Parrot_io_parse_open_flags()
# platform/generic/io.c, convert_flags_to_unix()
# platform/win32/io.c, convert_flags_to_win32 ()
$llmode = do given $llmode {
when 'r' { 'r' }
when '-ct' { 'w' }
when '-ca' { 'wa' }
default {
die "Backend { $*VM.name
} does not support opening files in mode '$llmode'";
}
}
#?endif

# TODO: catch error, and fail()
$!PIO := nqp::open(
nqp::unbox_s($!path.abspath),
nqp::unbox_s($llmode),
);
}
# TODO: catch error, and fail()
$!PIO := nqp::open(
nqp::unbox_s($!path.abspath),
nqp::unbox_s($llmode),
);

$!chomp = $chomp;
nqp::setinputlinesep($!PIO, nqp::unbox_s($!nl = $nl));
nqp::setencoding($!PIO, NORMALIZE_ENCODING($enc)) unless $bin;
self;
}

method input-line-separator {
DEPRECATED("nl",|<2015.03 2015.09>);
self.nl;
}

method nl is rw {
Proxy.new(
FETCH => {
Expand All @@ -175,17 +126,9 @@ my class IO::Handle does IO {

method close(IO::Handle:D:) {
# TODO:b catch errors
if $!pipe {
my $ps = Proc::Status.new;
$ps.status( nqp::closefh_i($!PIO) ) if nqp::defined($!PIO);
$!PIO := Mu;
$ps;
}
else {
nqp::closefh($!PIO) if nqp::defined($!PIO);
$!PIO := Mu;
True;
}
nqp::closefh($!PIO) if nqp::defined($!PIO);
$!PIO := Mu;
True;
}

method eof(IO::Handle:D:) {
Expand Down Expand Up @@ -511,11 +454,6 @@ my class IO::Handle does IO {
Bool::True;
}

method slurp(IO::Handle:D: |c) {
DEPRECATED('$handle.slurp-rest', |<2014.10 2015.09>);
self.slurp-rest(|c);
}

proto method slurp-rest(|) { * }
multi method slurp-rest(IO::Handle:D: :$bin!) returns Buf {
my $Buf := buf8.new();
Expand All @@ -532,23 +470,6 @@ my class IO::Handle does IO {
nqp::p6box_s(nqp::readallfh($!PIO));
}

proto method spurt(|) { * }
multi method spurt(IO::Handle:D: Cool $contents, :$nodepr) {
DEPRECATED("IO::Path.spurt", |<2014.10 2015.09>) unless $nodepr;
self.print($contents);
}

multi method spurt(IO::Handle:D: Blob $contents, :$nodepr) {
DEPRECATED("IO::Path.spurt", |<2014.10 2015.09>) unless $nodepr;
self.write($contents);
}

# not spec'd
method copy(IO::Handle:D: $dest) {
DEPRECATED("IO::Path.copy", |<2014.10 2015.09>);
$!path.copy($dest);
}

method chmod(IO::Handle:D: Int $mode) { $!path.chmod($mode) }
method IO(IO::Handle:D: |c) { $!path.IO(|c) }
method path(IO::Handle:D:) { $!path.IO }
Expand Down
21 changes: 0 additions & 21 deletions src/core/IO/Path.pm
Expand Up @@ -33,17 +33,6 @@ my class IO::Path is Cool {
die "Must specify something as a path: did you mean '.' for the current directory?" unless $path.chars;
self.bless(:$path, :$SPEC, :$CWD);
}
multi method new(IO::Path:
:$basename,
:$directory!,
:$volume = '',
:$SPEC = $*SPEC,
:$CWD = $*CWD,
) {
DEPRECATED(':dirname', |<2014.10 2015.09>, :what<IO::Path.new with :directory>);
self.bless(
:path($SPEC.join($volume,$directory,$basename)), :$SPEC, :$CWD);
}
multi method new(IO::Path:
:$basename!,
:$dirname = '',
Expand Down Expand Up @@ -404,11 +393,6 @@ my class IO::Path is Cool {
True;
}

method contents(IO::Path:D: |c) {
DEPRECATED('dir', |<2014.10 2015.09>);
self.dir(|c);
}

method dir(IO::Path:D:
Mu :$test = $*SPEC.curupdir,
:$absolute,
Expand Down Expand Up @@ -635,11 +619,6 @@ my class IO::Path is Cool {
fail X::IO::DoesNotExist.new(:path(self.Str),:trying<changed>) if !$.e;
FILETEST-CHANGED($!abspath);
}

method directory() {
DEPRECATED("dirname", |<2014.10 2015.09>);
self.dirname;
}
}

my class IO::Path::Cygwin is IO::Path {
Expand Down
89 changes: 0 additions & 89 deletions src/core/IO/Spec.pm
Expand Up @@ -26,95 +26,6 @@ my class IO::Spec {
#?endif
IO::Spec::{%module{ lc $token } // 'Unix'};
}

method MODULE(IO::Spec:U:) {
DEPRECATED('$*SPEC', |<2014.10 2015.09>);
$*SPEC;
}

method FSTYPE(IO::Spec:U: $OS?) {
DEPRECATED('$*SPEC.select', |<2014.10 2015.09>);
self.select($OS);
}

method os (Str $OS?) {
DEPRECATED('$*SPEC.select', |<2014.10 2015.09>);
self.select($OS);
}

method tmpdir() { # people seem to expect IO::Spec.tmpdir to return a Str
DEPRECATED('$*TMPDIR', |<2014.10 2015.09>);
$*SPEC.tmpdir.path;
}

method canonpath(IO::Spec:U: |c ) {
DEPRECATED('$*SPEC.canonpath', |<2014.10 2015.09>);
$*SPEC.canonpath( |c );
}
method curdir(IO::Spec:U:) {
DEPRECATED('$*SPEC.curdir', |<2014.10 2015.09>);
$*SPEC.curdir();
}
method updir(IO::Spec:U:) {
DEPRECATED('$*SPEC.updir', |<2014.10 2015.09>);
$*SPEC.updir();
}
method rootdir(IO::Spec:U:) {
DEPRECATED('$*SPEC.rootdir', |<2014.10 2015.09>);
$*SPEC.rootdir();
}
method devnull(IO::Spec:U:) {
DEPRECATED('$*SPEC.devnull', |<2014.10 2015.09>);
$*SPEC.devnull();
}
method is-absolute(IO::Spec:U: |c ) {
DEPRECATED('$*SPEC.is-absolute', |<2014.10 2015.09>);
$*SPEC.is-absolute( |c );
}
method no-parent-or-current-test(IO::Spec:U:) {
DEPRECATED('$*SPEC.curupdir', |<2014.10 2015.09>);
$*SPEC.curupdir;
}
method path(IO::Spec:U:) {
DEPRECATED('$*SPEC.path', |<2014.10 2015.09>);
$*SPEC.path();
}
method split(IO::Spec:U: |c ) {
DEPRECATED('$*SPEC.split', |<2014.10 2015.09>);
$*SPEC.split( |c );
}
method join(IO::Spec:U: |c ) {
DEPRECATED('$*SPEC.join', |<2014.10 2015.09>);
$*SPEC.join( |c );
}
method splitpath(IO::Spec:U: |c ) {
DEPRECATED('$*SPEC.splitpath', |<2014.10 2015.09>);
$*SPEC.splitpath( |c );
}
method catpath(IO::Spec:U: |c ) {
DEPRECATED('$*SPEC.catpath', |<2014.10 2015.09>);
$*SPEC.catpath( |c );
}
method catfile(IO::Spec:U: |c ) {
DEPRECATED('$*SPEC.catfile', |<2014.10 2015.09>);
$*SPEC.catfile( |c );
}
method splitdir(IO::Spec:U: |c ) {
DEPRECATED('$*SPEC.splitdir', |<2014.10 2015.09>);
$*SPEC.splitdir( |c );
}
method catdir(IO::Spec:U: |c ) {
DEPRECATED('$*SPEC.catdir', |<2014.10 2015.09>);
$*SPEC.catdir( |c );
}
method abs2rel(IO::Spec:U: |c ) {
DEPRECATED('$*SPEC.abs2rel', |<2014.10 2015.09>);
$*SPEC.abs2rel( |c );
}
method rel2abs(IO::Spec:U: |c ) {
DEPRECATED('$*SPEC.rel2abs', |<2014.10 2015.09>);
$*SPEC.rel2abs( |c );
}
}

# temporary non-lazy initialization of $*SPEC
Expand Down
5 changes: 0 additions & 5 deletions src/core/IO/Spec/Unix.pm
Expand Up @@ -177,11 +177,6 @@ my class IO::Spec::Unix is IO::Spec {
}
self.catdir( self.canonpath($base), $path );
}

method no-parent-or-current-test {
DEPRECATED('curupdir', |<2014.10 2015.09>);
none('.', '..');
}
}

# vim: ft=perl6 expandtab sw=4
13 changes: 1 addition & 12 deletions src/core/io_operators.pm
Expand Up @@ -144,23 +144,12 @@ multi sub slurp(IO::ArgFiles:D $io = $*ARGFILES, :$bin, :$enc = 'utf8', |c) {
my $result := $io.slurp(:$bin, :$enc, |c);
$result // $result.throw;
}
multi sub slurp(IO::Handle:D $io = $*ARGFILES, :$bin, :$enc = 'utf8', |c) {
DEPRECATED('slurp($path,...)',|<2014.10 2015.09>,:what<slurp($handle,...)>);
my $result := $io.slurp-rest(:$bin, :$enc, |c);
$result // $result.throw;
}
multi sub slurp(Cool:D $path, :$bin = False, :$enc = 'utf8', |c) {
my $result := $path.IO.slurp(:$bin, :$enc, |c);
$result // $result.throw;
}

proto sub spurt(|) { * }
multi sub spurt(IO::Handle $fh, $contents, :$enc = 'utf8', |c ) {
DEPRECATED('spurt($path,...)',|<2014.10 2015.09>,:what<spurt($handle,...)>);
my $result := $fh.spurt($contents, :$enc, :nodepr, |c);
$result // $result.throw;
}
multi sub spurt(Cool $path, $contents, :$enc = 'utf8', |c) {
sub spurt(Cool $path, $contents, :$enc = 'utf8', |c) {
my $result := $path.IO.spurt($contents, :$enc, |c);
$result // $result.throw;
}
Expand Down

0 comments on commit 03b5a0a

Please sign in to comment.