Skip to content

Commit

Permalink
Allow use of :: as anonymous package name
Browse files Browse the repository at this point in the history
Clear up more * as GLOBAL fossils


git-svn-id: http://svn.pugscode.org/pugs@25323 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information
lwall committed Feb 14, 2009
1 parent 6ecb2d0 commit 60cc0db
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 31 deletions.
9 changes: 7 additions & 2 deletions S10-packages.pod
Expand Up @@ -12,9 +12,9 @@ Larry Wall <larry@wall.org>

Maintainer: Larry Wall <larry@wall.org>
Date: 27 Oct 2004
Last Modified: 12 Feb 2009
Last Modified: 13 Feb 2009
Number: 10
Version: 8
Version: 9

=head1 Overview

Expand Down Expand Up @@ -58,6 +58,11 @@ a global package name.

To declare a lexically scoped package, use C<my package>.

To declare an anonymous package you can use either of

package {...}
package :: {...}

All files start out being parsed in the C<GLOBAL>
package, but may switch to some other package scope depending on the first
package-ish declaration. If that first declaration is not a package variant, then
Expand Down
38 changes: 19 additions & 19 deletions S11-modules.pod
Expand Up @@ -12,9 +12,9 @@ Larry Wall <larry@wall.org>

Maintainer: Larry Wall <larry@wall.org>
Date: 27 Oct 2004
Last Modified: 06 Jan 2009
Last Modified: 13 Feb 2009
Number: 11
Version: 25
Version: 26

=head1 Overview

Expand Down Expand Up @@ -46,7 +46,7 @@ imply globalness as it does in Perl 5. (Use C<GLOBAL::> for that.)

A bare (unscoped) C<module> declarator declares a nested C<our> module
name within the current package. However, at the start of the file,
the current package is C<*>, so the first such declaration in the
the current package is C<GLOBAL>, so the first such declaration in the
file is automatically global.

You can use C<our module> to explicitly
Expand All @@ -56,23 +56,23 @@ Module names are always searched for from innermost scopes to outermost.
As with an initial C<::>, the presence of a C<::> within the name
does not imply globalness (unlike in Perl 5).

The C<::*> namespace is not "main". The default namespace for the
main program is C<::*Main>, which it switches to from * as soon as
it sees the first declaration, if that declaration doesn't set the
package name. (Putting C<module Main;> at the top of your program
The default namespace for the main program is C<GLOBAL>.
(Putting C<module GLOBAL;> at the top of your program
is redundant, except insofar as it tells Perl that the code is Perl
6 code and not Perl 5 code. But it's better to say "use v6" for that.)

But note that if you say
Module traits are set using C<is>:

use v6;
module Foo {...}
module Foo is bar {...}

you've just created Main::Foo, not *Foo.
An anonymous module make be created with either of:

Module traits are set using C<is>:
module {...}
module :: {...}

module Foo is bar {...}
The second form is useful if you need to apply a trait:

module :: is bar {...}

=head1 Exportation

Expand Down Expand Up @@ -133,14 +133,14 @@ Importing via C<use> binds into the current lexical scope by default

You can be explicit about the desired namespace:

use Sense :MY<common> :OUR<@horse> :GLOBAL<$warming>;
use Sense :MY<common> :OUR<@horse> :CONTEXT<$sensitive>;

That's pretty much equivalent to:

use Sense;
my &common ::= &Sense::common;
our @horse ::= @Sense::horse;
$*warming ::= $Sense::warming;
my &common ::= Sense::<&common>;
our @horse ::= Sense::<@horse>;
$*sensitive ::= Sense::<$sensitive>

It is also possible to re-export the imported symbols:

Expand Down Expand Up @@ -187,15 +187,15 @@ to the package scope instead:
You may also import symbols from the various pseudo-packages listed in S02.
They behave as if all their symbols are in the C<:ALL> export list:

use GLOBAL <$IN $OUT $ERR>;
use CONTEXT <$IN $OUT $ERR>;
require CALLER <$x $y>;

# Same as:
# my ($IN, $OUT, $ERR) ::= ($*IN, $*OUT, $*ERR)
# my ($x, $y) := ($CALLER::x, $CALLER::y)

As pseudo-packages are always already preloaded, C<use> and C<require> will
never attempt to load, for example, C<GLOBAL.pm> from an external source.
never attempt to load, for example, C<CALLER.pm> from an external source.

=head1 Versioning

Expand Down
30 changes: 20 additions & 10 deletions S12-objects.pod
Expand Up @@ -12,9 +12,9 @@ Larry Wall <larry@wall.org>

Maintainer: Larry Wall <larry@wall.org>
Date: 27 Oct 2004
Last Modified: 21 Jan 2009
Last Modified: 12 Feb 2009
Number: 12
Version: 68
Version: 69

=head1 Overview

Expand Down Expand Up @@ -74,10 +74,12 @@ Use composition and/or delegation to change the representation.

Since there are no barewords in Perl 6, bare class names must be
predeclared. You can predeclare a stub class and fill it in later
just as you would a subroutine. Alternately, you can define a local
class or type variable using the C<::> type sigil. In an rvalue
context the C<::> prefix is a no-op, but in a declarational context,
it binds a new type name within its declared scope.
just as you would a subroutine.

You can force interpretation of a name as a class or type name using
the C<::> prefix. In an rvalue context the C<::> prefix is a no-op,
but in a declarational context, it binds a new type name within the
declaration's scope along with anything else being declared by the declaration.

Without a C<my> or other scoping declarator, a bare C<class>
declarator declares an C<our> declarator, that is, a name within
Expand Down Expand Up @@ -152,6 +154,14 @@ handled with lexical scoping in Perl 6. The fact that importation
is lexical by default also means that any names your class imports
are also private by default.

In an anonymous class declaration, C<::> by itself may represent the
anonymous class name if desired:

class {...} # ok
class is Mammal {...} # WRONG
class :: is Mammal {...} # ok
class { is Mammal; ...} # also ok

=head1 Methods

Methods are routines declared in a class with the C<method> keyword:
Expand Down Expand Up @@ -1128,7 +1138,7 @@ class composition time. This means that if two roles bring in the
same crony, there's no conflict--it's just as if the class pulled in
the crony role itself and the respective roles didn't. A role may
never conflict with itself regardless of its method of incorporation.
A role that brings in two conflicting crony roles *may* resolve them
A role that brings in two conflicting crony roles I<may> resolve them
as if it were a class. This solution is accepted by the class unless
the class supplies its own solution. If two different roles resolve
the same crony conflict two different ways, those roles are themselves
Expand Down Expand Up @@ -1428,11 +1438,11 @@ These capture control if C<MyBase> wants to capture control of how it gets
used by any class or container. But usually you can just let it call
the generic defaults:

multi *trait_auxiliary:is(Class $base, Class $class; $arg?) {...}
multi trait_auxiliary:is(Class $base, Class $class; $arg?) {...}

which adds C<$base> to the "isa" list of C<$class>, or

multi *trait_auxiliary:is(Class $tied, Any $container; $arg?) {...}
multi trait_auxiliary:is(Class $tied, Any $container; $arg?) {...}

which sets the "tie" type of the container to the implementation type
in C<$tied>.
Expand All @@ -1443,7 +1453,7 @@ or "C<should>", or "C<does>". We call these helping verbs "trait
auxiliaries". Here's "C<will>", which (being syntactic sugar) merely
delegates to back to "is":

multi sub *trait_auxiliary:will($trait, $container; &arg) {
multi sub trait_auxiliary:will($trait, $container; &arg) {
trait_auxiliary:is($trait, $container, &arg);
}

Expand Down

0 comments on commit 60cc0db

Please sign in to comment.