class Formatter
class Formatter { }
The Formatter
class does not produce any instances of itself,
but instead serves as an access point to the "change a 'sprintf'
compatible format specification into Callable" functionality.
Available as of the 2023.06 release of the Rakudo compiler.
Requires language level 6.e
.
use v6.e.PREVIEW;
my &handle = Formatter.new("'%5s'");
say handle("foo"); # OUTPUT: «' foo'»
Methods
method new
method new($format --> Callable:D)
Returns a cached Callable object from a sprintf
compatible
format string. Will create a new Callable object if the
given format string had not been seen before.
use v6.e.PREVIEW;
my &zero5 = Formatter.new("%05d");
say zero5(42); # OUTPUT: «00042»
method CODE
method CODE(--> Callable:D)
Returns an uncached Callable object from a sprintf
compatible format string. Intended to be used in compile-time
situations where caching is neither important nor wanted.
method AST
method AST(--> RakuAST::Node:D)
Returns a RakuAST representation of the Callable for
the given sprintf
compatible format string. Intended to
be used for debugging.