On 2009-Aug-18, at 3:27 am, Timothy S. Nelson wrote:
On Tue, 18 Aug 2009, David Green wrote:
Maybe setting $*CWD just calls chdir() under the hood? Same implementation, brand new shiny Perl-style interface!
That was my intent, but we had some discussions on IRC about the whys and wherefores, and it will return as soon as I do my next commit (hopefully sometime within the next 4-5 hours). Unless you can think of a good way to do relative paths.

In my naiveté, I would do:

class IO::CurrentDir;      # the type of $*CWD

  sub STORE($self: IO::Path $new)
      $self = getcwd();

or however that would work in P6. It may have problems, but by definition they're the same problems as chdir() has. What am I missing?

On 2009-Aug-18, at 3:12 am, Jan Ingvoldstad wrote:
It may seem cool, but I don't like secondary effects like that. They break the principle of least surprise.

It doesn't seem that surprising to me, especially after seeing the docs the first time. Are there environments where you can set a variable like $*CWD and it doesn't do something like chdir? (And we can always keep chdir() as well, so old dogs aren't forced to learn new tricks.)

On 2009-Aug-18, at 3:52 am, Mark J. Reed wrote:
If $*CWD is really a Path object and not a Str, then it should be easy
to use mutator methods to change to a relative directory and do other
chdir()ish things.  Say, concatenation works in terms of path
components, for instance:
    $*CWD ~= $subdir;   # chdir($subdir)

Yes. Though $*CWD = "subdir" should also work; "subdir" is not the same path as "/subdir", so it knows whether you're assigning a relative path or not. Or rather, our path-type would know, and implicitly prepend the current dir when it parses/forms the actual pathname, so $CWD would effectively get a fully specified path every time.

With a method for getting the parent:
    given $*CWD { $_ = $_.up ~ $sibling }   # chdir("../$sibling")

I like that.

and so on.  My favorite kshism is "cd old new" which does a
search/replace on the current working directory; the bash equivalent
"cd ${PWD/old/new}" which is not quite as handy.  $*CWD could make
that simple, too.



Reply via email to