Skip to content

Instantly share code, notes, and snippets.

@masak
Created September 17, 2013 15:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masak/6595941 to your computer and use it in GitHub Desktop.
Save masak/6595941 to your computer and use it in GitHub Desktop.
change $!path to $!pathstr in IO::Path
From a15adc19a622d4e7f121047ac73d427d8e2b408f Mon Sep 17 00:00:00 2001
From: Carl Masak <cmasak@gmail.com>
Date: Tue, 17 Sep 2013 17:27:53 +0200
Subject: [PATCH] IO::Path attribute s/path/pathstr/
---
src/core/IO.pm | 46 +++++++++++++++++++++++-----------------------
1 file changed, 23 insertions(+), 23 deletions(-)
diff --git a/src/core/IO.pm b/src/core/IO.pm
index 1252e8e..883c588 100644
--- a/src/core/IO.pm
+++ b/src/core/IO.pm
@@ -320,22 +320,22 @@ my class IO::Handle does IO::FileTestable {
my class IO::Path is Cool does IO::FileTestable {
method SPEC { IO::Spec.MODULE };
- has Str $.path;
+ has Str $.pathstr;
method dir() {
die "IO::Path.dir is deprecated in favor of .directory";
}
- submethod BUILD(:$!path!, :$dir) {
+ submethod BUILD(:$!pathstr!, :$dir) {
die "Named paramter :dir in IO::Path.new deprecated in favor of :directory"
if defined $dir;
}
multi method new(:$basename!, :$directory = '.', :$volume = '') {
- self.new: path=>$.SPEC.join($volume, $directory, $basename);
+ self.new: pathstr=>$.SPEC.join($volume, $directory, $basename);
}
- multi method new(Str:D $path) {
- self.new(:$path)
+ multi method new(Str:D $pathstr) {
+ self.new(:$pathstr)
}
method path(IO::Path:D:) {
@@ -343,7 +343,7 @@ my class IO::Path is Cool does IO::FileTestable {
}
method parts {
- $.SPEC.split($!path).hash
+ $.SPEC.split($!pathstr).hash
}
method basename {
self.parts<basename>
@@ -356,13 +356,13 @@ my class IO::Path is Cool does IO::FileTestable {
}
multi method Str(IO::Path:D:) {
- $!path;
+ $!pathstr;
}
multi method gist(IO::Path:D:) {
- "{self.^name}<{ $!path }>";
+ "{self.^name}<{ $!pathstr }>";
}
multi method perl(IO::Path:D:) {
- "IO::Path.new(path => " ~ $.Str.perl ~ ")";
+ "IO::Path.new(pathstr => " ~ $.Str.perl ~ ")";
}
multi method Numeric(IO::Path:D:) {
self.basename.Numeric;
@@ -382,27 +382,27 @@ my class IO::Path is Cool does IO::FileTestable {
}
method IO(IO::Path:D: *%opts) {
- IO::Handle.new(:$!path, |%opts);
+ IO::Handle.new(:$!pathstr, |%opts);
}
method open(IO::Path:D: *%opts) {
- open($!path, |%opts);
+ open($!pathstr, |%opts);
}
method is-absolute {
- $.SPEC.is-absolute($!path);
+ $.SPEC.is-absolute($!pathstr);
}
method is-relative {
- ! $.SPEC.is-absolute($!path);
+ ! $.SPEC.is-absolute($!pathstr);
}
method absolute ($base = ~$*CWD) {
- return self.new($.SPEC.rel2abs($!path, $base));
+ return self.new($.SPEC.rel2abs($!pathstr, $base));
}
method relative ($relative_to_directory = ~$*CWD) {
- return self.new($.SPEC.abs2rel($!path, $relative_to_directory));
+ return self.new($.SPEC.abs2rel($!pathstr, $relative_to_directory));
}
method cleanup (:$parent) {
- return self.new($.SPEC.canonpath($!path, :$parent));
+ return self.new($.SPEC.canonpath($!pathstr, :$parent));
}
method resolve {
# NYI: requires readlink()
@@ -430,28 +430,28 @@ my class IO::Path is Cool does IO::FileTestable {
}
method child ($childname) {
- self.new: path => $.SPEC.catfile($!path, $childname);
+ self.new: pathstr => $.SPEC.catfile($!pathstr, $childname);
}
method copy(IO::Path:D: $dest, :$createonly = False) {
my $absdest = IO::Spec.rel2abs($dest);
if $createonly and $absdest.e {
- fail(X::IO::Copy.new(from => $!path, to => $dest,
+ fail(X::IO::Copy.new(from => $!pathstr, to => $dest,
os-error => "Destination file $dest exists and :createonly passed to copy."));
}
try {
- nqp::copy(nqp::unbox_s(IO::Spec.rel2abs($!path)), nqp::unbox_s(~$absdest));
+ nqp::copy(nqp::unbox_s(IO::Spec.rel2abs($!pathstr)), nqp::unbox_s(~$absdest));
}
- $! ?? fail(X::IO::Copy.new(from => $!path, to => $dest, os-error => ~$!)) !! True
+ $! ?? fail(X::IO::Copy.new(from => $!pathstr, to => $dest, os-error => ~$!)) !! True
}
method chmod(IO::Path:D: Int $mode) {
- nqp::chmod(nqp::unbox_s(IO::Spec.rel2abs($!path)), nqp::unbox_i($mode.Int));
+ nqp::chmod(nqp::unbox_s(IO::Spec.rel2abs($!pathstr)), nqp::unbox_i($mode.Int));
return True;
CATCH {
default {
X::IO::Chmod.new(
- :$!path,
+ :path($!pathstr),
:$mode,
os-error => .Str,
).throw;
@@ -464,7 +464,7 @@ my class IO::Path is Cool does IO::FileTestable {
CATCH {
default {
X::IO::Dir.new(
- :$!path,
+ :path($!pathstr),
os-error => .Str,
).throw;
}
--
1.7.10.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment