| 1 | #! perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Text::Layout::Utils; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use v5.26; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use feature qw( signatures ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | no warnings "experimental::signatures"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 8 | our @EXPORT; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # Split (pseudo) command line into key/value pairs. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | sub parse_kv ( @lines ) { | ||||||||||||||||||||||||||
|
Subroutine
parse_kv: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 8 | ▶ | use Text::ParseWords qw(shellwords); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 2 | my @words = shellwords(@lines); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | my $res = {}; | |||||||||||||||||||||||||||
| 22 | 2 | foreach ( @words ) { | |||||||||||||||||||||||||||
| 23 | 3 | ▶ | if ( /^(.*?)=(.+)/ ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 24 | 3 | $res->{$1} = $2; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | elsif ( /^no[-_]?(.+)/ ) { | ||||||||||||||||||||||||||||
| 27 | 0 | $res->{$1} = 0; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | else { | ||||||||||||||||||||||||||||
| 30 | 0 | $res->{$_}++; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 2 | return $res; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 8 | push( @EXPORT, 'parse_kv' ); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # Remove markup. | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub demarkup ( $t ) { | ||||||||||||||||||||||||||
|
Subroutine
demarkup: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 0 | return join( '', grep { ! /^\</ } splitmarkup($t) ); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 8 | push( @EXPORT, 'demarkup' ); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # Split into markup/nonmarkup segments. | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub splitmarkup ( $t ) { | ||||||||||||||||||||||||||
|
Subroutine
splitmarkup: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 0 | my @t = split( qr;(</?(?:[-\w]+|span\s.*?)>);, $t ); | |||||||||||||||||||||||||||
| 48 | 0 | return @t; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 8 | push( @EXPORT, 'splitmarkup' ); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # For conditional filling of hashes. | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub maybe ( $key, $value, @rest ) { | ||||||||||||||||||||||||||
|
Subroutine
maybe: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if (defined $key and defined $value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $key and defined $value
MC/DC0%0/2
defined $key and defined $value
defined $key
defined $value
Truth table0%0/3
A and B
A= defined $keyB= defined $value
| |||||||||||||||||||||||||||||
| 55 | 0 | return ( $key, $value, @rest ); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | else { | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | ( defined($key) || @rest ) ? @rest : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $key or @rest
MC/DC0%0/2
defined $key or @rest
defined $key
@rest
Truth table0%0/3
A or B
A= defined $keyB= @rest
| |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 8 | push( @EXPORT, "maybe" ); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # Min/Max. | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub min { $_[0] < $_[1] ? $_[0] : $_[1] } | ||||||||||||||||||||||||||
|
Subroutine
min: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub max { $_[0] > $_[1] ? $_[0] : $_[1] } | ||||||||||||||||||||||||||
|
Subroutine
max: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 8 | push( @EXPORT, "min", "max" ); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 8 | 1; | |||||||||||||||||||||||||||