RegMgr/Utils.pm

filter: Statementstmt 47.3% 35 / 74 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 68.7% 11 / 16 Podpod 100% 5 / 5 totaltotal 38.9% 51 / 131 CC 18 SCAR 34.5
CC
18
Cov
33%
run_callback
72.0
parse_svc
56.0
attr
12.0
CRAP 31.5
« RegMgr.pm ↑ Summary RegMgr/Monitor.pm »
1 package Inferno::RegMgr::Utils;
2 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = 'v1.0.0';
9  
10 1 ▶use Export::Attrs;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 0 ▶sub quote :Export {
Subroutine quote: not called CC=2 SCAR=17.9
Pod documented
14 0 my ($s) = @_;
15 0 ▶ if ($s =~ / \s | ' | \A\z /xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ / \s | ' | \A\z /msx) 0 0 0
16 0 $s =~ s/'/''/xmsg;
17 0 $s = "'$s'";
18 }
19 0 return $s;
20 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 0 ▶sub unquote :Export {
Subroutine unquote: not called CC=2 SCAR=17.9
Pod documented
23 0 my ($s) = @_;
24 0 ▶ if ($s =~ s/\A'(.*)'\z/$1/xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ s/\A'(.*)'\z/$1/msx) 0 0 0
25 0 $s =~ s/''/'/xmsg;
26 }
27 0 return $s;
28 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 0 ▶sub attr :Export {
Subroutine attr: not called CC=3 SCAR=24.8
Pod documented
31 0 my ($attr) = @_;
32 0 my @s;
33 0 ▶ while (my ($k, $v) = each %{ $attr || {} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$attr or {};}) 0 0 0
Condition0%0/2
$attr || {}
l!l
00
MC/DC0%0/1
$attr || {}
$attr
Truth table0%0/2
A
A= $attr
Aresult
11
00
34 0 push @s, sprintf '%s %s', quote($k), quote($v);
35 }
36 0 return join q{ }, @s;
37 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 0 ▶sub parse_svc :Export {
Subroutine parse_svc: not called CC=7 SCAR=40.3
Pod documented
40 0 my ($s) = @_;
41 0 state $qword = qr{( [^'\s]+ | '[^']*(?:''[^']*)*' )}xms;
42 0 ▶ return ({}, undef) if $s eq q{};
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "" 0 0 0
43 0 ▶ return (undef, 'no \\n at end') if $s !~ /\n\z/xms;
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /\n\z/msx 0 0 0
44 0 my %svc;
45 0 for my $line (split /\n/xms, $s) {
46 0 my $errmsg = "can't parse service: $line";
47 0 ▶ return (undef, $errmsg) if $line !~ s/\A$qword//xms;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ s/\A$qword//msx 0 0 0
48 0 my $name = unquote($1); ## no critic (ProhibitCaptureWithoutTest)
49 0 my %attr;
50 0 ▶ while (length $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $line) 0 0 0
51 0 ▶ return (undef, $errmsg) if $line !~ s/\s$qword\s$qword//xms;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ s/\s$qword\s$qword//msx 0 0 0
52 0 my ($attr, $value) = ($1, $2); ## no critic (ProhibitCaptureWithoutTest)
53 0 $attr{ unquote($attr) } = unquote($value);
54 }
55 0 $svc{$name} = \%attr;
56 }
57 0 return (\%svc, undef);
58 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 1 my $STDREF = qr{SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE}xms;
61 0 ▶sub run_callback :Export {
Subroutine run_callback: not called CC=8 SCAR=42.8
Pod documented
62 0 ▶ croak 'usage: run_callback( CB [, METHOD [, @ARGS]] )' if @_ < 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 1 0 0 0
63 0 my ($cb, $method) = (shift, shift);
64 0 ▶ my $cb_type
Branch: 3 branches
BranchTrueFalseTotal
!ref($cb) ? : 0 0 0
ref $cb eq 'CODE' ? : 0 0 0
!(ref($cb) =~ /\A$STDREF\z/mosx) ? : 0 0 0
65 = !ref($cb) ? 'CLASS'
66 : ref($cb) eq 'CODE' ? 'CODE'
67 : ref($cb) !~ m{\A$STDREF\z}xmso ? 'OBJECT'
68 : undef
69 ;
70 0 ▶ if ($cb_type eq 'CLASS' || $cb_type eq 'OBJECT') {
Branch: 2 branches
BranchTrueFalseTotal
if ($cb_type eq 'CLASS' or $cb_type eq 'OBJECT') { } 0 0 0
elsif ($cb_type eq 'CODE') { } 0 0 0
Condition0%0/3
$cb_type eq "CLASS" or $cb_type eq "OBJECT"
l!l&&r!l&&!r
000
MC/DC0%0/2
$cb_type eq "CLASS" or $cb_type eq "OBJECT"
$cb_type eq "CLASS" $cb_type eq "OBJECT"
Truth table0%0/3
A or B
A= $cb_type eq "CLASS"B= $cb_type eq "OBJECT"
ABresult
1X1
011
000
71 0 $cb->$method(@_);
72 }
73 elsif ($cb_type eq 'CODE') {
74 0 $cb->(@_);
75 }
76 else {
77 0 croak qq{run_callback: wrong CB $cb};
78 }
79 0 return;
80 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82  
83  
84 1 1; # Magic true value required at end of module
85 __END__
« RegMgr.pm ↑ Summary RegMgr/Monitor.pm »