Sorry, quoting myself...

In a message dated Mon, 7 Jan 2008, Trey Harris writes:
 given $?OS {
    when m:i:/win/ { use Foo in WinFoo.pm }
    when m:i:/nix/ { use Foo in UnixLikeFoo.pm }
 }

It strikes me that $?OS and $?OSVER should probably not be strings (as they now are in Pugs) and should be objects--in fact, they can both be the same object, just with different stringifications. Auto-instantiated singletons of classes named for the OS, to be precise.

That way, you could do Config-and OS-specific-type stuff through the $?OS object--which is nice, though not that important--but better yet you can do

  given $?OS {
     when Windows { ... }
     when MacOS   { ... }
     when Linux   { ... }
     when Unix    { ... }
     default      { ... }
  }

Rather than having to do string-matching (and one would assume that Linux and MacOS are subtypes of Unix, etc.)

Then we can have roles that describe cross-cutting behavior of various OS's (like POSIX):

  my &trytolink;
  give $?OS {
     when OS::HasSymlinks { &trytolink := &*symlink; }
     when OS::HasLinks    { &trytolink := &*link; }
     default              { &trytolink :=
                            -> ($old, $new) { fail X::LinkNotAvailable }
                          }
  }

  # (Aside: Is there some way to do create a two-argument sub that ignores
  #  its arguments?  Would -> (undef, undef) or -> (*, *) or -> (Any, Any)
  #  work?)

So $?OS isn't "the type of OS", it's *the OS*, and you can manipulate the OS through it.

Thoughts?

Trey

Reply via email to