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