On Mon, Jun 8, 2020 at 2:11 PM ToddAndMargo via perl6-users < perl6-us...@perl.org> wrote:
> On 2020-06-08 04:32, Fernando Santagata wrote: > > On Mon, Jun 8, 2020 at 1:20 PM ToddAndMargo via perl6-users > > <perl6-us...@perl.org <mailto:perl6-us...@perl.org>> wrote: > > > > On 2020-06-08 03:38, Fernando Santagata wrote: > > > …and line 3: > > > > > > unit module Informative; > > > > 3: unit module Informative; > > > > Does not look like a class to me. What am I missing? > > > > It's a namespace declaration, see: > > > > > https://docs.raku.org/language/syntax#index-entry-declarator_unit-declarator_module-declarator_package-Package,_Module,_Class,_Role,_and_Grammar_declaration > > > > That's the reason why the class name is Informative::Informing and not > > just Informing. > > Hi Fernando, > > I see: > > Several packages may be declared in a single file. > However, you can declare a unit package at the start > of the file (preceded only by comments or use > statements), and the rest of the file will be taken > as being the body of the package. In this case, the > curly braces are not required. > > unit module M; > # ... stuff goes here instead of in {}'s > > I thought methods had to be part of classes? Or > how the above relates to the methods in the module. > > I am confused. Methods are just subroutines which take an implicit first argument: the object they are operating on. All the methods in the module you mentioned are methods of the Informative::Informing class. You can check it by matching the '{' at the beginning of the class declaration with the corresponding '}'; method show() is inside the class. OTOH there's a "sub inform" in the "Informative" namespace which is not inside a class and is indeed a simple sub, even if it has been localized in that namespace. You can call that sub without prepending its namespace, since it has been declared as "is export." -- Fernando Santagata