Zest/Author/TABULO/Util/Dzil.pm

filter: Statementstmt 100% 46 / 46 Branchbran 80.0% 8 / 10 Conditioncond 54.1% 13 / 24 MC/DCmcdc 20.0% 3 / 15 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 74.0% 77 / 104 CC 16 SCAR 22.9
CC
16
Cov
84%
grok_plugin
15.6
grok_plugins
5.0
BEGIN
1.0
CRAP 9.9
« Zest/Author/TABULO/MungersForHas.pm ↑ Summary Zest/Author/TABULO/Util/ShareDir.pm »
1  
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Zest::Author::TABULO::Util::Dzil;
6 2 our $VERSION = '1.000014';
7  
8 2 ▶use Data::OptList;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Text::Trim;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Exporter::Shiny qw( grok_plugin grok_plugins);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 #region: #== UTILITY FUNCTIONS (EXPORT_OK) ==
14  
15 ## no critic: Prototypes
16 128 ▶sub grok_plugin($) { # single plugin ()
Subroutine grok_plugin: called CC=12 SCAR=27.5
Pod undocumented
17 128 local $_;
18 128 my (@plugin) = @{$_[0]}; # MUST be an ARRAY ref.
19 128 ▶ my $v = ref $plugin[$#plugin] ? pop @plugin : {}; # options
Branch: 1 branch
BranchTrueFalseTotal
ref $plugin[$#plugin] ? : 54 74 128
20 128 ▶ my $k = join '/', grep {; defined && $_ ne '' } map {; $_= trim($_ // '') } (@plugin);
Condition80%4/5
defined $_ && $_ ne ''
!ll&&!rl&&r
074132
$_ // ""
l!l
13274
MC/DC50%1/2
defined $_ && $_ ne ''
defined $_ $_ ne ''
MC/DC100%1/1
$_ // ""
$_
Truth table66%2/3
A && B
A= defined $_B= $_ ne ''
ABresult
0X0
100
111
Truth table100%2/2
A
A= $_
Aresult
11
00
21  
22 128 my ( $moniker, $label ) = split( qr{\s*/\s*}, $k, 2 );
23 128 ▶ ( $moniker, $label ) = (trim($moniker //= ''), trim($label //= ''));
Condition75%3/4
$moniker //= ""
l!l
1280
$label //= ""
l!l
9119
MC/DC0%0/1
$moniker //= ""
$moniker
MC/DC100%1/1
$label //= ""
$label
Truth table50%1/2
A
A= $moniker
Aresult
11
00
Truth table100%2/2
A
A= $label
Aresult
11
00
24 128 $label =~ s!\A$moniker\Z!!; # in case it starts with that
25 128 ▶ my $name = join('/', $moniker || (), $label || ());
Condition50%3/6
$moniker || ()
l!l&&r!l&&!r
12800
$label || ()
l!l&&r!l&&!r
51230
MC/DC0%0/2
$moniker || ()
$moniker ()
MC/DC0%0/2
$label || ()
$label ()
Truth table33%1/3
A || B
A= $monikerB= ()
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $labelB= ()
ABresult
1X1
011
000
26  
27 128 ▶ my $p = [ $moniker || (), $name || (), $v // () ];
Condition33%3/9
$moniker || ()
l!l&&r!l&&!r
12800
$name || ()
l!l&&r!l&&!r
12800
$v // ()
l!l&&r!l&&!r
12800
MC/DC0%0/2
$moniker || ()
$moniker ()
MC/DC0%0/2
$name || ()
$name ()
MC/DC0%0/2
$v // ()
$v ()
Truth table33%1/3
A || B
A= $monikerB= ()
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $nameB= ()
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $vB= ()
ABresult
1X1
011
000
28 128 ▶ @$p ? $p : ()
Branch: 1 branch
BranchTrueFalseTotal
@$p ? : 128 0 128
29 }
30  
31 128 ▶sub grok_plugins { # One or more plugins. Lax style (can be a mix of ARRAY-refs and (k => v) pairs )
Subroutine grok_plugins: called CC=5 SCAR=16.1
Pod undocumented
32 128 local $_;
33 128 my (@args) = @_;
34 128 my ( @res, @input );
35  
36 128 for my $arg (@args) {
37 173 ▶ if ( ref($arg) =~ m/ARRAY/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($arg) =~ /ARRAY/) { } 9 164 173
38 9 ▶ push @res, grok_plugins(@input) if @input; # recurse!
Branch: 1 branch
BranchTrueFalseTotal
if @input 0 9 9
39 9 push @res, grok_plugin($arg);
40 9 @input = ();
41 } else {
42 164 push @input, $arg;
43 }
44 }
45 128 ▶ if (@input) {
Branch: 1 branch
BranchTrueFalseTotal
if (@input) 119 9 128
46  
47 119 my %prefs = (
48 moniker => 'plugins',
49 require_unique => 1,
50 must_be => [qw(HASH)],
51 );
52 119 my @optlist = @{ Data::OptList::mkopt( \@input, \%prefs ) };
53  
54 push @res, map {
55 119 grok_plugin($_);
56 } @optlist;
57 }
58  
59 # say STDERR "Grokked plugins: "; p @res;
60 128 @res;
61 }
62  
63  
64  
65  
66 #endregion (UTILITY FUNCTIONS)
67  
68 2 1;
69  
70 =pod
71  
72 =encoding UTF-8
73  
74 =for :stopwords Tabulo[n]
75  
76 =head1 NAME
77  
78 Zest::Author::TABULO::Util::Dzil - DZIL-related utility functions used by TABULO's authoring dist
79  
80 =head1 VERSION
81  
82 version 1.000014
83  
84 =for Pod::Coverage grok_plugin grok_plugins
85  
86 =head1 AUTHORS
87  
88 Tabulo[n] <dev@tabulo.net>
89  
90 =head1 LEGAL
91  
92 This software is copyright (c) 2023 by Tabulo[n].
93  
94 This is free software; you can redistribute it and/or modify it under
95 the same terms as the Perl 5 programming language system itself.
96  
97 =cut
98  
99 __END__
« Zest/Author/TABULO/MungersForHas.pm ↑ Summary Zest/Author/TABULO/Util/ShareDir.pm »