File Coverage

blib/lib/Text/Layout/Utils.pm
Criterion Covered Total %
statement 29 51 56.8
branch 1 12 8.3
condition 0 6 0.0
subroutine 8 13 61.5
pod 0 6 0.0
total 38 88 43.1


line stmt bran cond sub pod time code
1             #! perl
2              
3             package Text::Layout::Utils;
4              
5 8     8   124 use v5.26;
  8         30  
6 8     8   61 use utf8;
  8         36  
  8         64  
7 8     8   296 use Carp;
  8         25  
  8         2695  
8 8     8   61 use feature qw( signatures );
  8         11  
  8         1637  
9 8     8   56 no warnings "experimental::signatures";
  8         15  
  8         486  
10              
11 8     8   45 use Exporter 'import';
  8         32  
  8         852  
12             our @EXPORT;
13              
14             # Split (pseudo) command line into key/value pairs.
15              
16 2     2 0 5 sub parse_kv ( @lines ) {
  2         5  
  2         4  
17              
18 8     8   4674 use Text::ParseWords qw(shellwords);
  8         15334  
  8         24872  
19 2         9 my @words = shellwords(@lines);
20              
21 2         480 my $res = {};
22 2         6 foreach ( @words ) {
23 3 50       17 if ( /^(.*?)=(.+)/ ) {
    0          
24 3         13 $res->{$1} = $2;
25             }
26             elsif ( /^no[-_]?(.+)/ ) {
27 0         0 $res->{$1} = 0;
28             }
29             else {
30 0         0 $res->{$_}++;
31             }
32             }
33              
34 2         16 return $res;
35             }
36              
37             push( @EXPORT, 'parse_kv' );
38              
39             # Remove markup.
40 0     0 0   sub demarkup ( $t ) {
  0            
  0            
41 0           return join( '', grep { ! /^\
  0            
42             }
43             push( @EXPORT, 'demarkup' );
44              
45             # Split into markup/nonmarkup segments.
46 0     0 0   sub splitmarkup ( $t ) {
  0            
  0            
47 0           my @t = split( qr;();, $t );
48 0           return @t;
49             }
50             push( @EXPORT, 'splitmarkup' );
51              
52             # For conditional filling of hashes.
53 0     0 0   sub maybe ( $key, $value, @rest ) {
  0            
  0            
  0            
  0            
54 0 0 0       if (defined $key and defined $value) {
55 0           return ( $key, $value, @rest );
56             }
57             else {
58 0 0 0       ( defined($key) || @rest ) ? @rest : ();
59             }
60             }
61             push( @EXPORT, "maybe" );
62              
63             # Min/Max.
64 0 0   0 0   sub min { $_[0] < $_[1] ? $_[0] : $_[1] }
65 0 0   0 0   sub max { $_[0] > $_[1] ? $_[0] : $_[1] }
66              
67             push( @EXPORT, "min", "max" );
68              
69             1;