All this discussion about file paths, particularly about "current working directory", has inspired me to raise another idea for how this could be done, which may be a little more abstract or different than you're used to, but may also be an elegant solution.

My proposal draws inspiration from a design aspect of my Muldis D language in regards to how fully-qualified names for DBMS entities are written out, including the names of types, routines, variables, and so on, which is in turn inspired by how SQL DBMSs tend to name things, where you qualify them with a database name plus schema name plus package name if applicable and so on; for a DBMS, the hierarchy of namespaces is like a filesystem, since everything relevant lives in there, and so schema names etc are like directories and variables or routines etc are like files, or alternately they are like namespaces in a programming language defined by packages or classes etc for their routines or types or variables. The Muldis D concept is that there are some primary namespaces whose definition is relative to where they are invoked; and invoking entities by way of these means "I refer to this entity in terms of a particular context of mine", such as "in my package" ($pkg.foo) or "in my schema" ($sdp.foo or $dep.bar.foo etc).

My proposal is to have all filesystem paths as seen within Perl being relative paths, and that there are multiple filesystem roots which can be referred to by name and each relative path is explicitly relative to a named root; each of these named roots is called a "directory of interest" or "doi".

The named filesystem roots can be defined or altered at runtime by Perl code, and each one is defined within the context of another.

Obviously at least one must be system-defined by Perl so to be able to genesis the others, and that one corresponds to the actual filesystem root (or some other dir if the Perl process is operating in a jail).

When you write a path, then rather than rooting it with "/", you instead root it with "<doi>/".

Examples of "doi" can be:

  fsroot - the root of the real file system, analogous to "/"
  fscwd - the dir that was the fs CWD when Perl started up
  docs - the dir that contains the usual files we want to work with
  temp - the dir where we can put temporary files
  home - the current user's home dir
  mycwd - some other cwd-dir, which is virtual-changeable in Perl

So to refer to common things on a Unix system like the fully-qualified ways, you can write paths like:

  fsroot/home/me/myfile
  fsroot/usr/bin/perl
  fsroot

For something analogous to traditional CWD sans modifications:

  fscwd/mynewfile.txt
  fscwd/lib/doit.pl

To define a new doi at runtime, something like:

  %DOI{'mycwd'} = %DOI{'fscwd'};
  %DOI{'mycwd'} ~= 'subdir';
  # later
  my $fh = IO.open( 'mycwd/myfile.txt' );

For ease of use, we can still have vars like $*CWD, which might be an alias for a doi with a specific name.

Note, please ignore my specific syntax for denoting Path objects. I defer to other discussions and synopsis for those details, and mainly what I'm trying to put across here is concepts.

My main point here is that we effectively can have multiple CWD in the same Perl thread, and it shouldn't be too much trouble to make this work well.

-- Darren Duncan

Reply via email to