
=encoding utf8

=head1 TITLE

DRAFT: Synopsis 16: IO / Name Services

=head1 AUTHORS

    Largely, the authors of the related Perl 5 docs.
    Larry Wall <larry@wall.org>
    Mark Stosberg <mark@summersault.com>
    Tim Nelson <wayland@wayland.id.au>
    Daniel Ruoso <daniel@ruoso.com>

=head1 VERSION

    Created: 12 Sep 2006

    Last Modified: 19 Apr 2009
    Version: 22

This is a draft document. Many of these functions will work as in Perl
5, except we're trying to rationalize everything into roles.  For
now you can assume most of the important functions will automatically
be in the * namespace.  However, with IO operations in particular,
many of them are really methods on an IO handle, and if there is a
corresponding global function, it's merely an exported version of
the method.

=head1 IO

=head2 Overridable IO handles

In Perl 6, there are the I<standard> IO handles, and any number of overriding
inner filehandles for the same symbol.

The I<standard> handles are our old familiar friends (with new names).
Standard input changed from STDIN to C<$*IN>, standard output changed
from STDOUT to C<$*OUT>, and standard error changed from STDERR to
C<$*ERR>.  In Perl 6 these symbols represent more of a concept than
a given filehandle, since the meaning is contextually determined.
The process's version of these handles live in the C<PROCESS::>
namespace, which is more global than the per-interpreter C<GLOBAL::>
namespace.

When no explicit filehandle is used, the standard IO operators are
defined in terms of the contextual variables.  So the C<print> function
prints to C<$*OUT>, while C<warn> warns to C<$*ERR>.  The C<< lines() >>
term inputs from C<$*ARGFILES> which defaults to C<$*IN> in the absence of any
filenames.  So any given dynamic scope (interpreter,
thread, function or method call) may redefine the current meaning of
any of those filehandles within the dynamic scope of itself and of
its called routines.

So to put it another way, when you write something like

    say "Howdy, world!"

the C<say> function looks for the current meaning of C<$*OUT>, and
takes the closest definition it can find in its callers.  If none
of the callers have overridden the definition, it looks in the
interpreter's C<GLOBAL> namespace.  If the interpreter hasn't overridden
the meaning, it takes the meaning from C<PROCESS>.  In essence, any
dynamic scope in Perl 6 is allowed to do IO redirection much like
a Unix shell does with its subprocesses, albeit with a different
syntax:

    {
        temp $*OUT = open $newfile, :w;
        foo() # all stdout goes to $newfile
    }
    # stdout reverts to outer scope's definition

=head2 Roles and Classes

The roles and classes that define most of the functionality for IO are defined in
S32-setting-library/IO.pod.  The main functions used are listed in S29 with references to
S32-setting-library/IO.pod.

=head1 Name Services

=head2 User role

    role User {
        has $username; # Username (some descendants(?) may want to implement a real $name)
        has $id;  # User ID
        has $dir; # Home directory for files
    }

=over

=item new

    method User new($Username?, $UID?) {...}

Creates a new User object, fetching the information either by username or user ID.

=item write

    method write() {...}

Tries to write the current User object to the user database.  This may well fail.

=item Str

When converted to a Str, returns $username.

=item Num

When converted to a Num, returns $uid.

=back

=head2 OS::Unix::User role

    role OS::Unix::User does User {
        has $password;
        has $gid;
        has $gecos;
        has $shell;
    }

All the information is naturally fetched from the system via getpwuid, getpwnam, or the
like.

=head2 Group role

    role Group {
        has $name;
        has $id;
        has @members;
    }

=over

=item new

    method Group new(:$Name, :$ID);

=item write

    method write();

Tries to write the group entry into the system group database.

=back

=head2 OS::Unix::NameServices role

The NameServices role has a bunch of functions that between them will return the whole
Name Services database between them, as lists of objects.  The lists are specifically
intended to be lazy.

    role NameServices {
        method List of User     users()     {...} # getpwent, setpwent, endpwent
        method List of Group    groups()    {...} # getgrent, setgrent, endgrent
        method List of Service  services()  {...} # getservent, setservent, endservent
        method List of Protocol protocols() {...} # getprotoent, setprotoent, endprotoent
        method List of Network  networks()  {...} # getnetent, setnetent, endnetent
        method List of Host     hosts()     {...} # gethostent, sethostent, endhostent
    }

=head1 Additions

Please post errors and feedback to perl6-language.  If you are making
a general laundry list, please separate messages by topic.

=cut

=for vim:set expandtab sw=4:
