RegMgr/Utils.pm

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