Zest/Author/TABULO/Util/Text.pm

filter: Statementstmt 95.8% 46 / 48 Branchbran 70.0% 7 / 10 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 83.5% 66 / 79 CC 11 SCAR 13.4
CC
11
Cov
89%
lines_utf8_from
6.3
strip_comments
5.0
undent
2.0
CRAP 3.8
« Zest/Author/TABULO/Util/Mayhap.pm ↑ Summary Pod/Wordlist/Author/TABULO.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Zest::Author::TABULO::Util::Text;
5 2 our $VERSION = '1.000014';
6  
7 2 ▶use Text::Trim qw(trim);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Exporter::Shiny qw( docstr lines_utf8_from strip_comments trim undent);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #region: #== UTILITY FUNCTIONS (EXPORT_OK) ==
11  
12 10 ▶sub lines_utf8_from { # function
Subroutine lines_utf8_from: called CC=6 SCAR=18.4
Pod undocumented
13 10 my ( @res, @lines );
14  
15 10 ARG: for my $arg (@_) {
16 10 ▶ my $ref = ref $arg // '';
Condition50%1/2
ref $arg // ""
l!l
100
MC/DC0%0/1
ref $arg // ""
ref $arg
Truth table50%1/2
A
A= ref $arg
Aresult
11
00
17 10 ▶ if ( $ref and my $lines_utf8 = eval { $arg->can('lines_utf8') } ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ref and my $lines_utf8 = eval { do { $arg->can('lines_utf8') } }) { } 4 6 10
elsif ($ref =~ /^IO$/) { } 0 6 6
Condition66%2/3
$ref and my $lines_utf8 = eval { do { $arg->can("lines_utf8") } }
!ll&&!rl&&r
604
MC/DC50%1/2
$ref and my $lines_utf8 = eval { do { $arg->can("lines_utf8") } }
$ref my $lines_utf8 = eval { do { $arg->can("lines_utf8") } }
Truth table66%2/3
A and B
A= $refB= my $lines_utf8 = eval { do { $arg->can("lines_utf8") } }
ABresult
0X0
100
111
18 4 @lines = $lines_utf8->($arg);
19 } elsif ( $ref =~ m/^IO$/ ) {
20 0 @lines = <$arg>;
21 } else { # assume simple SCALAR
22 6 @lines = split /\n/, $arg;
23 }
24 10 chomp(@lines);
25 10 push @res, @lines;
26 }
27 10 @res;
28 }
29  
30 10 ▶sub strip_comments { # function
Subroutine strip_comments: called CC=5 SCAR=16.1
Pod undocumented
31 10 my @res;
32 10 ARG: for my $arg (@_) {
33 384 my @lines = split /\n/, $arg;
34 384 LINE: for (@lines) {
35 340 chomp; s!^\s+!!; s!\s+$!!; # chomp & trim white space
36 340 ▶ next LINE if m/^\s*[#]/; # skip line comments
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*[#]/ 40 300 340
37 300 s!\s+[#].*$!!; # strip side comments
38 300 ▶ next LINE unless "$_"; # skip blank lines.
Branch: 1 branch
BranchTrueFalseTotal
unless "$_" 0 300 300
39 300 push @res, $_;
40 }
41 }
42 10 @res;
43 }
44  
45 # [TAU]: Shamelessly copied from: [Filter::Undent](https://metacpan.org/release/KILNA/Filter-Undent-v1.0.3/view/lib/Filter/Undent.pm)
46 36 ▶sub undent ($) { ## no critic
Subroutine undent: called CC=2 SCAR=7.0
Pod undocumented
47 2 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
48 36 ▶ if ( $_[0] =~ m/^(\r?\n)*([ \t]+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^(\r?\n)*([ \t]+)/) 36 0 36
49 36 my $i = $2;
50 36 return join '', map { s/^\Q$i\E/$1/g; $_ } grep { $_ ne '' }
51 split /(.*?\n)/, $_[0];
52 }
53 0 return $_[0];
54 }
55  
56 36 ▶sub docstr {
Subroutine docstr: called CC=1 SCAR=0.0
Pod undocumented
57 36 trim(undent(join("\n", @_)))
58 }
59  
60  
61 #endregion (UTILITY FUNCTIONS)
62  
63 2 1;
64  
65 =pod
66  
67 =encoding UTF-8
68  
69 =for :stopwords Tabulo[n]
70  
71 =head1 NAME
72  
73 Zest::Author::TABULO::Util::Text - DZIL-related utility functions used by TABULO's authoring dist
74  
75 =head1 VERSION
76  
77 version 1.000014
78  
79 =for Pod::Coverage docstr lines_utf8_from strip_comments trim undent
80  
81 =head1 AUTHORS
82  
83 Tabulo[n] <dev@tabulo.net>
84  
85 =head1 LEGAL
86  
87 This software is copyright (c) 2023 by Tabulo[n].
88  
89 This is free software; you can redistribute it and/or modify it under
90 the same terms as the Perl 5 programming language system itself.
91  
92 =cut
93  
94 __END__
« Zest/Author/TABULO/Util/Mayhap.pm ↑ Summary Pod/Wordlist/Author/TABULO.pm »