Skip to content

Commit 7811748

Browse files
committed
Add initial documentation for Formatter
1 parent f1cd033 commit 7811748

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

doc/Type/Formatter.rakudoc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
=begin pod :kind("Type") :subkind("class") :category("basic")
2+
3+
=TITLE class Formatter
4+
5+
=SUBTITLE Produce Callable for given format specification
6+
7+
class Formatter { }
8+
9+
The C<Formatter> class does not produce any instances of itself,
10+
but instead serves as an access point to the "change a 'sprintf'
11+
compatible format specification into Callable" functionality.
12+
13+
Available as of the 2023.06 release of the Rakudo compiler.
14+
Requires language level C<6.e>.
15+
16+
use v6.e.PREVIEW;
17+
my &handle = Formatter.new("'%5s'");
18+
say handle("foo"); # OUTPUT: «' foo'␤»
19+
20+
=head1 Methods
21+
22+
=head2 method new
23+
24+
method new($format --> Callable:D)
25+
26+
Returns a cached C<Callable> object from a C<sprintf> compatible
27+
format string. Will create a new C<Callable> object if the
28+
given format string had not been seen before.
29+
30+
use v6.e.PREVIEW;
31+
my &zero5 = Formatter.new("%05d");
32+
say zero5(42); # OUTPUT: «00042␤»
33+
34+
=head2 method CODE
35+
36+
method CODE(--> Callable:D)
37+
38+
Returns a <un>cached C<Callable> object from a C<sprintf>
39+
compatible format string. Intended to be used in compile-time
40+
situations where caching is neither important nor wanted.
41+
42+
=head2 method AST
43+
44+
method AST(--> RakuAST::Node:D)
45+
46+
Returns a C<RakuAST> representation of the C<Callable> for
47+
the given C<sprintf> compatible format string. Intended to
48+
be used for debugging.
49+
50+
=end pod

0 commit comments

Comments
 (0)