From 99ad1eba788968e9d758e4a381c691691b96286e Mon Sep 17 00:00:00 2001 From: Carl Masak Date: Tue, 7 Jul 2009 00:12:08 +0200 Subject: [PATCH] added $format default to all .fmt variants --- src/classes/Mapping.pir | 13 +++++++++---- src/setting/Any-str.pm | 2 +- src/setting/List.pm | 4 ++-- src/setting/Pair.pm | 4 ++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/classes/Mapping.pir b/src/classes/Mapping.pir index 7e006f7dee7..6b54d327f6b 100644 --- a/src/classes/Mapping.pir +++ b/src/classes/Mapping.pir @@ -28,7 +28,7 @@ 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. @@ -36,13 +36,18 @@ 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" diff --git a/src/setting/Any-str.pm b/src/setting/Any-str.pm index 1b7304f2409..e0f4f3079ca 100644 --- a/src/setting/Any-str.pm +++ b/src/setting/Any-str.pm @@ -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) } diff --git a/src/setting/List.pm b/src/setting/List.pm index cd5fe357c17..cf079ef5674 100644 --- a/src/setting/List.pm +++ b/src/setting/List.pm @@ -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 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) })); } diff --git a/src/setting/Pair.pm b/src/setting/Pair.pm index fd2764e6794..8e19bcdfd56 100644 --- a/src/setting/Pair.pm +++ b/src/setting/Pair.pm @@ -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 on the key and value. =end item - method fmt(Str $format) { + method fmt(Str $format = "%s\t%s") { return sprintf($format, $.key, $.value); }