Author: lwall Date: 2009-02-14 02:31:33 +0100 (Sat, 14 Feb 2009) New Revision: 25323
Modified: docs/Perl6/Spec/S10-packages.pod docs/Perl6/Spec/S11-modules.pod docs/Perl6/Spec/S12-objects.pod Log: Allow use of :: as anonymous package name Clear up more * as GLOBAL fossils Modified: docs/Perl6/Spec/S10-packages.pod =================================================================== --- docs/Perl6/Spec/S10-packages.pod 2009-02-13 19:34:40 UTC (rev 25322) +++ docs/Perl6/Spec/S10-packages.pod 2009-02-14 01:31:33 UTC (rev 25323) @@ -12,9 +12,9 @@ Maintainer: Larry Wall <la...@wall.org> Date: 27 Oct 2004 - Last Modified: 12 Feb 2009 + Last Modified: 13 Feb 2009 Number: 10 - Version: 8 + Version: 9 =head1 Overview @@ -58,6 +58,11 @@ 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 Modified: docs/Perl6/Spec/S11-modules.pod =================================================================== --- docs/Perl6/Spec/S11-modules.pod 2009-02-13 19:34:40 UTC (rev 25322) +++ docs/Perl6/Spec/S11-modules.pod 2009-02-14 01:31:33 UTC (rev 25323) @@ -12,9 +12,9 @@ Maintainer: Larry Wall <la...@wall.org> Date: 27 Oct 2004 - Last Modified: 06 Jan 2009 + Last Modified: 13 Feb 2009 Number: 11 - Version: 25 + Version: 26 =head1 Overview @@ -46,7 +46,7 @@ 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 @@ -56,24 +56,24 @@ 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 Exportation is now done by trait declaration on the exportable item: @@ -133,14 +133,14 @@ 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: @@ -187,7 +187,7 @@ 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: @@ -195,7 +195,7 @@ # 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 Modified: docs/Perl6/Spec/S12-objects.pod =================================================================== --- docs/Perl6/Spec/S12-objects.pod 2009-02-13 19:34:40 UTC (rev 25322) +++ docs/Perl6/Spec/S12-objects.pod 2009-02-14 01:31:33 UTC (rev 25323) @@ -12,9 +12,9 @@ Maintainer: Larry Wall <la...@wall.org> Date: 27 Oct 2004 - Last Modified: 21 Jan 2009 + Last Modified: 12 Feb 2009 Number: 12 - Version: 68 + Version: 69 =head1 Overview @@ -74,11 +74,13 @@ 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 the current package. Since class files begin parsing in the @@ -152,6 +154,14 @@ 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: @@ -1128,7 +1138,7 @@ 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 @@ -1428,11 +1438,11 @@ 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>. @@ -1443,7 +1453,7 @@ 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); }