Skip to content

Commit 8e6753b

Browse files
committed
Documents X::NYI constructor and methods
Closes #2052
1 parent 74a0051 commit 8e6753b

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

doc/Type/X/NYI.pod6

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Error class for unimplemented features. I<NYI> stands for I<Not Yet
1010
Implemented>.
1111
1212
If a Perl 6 compiler is not yet feature complete, it may throw an C<X::NYI>
13-
exception when a program uses a feature that it can detect is not yet
13+
exception when a program uses a feature that it can detect and is somehow specified is not yet
1414
implemented.
1515
1616
A full-featured Perl 6 compiler must not throw such exceptions, but
@@ -23,8 +23,52 @@ HyperWhatever is not yet implemented. Sorry.
2323
2424
=head1 Methods
2525
26-
=head2 method features
26+
=head2 method new
27+
28+
method new( :$feature, :$did-you-mean, :$workaround)
29+
30+
This is the default constructor for C<X:NYI> which can take three parameters with obvious meanings.
31+
32+
=begin code
33+
class Nothing {
34+
method ventured( $sub, **@args) {
35+
X::NYI.new( feature => &?ROUTINE.name,
36+
did-you-mean => "gained",
37+
workaround => "Implement it yourself" ).throw;
38+
}
39+
}
40+
41+
my $nothing = Nothing.new;
42+
$nothing.ventured("Nothing", "Gained");
43+
=end code
44+
45+
In this case, we are throwing an exception that indicates that the C<ventured> routine has not been implemented; we use the generic C<&?ROUTINE.name> to not tie the exception to the method name in case it is changed later on. This code effectively throws this exception
46+
47+
=begin code
48+
# OUTPUT:
49+
# ventured not yet implemented. Sorry.
50+
# Did you mean: gained?
51+
# Workaround: Implement it yourself
52+
# in method ventured at NYI.p6 line 6
53+
# in block <unit> at NYI.p6 line 14
54+
=end code
55+
56+
Using the exception properties, it composes the message that we see there.
57+
58+
=head2 method feature
2759
2860
Returns a C<Str> describing the missing feature.
2961
62+
=head2 method did-you-mean
63+
64+
Returns a C<Str> indicating the optional feature that is already implemented.
65+
66+
=head2 method workaround
67+
68+
It helpfully shows a possible workaround for the missing feature, if it's been declared.
69+
70+
=head2 method message
71+
72+
Returns the message including the above properties.
73+
3074
=end pod

0 commit comments

Comments
 (0)