Skip Menu |

This queue is for tickets about the Term-Sk CPAN distribution.

Report information
The Basics
Id: 57903
Status: resolved
Priority: 0/
Queue: Term-Sk

People
Owner: KEICHNER [...] cpan.org
Requestors: avar [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.05
Fixed in: (no value)



Subject: Allow for overriding commify
If I don't like 100_000 and want to turn it into 100,000 (or 100.000) I have to subclass Term::Sk and override commify. It would be nice if this was either documented, or preferably that there was an optional callaback you could supply when constructing the object. E.g.: my $sk = Term::Sk->new( commify => sub { ... } ... );
RT-Send-CC: avar [...] cpan.org, klaus03 [...] gmail.com
Le Jeu 27 Mai 2010 08:36:38, AVAR a écrit : Show quoted text
> If I don't like 100_000 and want to turn it into 100,000 (or 100.000) I > have to subclass Term::Sk and override commify. It would be nice if this > was either documented, or preferably that there was an optional callaback > you could supply when constructing the object. E.g.: > > my $sk = Term::Sk->new( > commify => sub { ... } > ... > );
Thanks for your message, I think will incorporate a callback. I expect that I will find some time next week to implement the changes. -- Klaus
RT-Send-CC: klaus03 [...] gmail.com
Le Jeu 27 Mai 2010 09:30:18, KEICHNER a écrit : Show quoted text
> Le Jeu 27 Mai 2010 08:36:38, AVAR a écrit :
> > If I don't like 100_000 and want to turn it into 100,000 (or 100.000) I > > have to subclass Term::Sk and override commify. It would be nice if
this Show quoted text
> > was either documented, or preferably that there was an optional
callaback Show quoted text
> > you could supply when constructing the object. E.g.: > > > > my $sk = Term::Sk->new( > > commify => sub { ... } > > ... > > );
> > Thanks for your message, > I think will incorporate a callback. > > I expect that I will find some time next week to implement the changes. > > -- > Klaus
I have released Term::Sk ver 0.06 Here is a showcase: use strict; use warnings; use Term::Sk; { print qq|Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9,999} } );\n|; my $ctr = Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9,999} } ); print "Result: ", content($ctr->get_line), "\n\n"; } { print qq|Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9 999} } );\n|; my $ctr = Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9 999} } ); print "Result: ", content($ctr->get_line), "\n\n"; } { print qq|Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9_999} } );\n|; my $ctr = Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9_999} } ); print "Result: ", content($ctr->get_line), "\n\n"; } { print qq|Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9_99} } );\n|; my $ctr = Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9_99} } ); print "Result: ", content($ctr->get_line), "\n\n"; } { print qq|Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9} } );\n|; my $ctr = Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9} } ); print "Result: ", content($ctr->get_line), "\n\n"; } { print qq|Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9'999} } );\n|; my $ctr = Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9'999} } ); print "Result: ", content($ctr->get_line), "\n\n"; } { print qq|Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, commify => sub{ join '!', split m{}xms, \$_[0]; } });\n|; my $ctr = Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, commify => sub{ join '!', split m{}xms, $_[0]; } }); print "Result: ", content($ctr->get_line), "\n\n"; } sub content { my ($text) = @_; $text =~ s{^ \010+ \s+ \010+}{}xms; return $text; } ***************************************************** And this is the output: ***************************************************** Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9,999} } ); Result: num 1,234,567 of 2,345,678 Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9 999} } ); Result: num 1 234 567 of 2 345 678 Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9_999} } ); Result: num 1_234_567 of 2_345_678 Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9_99} } ); Result: num 1_23_45_67 of 2_34_56_78 Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9} } ); Result: num 1234567 of 2345678 Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, num => q{9'999} } ); Result: num 1'234'567 of 2'345'678 Term::Sk->new('num %c of %m', { test => 1, base => 1234567, target => 2345678, commify => sub{ join '!', split m{}xms, $_[0]; } }); Result: num 1!2!3!4!5!6!7 of 2!3!4!5!6!7!8 ***************************************************** If you agree, I will close this ticket. -- Klaus
On Sat May 29 13:18:02 2010, KEICHNER wrote: Show quoted text
> If you agree, I will close this ticket.
Thanks. I've tested it and it works perfectly.