File Coverage

blib/lib/Data/Unixish/centerpad.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod 1 1 100.0
total 35 35 100.0


line stmt bran cond sub pod time code
1             package Data::Unixish::centerpad;
2              
3 1     1   453 use 5.010;
  1         5  
4 1     1   369 use locale;
  1         516  
  1         5  
5 1     1   33 use strict;
  1         3  
  1         52  
6 1     1   344 use syntax 'each_on_array'; # to support perl < 5.12
  1         19901  
  1         5  
7 1     1   2920 use warnings;
  1         2  
  1         22  
8             #use Log::Any '$log';
9              
10 1     1   381 use Data::Unixish::_pad;
  1         4  
  1         36  
11 1     1   386 use Data::Unixish::Util qw(%common_args);
  1         2  
  1         263  
12              
13             our $VERSION = '1.572'; # VERSION
14              
15             our %SPEC;
16              
17             $SPEC{centerpad} = {
18             v => 1.1,
19             summary => 'Center text to a certain column width',
20             description => <<'_',
21              
22             This function can handle text containing wide characters and ANSI escape codes.
23              
24             Note: to center to a certain character length instead of column width (note that
25             wide characters like Chinese can have width of more than 1 column in terminal),
26             you can turn of `mb` option even when your text contains wide characters.
27              
28             _
29             args => {
30             %common_args,
31             width => {
32             schema => ['int*', min => 0],
33             req => 1,
34             pos => 0,
35             cmdline_aliases => { w => {} },
36             },
37             ansi => {
38             summary => 'Whether to handle ANSI escape codes',
39             schema => ['bool', default => 0],
40             },
41             mb => {
42             summary => 'Whether to handle wide characters',
43             schema => ['bool', default => 0],
44             },
45             char => {
46             summary => 'Character to use for padding',
47             schema => ['str*', len=>1, default=>' '],
48             description => <<'_',
49              
50             Character should have column width of 1. The default is space (ASCII 32).
51              
52             _
53             cmdline_aliases => { c => {} },
54             },
55             trunc => {
56             summary => 'Whether to truncate text wider than specified width',
57             schema => ['bool', default => 0],
58             },
59             },
60             tags => [qw/itemfunc text/],
61             };
62             sub centerpad {
63 2     2 1 7 my %args = @_;
64 2         9 Data::Unixish::_pad::_pad("c", %args);
65             }
66              
67 2     2   7 sub _centerpad_begin { Data::Unixish::_pad::__pad_begin('c', @_) }
68 12     12   20 sub _centerpad_item { Data::Unixish::_pad::__pad_item('c', @_) }
69              
70             1;
71             # ABSTRACT: Center text to a certain column width
72              
73             __END__