Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Str.path, IO::Path.new(Str:D), tests

Also rename IO::Path.dir to .directory, as per spec
Preserve backwards compatiblity for now
  • Loading branch information...
commit e1905aad03b9ece059dba03a0a719d4831a7794e 1 parent eb46da2
Moritz Lenz moritz authored
Showing with 18 additions and 1 deletion.
  1. +12 −1 src/core/IO.pm
  2. +5 −0 src/core/Str.pm
  3. +1 −0  t/spectest.data
13 src/core/IO.pm
View
@@ -239,7 +239,18 @@ class IO does IO::FileTestable {
my class IO::Path is Cool does IO::FileTestable {
has Str $.basename;
- has Str $.dir = '.';
+ has Str $.directory = '.';
+
+ # just for backwards compatiblity
+ method dir() { $!directory }
+ submethod BUILD(:$!basename, :dir(:$!directory)) { }
+
+ multi method new(Str:D $path) {
+ my @chunks = $path.split('/');
+ my $basename = @chunks.pop;
+ my $directory = @chunks.join('/');
+ self.new(:$basename, :$directory);
+ }
multi method Str(IO::Path:D:) {
self.basename;
5 src/core/Str.pm
View
@@ -2,6 +2,7 @@ my class Cursor {... }
my class Range {... }
my class Match {... }
my class Buf {... }
+my class IO::Path { ... }
my class X::Str::Numeric { ... }
my class X::Str::Match::x { ... }
my class X::Str::Trans::IllegalKey { ... }
@@ -915,6 +916,10 @@ my class Str does Stringy {
method tclc(Str:D:) {
nqp::p6box_s(nqp::tclc(nqp::unbox_s(self)))
}
+
+ method path(Str:D:) {
+ IO::Path.new(self);
+ }
}
1  t/spectest.data
View
@@ -575,6 +575,7 @@ S32-hash/slice.t
S32-io/chdir.t
S32-io/dir.t
S32-io/file-tests.t
+S32-io/io-path.t
S32-io/IO-Socket-INET.t
S32-io/note.t
S32-list/categorize.t
Please sign in to comment.
Something went wrong with that request. Please try again.