File Coverage

blib/lib/Text/ANSI/Printf.pm
Criterion Covered Total %
statement 24 24 100.0
branch 1 2 50.0
condition 1 2 50.0
subroutine 10 10 100.0
pod 4 4 100.0
total 40 42 95.2


line stmt bran cond sub pod time code
1             package Text::ANSI::Printf;
2              
3             our $VERSION = "2.07";
4              
5 9     9   439205 use v5.14;
  9         34  
6 9     9   51 use warnings;
  9         19  
  9         563  
7 9     9   67 use Carp;
  9         15  
  9         825  
8              
9 9     9   56 use Exporter 'import';
  9         22  
  9         1306  
10             our @EXPORT_OK = qw(&ansi_printf &ansi_sprintf);
11              
12 9     9 1 33 sub ansi_printf { &printf (@_) }
13 31     31 1 709207 sub ansi_sprintf { &sprintf(@_) }
14              
15 9     9   5069 use Text::Conceal;
  9         689570  
  9         443  
16 9     9   5103 use Text::ANSI::Fold::Util qw(ansi_width);
  9         7895  
  9         3214  
17              
18             our $REORDER //= 0;
19              
20             sub sprintf {
21 102     102 1 1378236 my($format, @args) = @_;
22 102   50     1001 my $conceal = Text::Conceal->new(
23             except => $format,
24             max => int @args,
25             test => qr/[\e\b\P{ASCII}]/,
26             length => \&ansi_width,
27             ordered => ! $REORDER,
28             duplicate => !!$REORDER,
29             ) || goto &CORE::sprintf;
30 102         7440 ($conceal->decode(CORE::sprintf($format,
31             $conceal->encode(@args))))[0];
32             }
33              
34             sub printf {
35 9 50   9 1 45 my $fh = ref($_[0]) =~ /^(?:GLOB|IO::)/ ? shift : select;
36 9         32 $fh->print(&sprintf(@_));
37             }
38              
39             1;
40              
41             __END__