From fbe852570cefc631429d1dc01d9e0ebec178a662 Mon Sep 17 00:00:00 2001 From: Altai-man Date: Sat, 6 Aug 2016 03:06:48 +0300 Subject: [PATCH] This commit adds new pod config option: 'signature', and adapts current type documentation to it's usage instead of brackets addition. See https://github.com/perl6/doc/issues/794#issuecomment-237981574 --- CONTRIBUTING.md | 10 +++ doc/Type/Any.pod6 | 48 ++++++++++---- doc/Type/Array.pod6 | 54 +++++++++++----- doc/Type/Attribute.pod6 | 36 ++++++++--- doc/Type/Bool.pod6 | 20 ++++-- doc/Type/IO/Socket/Async.pod6 | 40 +++++++++--- doc/Type/Label.pod6 | 8 ++- doc/Type/Metamodel/AttributeContainer.pod6 | 16 +++-- doc/Type/Numeric.pod6 | 74 ++++++++++++++++------ doc/Type/Proc/Async.pod6 | 52 +++++++++++---- doc/Type/RatStr.pod6 | 17 +++-- doc/Type/Setty.pod6 | 48 ++++++++++---- doc/Type/Signature.pod6 | 22 +++++-- doc/Type/X/AdHoc.pod6 | 4 +- doc/Type/X/Anon/Augment.pod6 | 4 +- doc/Type/X/Proc/Async.pod6 | 4 +- doc/Type/X/Syntax/Regex/Adverb.pod6 | 8 ++- util/extract-examples.p6 | 5 +- 18 files changed, 348 insertions(+), 122 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 35b7998fa..19f343088 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -97,6 +97,16 @@ To export examples from all .pod6-files use `make extract-examples`. To run individual tests pick the right .p6-file from `examples/` as a parameter to `perl6`. +### Signatures + +Signatures are part of actual code and need to be tested too. But without the body every +signature will cause an error during the test. Use the pod-config option `signature` to +automatically add an empty body. + + =begin code :signature + method new(*@codes) + =end code + ### Skipping tests Some examples fail with compile time exceptions and would interrupt the test diff --git a/doc/Type/Any.pod6 b/doc/Type/Any.pod6 index aa82567d3..833ad8838 100644 --- a/doc/Type/Any.pod6 +++ b/doc/Type/Any.pod6 @@ -20,7 +20,9 @@ List or a list-like type. Defined as: - multi method ACCEPTS(Any:D: Mu $other) {} +=begin code :signature + multi method ACCEPTS(Any:D: Mu $other) +=end code Usage: @@ -36,7 +38,9 @@ Many built-in types override this for more specific comparisons Defined as: - method any() returns Junction:D {} +=begin code :signature + method any() returns Junction:D +=end code Usage: @@ -54,7 +58,9 @@ C-L from it. Defined as: - method all() returns Junction:D {} +=begin code :signature + method all() returns Junction:D +=end code Usage: @@ -72,7 +78,9 @@ C-L from it. Defined as: - method one() returns Junction:D {} +=begin code :signature + method one() returns Junction:D +=end code Usage: @@ -90,7 +98,9 @@ C-L from it. Defined as: - method none() returns Junction:D {} +=begin code :signature + method none() returns Junction:D +=end code Usage: @@ -127,8 +137,10 @@ into the newly created Array. Defined as: - multi sub reverse(*@list ) returns List:D {} - multi method reverse(List:D:) returns List:D {} +=begin code :signature + multi sub reverse(*@list ) returns List:D + multi method reverse(List:D:) returns List:D +=end code Usage: @@ -163,8 +175,10 @@ Examples: Defined as: proto method map(|) is nodal { * } - multi method map(\SELF: █; :$label, :$item) {} - multi method map(HyperIterable:D: █; :$label) {} +=begin code :signature + multi method map(\SELF: █; :$label, :$item) + multi method map(HyperIterable:D: █; :$label) +=end code C will iterate over the invocant and apply the number of positional parameters of the code object from the invocant per call. The returned values @@ -174,7 +188,9 @@ of the code object will become elements of the returned C. Defined as: - method deepmap(&block -->List) is nodal {} +=begin code :signature + method deepmap(&block -->List) is nodal +=end code C will apply C<&block> to each element and return a new C with the return values of C<&block>, unless the element does the C role. @@ -187,7 +203,9 @@ For those elements C will descend recursively into the sublist. Defined as: - method duckmap(&block) is rw is nodal {} +=begin code :signature + method duckmap(&block) is rw is nodal +=end code C will apply C<&block> on each element and return a new list with defined return values of the block. For undefined return values, C @@ -246,7 +264,9 @@ Interprets the invocant as a list, and returns the last index of that list. =head2 method pairup - method pairup() returns List {} +=begin code :signature + method pairup() returns List +=end code Interprets the invocant as a list, and constructs a list of L from it, in the same way that assignment to a @@ -259,7 +279,9 @@ list item, if any, is considered to be a key again). =head2 sub exit - sub exit(Int() $status = 0) {} +=begin code :signature + sub exit(Int() $status = 0) +=end code Exits the current process with return code C<$status>. diff --git a/doc/Type/Array.pod6 b/doc/Type/Array.pod6 index 9a175bcc4..0f09e6bd6 100644 --- a/doc/Type/Array.pod6 +++ b/doc/Type/Array.pod6 @@ -15,8 +15,10 @@ scalar containers, which means you can assign to array elements. Defined as: - multi sub pop(Array:D ) {} - multi method pop(Array:D:) {} +=begin code :signature + multi sub pop(Array:D ) + multi method pop(Array:D:) +=end code Usage: @@ -40,8 +42,10 @@ Example: Defined as: - multi sub push(Array:D, **@values) returns Array:D {} - multi method push(Array:D: **@values) returns Array:D {} +=begin code :signature + multi sub push(Array:D, **@values) returns Array:D + multi method push(Array:D: **@values) returns Array:D +=end code Usage: @@ -88,8 +92,11 @@ Defined as =begin code :skip-test sub append(\array, elems) =end code - multi method append(Array:D: \values) {} - multi method append(Array:D: **@values is raw) {} +=begin code :signature + multi method append(Array:D: \values) + multi method append(Array:D: **@values is raw) +=end code + Usage: @@ -117,8 +124,10 @@ Example: Defined as: - multi sub shift(Array:D ) {} - multi method shift(Array:D:) {} +=begin code :signature + multi sub shift(Array:D ) + multi method shift(Array:D:) +=end code Usage: @@ -142,8 +151,11 @@ Example: Defined as: - multi sub unshift(Array:D, **@values) returns Array:D {} - multi method unshift(Array:D: **@values) returns Array:D {} +=begin code :signature + multi sub unshift(Array:D, **@values) returns Array:D + multi method unshift(Array:D: **@values) returns Array:D +=end code + Usage: @@ -175,8 +187,11 @@ Defined as =begin code :skip-test sub prepend(\array, elems) =end code - multi method prepend(Array:D: \values) {} - multi method prepend(Array:D: **@values is raw) {} +=begin code :signature + multi method prepend(Array:D: \values) + multi method prepend(Array:D: **@values is raw) +=end code + Usage: @@ -198,8 +213,11 @@ Example: Defined as: - multi sub splice(@list, $start, $elems?, *@replacement) returns Array {} - multi method splice(Array:D $start, $elems?, *@replacement) returns Array {} +=begin code :signature + multi sub splice(@list, $start, $elems?, *@replacement) returns Array + multi method splice(Array:D $start, $elems?, *@replacement) returns Array +=end code + Usage: @@ -243,7 +261,9 @@ Example: Defined as: - method default {} +=begin code :signature + method default +=end code Usage: @@ -272,7 +292,9 @@ the type object C<(Any)>. Defined as: - method of {} +=begin code :signature + method of +=end code Usage: diff --git a/doc/Type/Attribute.pod6 b/doc/Type/Attribute.pod6 index 66c476c5b..5e3a3ed8d 100644 --- a/doc/Type/Attribute.pod6 +++ b/doc/Type/Attribute.pod6 @@ -36,7 +36,9 @@ The usual way to obtain an object of type C is by introspection: Defined as: - method name(Attribute:D:) returns Str:D {} +=begin code :signature + method name(Attribute:D:) returns Str:D +=end code Usage: @@ -51,7 +53,9 @@ so if an attribute is declared as C, the name returned is C<$!a>. Defined as: - method package(Attribute:D:) returns Mu:U {} +=begin code :signature + method package(Attribute:D:) returns Mu:U +=end code Usage: @@ -65,7 +69,9 @@ Returns the package (class/grammar/role) to which this attribute belongs. Defined as: - method has_accessor(Attribute:D:) returns Bool:D {} +=begin code :signature + method has_accessor(Attribute:D:) returns Bool:D +=end code Usage: @@ -79,7 +85,9 @@ Returns C if the attribute has a public accessor method. Defined as: - method readonly(Attribute:D:) returns Bool:D {} +=begin code :signature + method readonly(Attribute:D:) returns Bool:D +=end code Usage: @@ -94,7 +102,9 @@ Returns C for attributes marked as C. Defined as: - method type(Attribute:D:) returns Mu {} +=begin code :signature + method type(Attribute:D:) returns Mu +=end code Usage: @@ -108,7 +118,9 @@ Returns the type constraint of the attribute. Defined as: - method get_value(Attribute:D: Mu $instance) {} +=begin code :signature + method get_value(Attribute:D: Mu $instance) +=end code Usage: @@ -125,7 +137,9 @@ used with care. Here be dragons. Defined as: - method set_value(Attribute:D: Mu $instance, Mu \new_val) {} +=begin code :signature + method set_value(Attribute:D: Mu $instance, Mu \new_val) +=end code Usage: @@ -140,7 +154,9 @@ used with care. Here be dragons. =head2 trait is required - multi sub trait_mod: (Attribute $attr, :$required!) {} +=begin code :signature + multi sub trait_mod: (Attribute $attr, :$required!) +=end code Marks an attribute as being required. If a value is not provided during object construction, an exception is thrown. @@ -162,7 +178,9 @@ constructors written using L. =head2 trait is rw - multi sub trait_mod: (Attribute:D $attr, :$rw!) {} +=begin code :signature + multi sub trait_mod: (Attribute:D $attr, :$rw!) +=end code Marks an attribute as read/write as opposed to the default C. The default accessor for the attribute will return a diff --git a/doc/Type/Bool.pod6 b/doc/Type/Bool.pod6 index 812620002..a77551f44 100644 --- a/doc/Type/Bool.pod6 +++ b/doc/Type/Bool.pod6 @@ -12,7 +12,9 @@ An enum for boolean true/false decisions. =head2 routine succ - method succ() returns Bool:D {} +=begin code :signature + method succ() returns Bool:D +=end code Returns C. @@ -23,7 +25,9 @@ C is short for "successor"; it returns the next enum value. Bool is a spec =head2 routine pred - method pred() returns Bool:D {} +=begin code :signature + method pred() returns Bool:D +=end code Returns C. @@ -34,7 +38,9 @@ C is short for "predecessor"; it returns the previous enum value. Bool is =head2 routine enums - method enums() returns Hash:D {} +=begin code :signature + method enums() returns Hash:D +=end code Returns a L of enum-pairs. Works on both the C type and any key. @@ -46,13 +52,17 @@ and any key. =head2 prefix ? - multi sub prefix:(Mu) returns Bool:D {} +=begin code :signature + multi sub prefix:(Mu) returns Bool:D +=end code Coerces its argument to C. =head2 prefix so - multi sub prefix:(Mu) returns Bool:D {} +=begin code :signature + multi sub prefix:(Mu) returns Bool:D +=end code Coerces its argument to C, has looser precedence than C<< prefix: >>. diff --git a/doc/Type/IO/Socket/Async.pod6 b/doc/Type/IO/Socket/Async.pod6 index 4574a02e4..5a5aa894e 100644 --- a/doc/Type/IO/Socket/Async.pod6 +++ b/doc/Type/IO/Socket/Async.pod6 @@ -77,14 +77,18 @@ data,) should be used to create a client or a server respectively. =head2 method connect - method connect(Str $host, Int $port) returns Promise {} +=begin code :signature + method connect(Str $host, Int $port) returns Promise +=end code Attempts to connect to the TCP server specified by C<$host> and C<$port>, returning a L that will either be kept with a connected L or broken if the connection cannot be made. =head2 method listen - method listen(Str $host, Int $port) returns Supply {} +=begin code :signature + method listen(Str $host, Int $port) returns Supply +=end code Creates a listening socket on the specified C<$host> and C<$port>, returning a L to which the accepted client Ls will be Cted. This L should be tapped to @@ -95,7 +99,9 @@ should be Cd. =head2 method udp - method udp(IO::Socket::Async:U: :$broadcast ) returns IO::Socket::Async {} +=begin code :signature + method udp(IO::Socket::Async:U: :$broadcast ) returns IO::Socket::Async +=end code Returns an initialised C client object that is configured to send UDP messages using C or C. The @@ -104,7 +110,9 @@ the socket to send packets to a broadcast address. =head2 method bind-udp - method bind-udp(IO::Socket::Async:U: Str() $host, Int() $port, :$broadcast) returns IO::Socket::Async {} +=begin code :signature + method bind-udp(IO::Socket::Async:U: Str() $host, Int() $port, :$broadcast) returns IO::Socket::Async +=end code This returns an initialised C server object that is configured to receive UDP messages sent to the specified C<$host> and C<$port> @@ -114,7 +122,9 @@ address. =head2 method print - method print(Str $str) returns Promise {} +=begin code :signature + method print(Str $str) returns Promise +=end code Attempt to send C<$str> on the L that will have been obtained indirectly via C or C, returning a @@ -123,7 +133,9 @@ sent or broken if there was an error sending. =head2 method print-to - method print-to(IO::Socket::Async:D: Str() $host, Int() $port, Str() $str) returns Promise {} +=begin code :signature + method print-to(IO::Socket::Async:D: Str() $host, Int() $port, Str() $str) returns Promise +=end code This is the equivalent of C for UDP sockets that have been created with the C method, it will try send a UDP message of C<$str> to the specified @@ -134,7 +146,9 @@ have been specified when the socket was created. =head2 method write - method write(Blob $b) returns Promise {} +=begin code :signature + method write(Blob $b) returns Promise +=end code Attempt to send the bytes in C<$b> on the L that will have been obtained indirectly via C or C, returning a @@ -143,7 +157,9 @@ sent or broken if there was an error sending. =head2 method write-to - method write-to(IO::Socket::Async:D: Str() $host, Int() $port, Blob $b) returns Promise {} +=begin code :signature + method write-to(IO::Socket::Async:D: Str() $host, Int() $port, Blob $b) returns Promise +=end code This is the equivalent of C for UDP sockets that have been created with the C method, it will try send a UDP message comprised of @@ -155,7 +171,9 @@ flag must have been specified when the socket was created. =head2 method Supply - method Supply(:$bin, :$buf = buf8.new) returns Supply {} +=begin code :signature + method Supply(:$bin, :$buf = buf8.new) returns Supply +=end code Returns a L which can be tapped to obtain the data read from the connected L as it arrives. By default the data @@ -165,7 +183,9 @@ case you can provide your own C with the C<:buf> named parameter. =head2 method close - method close() {} +=begin code :signature + method close() +=end code Close the connected client L which will have been obtained from the C L or the C diff --git a/doc/Type/Label.pod6 b/doc/Type/Label.pod6 index b2fdc5e7b..744ab460e 100644 --- a/doc/Type/Label.pod6 +++ b/doc/Type/Label.pod6 @@ -29,7 +29,9 @@ Those label are objects of type C