File Coverage

blib/lib/Text/VisualPrintf.pm
Criterion Covered Total %
statement 26 27 96.3
branch 1 2 50.0
condition 1 2 50.0
subroutine 10 11 90.9
pod 4 4 100.0
total 42 46 91.3


line stmt bran cond sub pod time code
1             package Text::VisualPrintf;
2              
3             our $VERSION = "4.03";
4              
5 14     14   592161 use v5.14;
  14         59  
6 14     14   83 use warnings;
  14         28  
  14         894  
7 14     14   117 use Carp;
  14         30  
  14         1262  
8              
9 14     14   96 use Exporter 'import';
  14         33  
  14         1092  
10             our @EXPORT_OK = qw(&vprintf &vsprintf);
11              
12 14     14   8127 use Data::Dumper;
  14         115794  
  14         1499  
13 14     14   8475 use Text::Conceal;
  14         1017477  
  14         1526  
14              
15 0     0 1 0 sub vprintf { &printf (@_) }
16 3     3 1 615402 sub vsprintf { &sprintf(@_) }
17              
18 14     14   179 use Text::VisualWidth::PP;
  14         32  
  14         5731  
19             our $IS_TARGET = qr/[\e\b\P{ASCII}]/;
20             our $VISUAL_WIDTH = \&Text::VisualWidth::PP::width;
21             our $REORDER //= 0;
22              
23             sub sprintf {
24 597     597 1 2868857 my($format, @args) = @_;
25 597   50     4877 my $conceal = Text::Conceal->new(
26             except => $format,
27             test => $IS_TARGET,
28             length => $VISUAL_WIDTH,
29             max => int @args,
30             ordered => ! $REORDER,
31             duplicate => !!$REORDER,
32             ) || goto &CORE::sprintf;
33 597         47027 ($conceal->decode(CORE::sprintf($format,
34             $conceal->encode(@args))))[0];
35             }
36              
37             sub printf {
38 22 50   22 1 3343615 my $fh = ref($_[0]) =~ /^(?:GLOB|IO::)/ ? shift : select;
39 22         230 $fh->print(&sprintf(@_));
40             }
41              
42             1;
43              
44             __END__