Skip to content

Instantly share code, notes, and snippets.

@dogbert17
Last active May 7, 2016 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogbert17/829e1adf6c6f9b03f2f47d9eb1a2c72e to your computer and use it in GitHub Desktop.
Save dogbert17/829e1adf6c6f9b03f2f47d9eb1a2c72e to your computer and use it in GitHub Desktop.
Formatter examples (Dateish.pod)
=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