Skip to content

Commit

Permalink
added $format default to all .fmt variants
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Masak committed Jul 6, 2009
1 parent cf851ca commit 99ad1eb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
13 changes: 9 additions & 4 deletions src/classes/Mapping.pir
Expand Up @@ -28,21 +28,26 @@ src/classes/Mapping.pir - Perl 6 hash class and related functions

=item fmt

our Str multi Mapping::fmt ( Str $format, $separator = "\n" )
our Str multi Mapping::fmt ( Str $format = "%s\t%s", $separator = "\n" )

Returns the invocant mapping formatted by an implicit call to C<.fmt> on
every pair, joined by newlines or an explicitly given separator.

=cut

.sub 'fmt' :method :multi() :subid('mapping_fmt')
.param pmc format
.param string sep :optional
.param int has_sep :opt_flag
.param string format :optional
.param int has_format :opt_flag
.param string sep :optional
.param int has_sep :opt_flag

.local pmc it
.local pmc rv

if has_format goto have_format
format = "%s\t%s"

have_format:
if has_sep goto have_sep
sep = "\n"

Expand Down
2 changes: 1 addition & 1 deletion src/setting/Any-str.pm
Expand Up @@ -15,7 +15,7 @@ class Any is also {
self.substr(0, -1)
}

our Str multi method fmt(Str $format) {
our Str multi method fmt(Str $format = '%s') {
sprintf($format, self)
}

Expand Down
4 changes: 2 additions & 2 deletions src/setting/List.pm
Expand Up @@ -2,13 +2,13 @@ class List is also {

=begin item fmt
our Str multi List::fmt ( Str $format, $separator = ' ' )
our Str multi List::fmt ( Str $format = '%s', $separator = ' ' )
Returns the invocant list formatted by an implicit call to C<sprintf> on each
of the elements, then joined with spaces or an explicitly given separator.
=end item
multi method fmt(Str $format, $sep = ' ') is export {
multi method fmt(Str $format = '%s', $sep = ' ') is export {
return join($sep, self.map({ sprintf($format, $^elem) }));
}

Expand Down
4 changes: 2 additions & 2 deletions src/setting/Pair.pm
Expand Up @@ -13,13 +13,13 @@ Delegates on to a method call '.:Xkey(Xval)'.

=begin item fmt
our Str multi Pair::fmt ( Str $format )
our Str multi Pair::fmt ( Str $format = "%s\t%s" )
Returns the invocant pair formatted by an implicit call to C<sprintf> on
the key and value.
=end item
method fmt(Str $format) {
method fmt(Str $format = "%s\t%s") {
return sprintf($format, $.key, $.value);
}

Expand Down

0 comments on commit 99ad1eb

Please sign in to comment.