Last active
May 7, 2016 17:11
-
-
Save dogbert17/829e1adf6c6f9b03f2f47d9eb1a2c72e to your computer and use it in GitHub Desktop.
Formatter examples (Dateish.pod)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=head2 method formatter | |
Defined as: | |
method formatter(Dateish:D:) | |
Usage: | |
Dateish.formatter | |
Returns the formatting function which is used for conversion to | |
L<Str|/type/Str>. If none was provided at object construction, a | |
default formatter is used. In that case the method will return a | |
Callable type object. | |
The formatting function is called by L<#method Str> with the invocant as its | |
only argument. | |
+ my $dt = Date.new('2015-12-31'); # (no formatter specified) | |
+ say $dt.formatter.WHAT; # (Callable) | |
+ my $us-format = sub ($self) { sprintf "%2d/%02d/%04d", .month, .day, .year given $self; }; | |
+ $dt = Date.new('2015-12-31', formatter => $us-format); | |
+ say $dt.formatter.WHAT; # (Sub) | |
+ say $dt; # 12/31/2015 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment