blib/lib/Bot/Cobalt/Common.pm

filter: Statementstmt 92.8% 78 / 84 Branchbran 70.0% 14 / 20 Conditioncond 46.1% 12 / 26 MC/DCmcdc 20.0% 3 / 15 Subroutinesub 100% 16 / 16 Podpod n/a totaltotal 76.4% 123 / 161 SCAR 33.0
CC
23
Cov
80%
import
31.9
__ANON__
3.0
__ANON__
2.0
CRAP 27.2
« blib/lib/Bot/Cobalt/Plugin/Games/Roulette.pm ↑ Summary blib/lib/Bot/Cobalt/Plugin/RDB/SearchCache.pm »
1 package Bot::Cobalt::Common;
2 $Bot::Cobalt::Common::VERSION = '0.021002';
3 35 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 35 ▶use List::Objects::WithUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 11 ▶use Import::Into;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 10 ▶use Bot::Cobalt::Utils ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use IRC::Utils ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use Object::Pluggable::Constants ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use Try::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 7 ▶use Types::Standard ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 ▶use List::Objects::Types ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 our $ImportMap = hash(
20 string => hash(
21 'Bot::Cobalt::Utils' => array( qw/
22 rplprintf
23 color
24 glob_to_re
25 glob_to_re_str
26 glob_grep
27 / ),
28  
29 'IRC::Utils' => array( qw/
30 lc_irc
31 eq_irc
32 uc_irc
33 decode_irc
34 strip_color
35 strip_formatting
36 / ),
37 ),
38  
39 errors => hash(
40 'Carp' => array(qw/carp croak confess/),
41 ),
42  
43 passwd => hash(
44 'Bot::Cobalt::Utils' => array( qw/ mkpasswd passwdcmp / ),
45 ),
46  
47 time => hash(
48 'Bot::Cobalt::Utils' => array( qw/
49 timestr_to_secs
50 secs_to_timestr
51 secs_to_str
52 secs_to_str_y
53 / ),
54 ),
55  
56 validate => hash(
57 'IRC::Utils' => array( qw/
58 is_valid_nick_name
59 is_valid_chan_name
60 / ),
61 ),
62  
63 host => hash(
64 'IRC::Utils' => array( qw/
65 parse_user
66 normalize_mask
67 matches_mask
68 / ),
69 ),
70  
71 constant => hash(
72 'Object::Pluggable::Constants' => array( ':ALL' ),
73 ),
74  
75 types => hash(
76 'Types::Standard' => array( -types ),
77 'List::Objects::Types' => array( -types ),
78 ),
79 );
80  
81 my $FuncMap =
82 $ImportMap
83 ->values
84 ->map(sub {
85 56 ▶ my @func_pkg_pairs;
Subroutine __ANON__: called CC=2 SCAR=6.9
86 56 my $iter = $_->iter;
87 56 ▶ while (my ($pkg, $opts) = $iter->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = &$iter()) 70 56 126
88 $opts->visit(sub {
89 196 ▶ my $maybe_prefix = substr $_, 0, 1;
Subroutine __ANON__: called CC=3 SCAR=11.0
90 196 ▶ push @func_pkg_pairs, ($_ => $pkg)
Branch: 1 branch
BranchTrueFalseTotal
unless $maybe_prefix eq ":" or $maybe_prefix eq "-" 175 21 196
Condition100%3/3
$maybe_prefix eq ":" or $maybe_prefix eq "-"
l!l&&r!l&&!r
714175
MC/DC100%2/2
$maybe_prefix eq ":" or $maybe_prefix eq "-"
$maybe_prefix eq ":" $maybe_prefix eq "-"
Truth table100%3/3
A or B
A= $maybe_prefix eq ":"B= $maybe_prefix eq "-"
ABresult
1X1
011
000
91 unless $maybe_prefix eq ':'
92 or $maybe_prefix eq '-'
93 })
94 70 }
95 @func_pkg_pairs
96 56 })
97 ->inflate;
98  
99 sub import {
100 17 ▶ my (undef, @items) = @_;
Subroutine import: called CC=20 SCAR=34.6
101 17 my $target = caller;
102  
103 17 feature->import( ':5.10' );
104 17 strictures->import::into($target);
105 17 Try::Tiny->import::into($target);
106  
107 17 my $toimport = hash;
108  
109 # : or - prefixed tags are valid, everything else is a func/symbol:
110 17 my (@tags, @funcs);
111 17 for my $item (@items) {
112 16 my $maybe_prefix = substr $item, 0, 1;
113 16 ▶ if ($maybe_prefix eq ':' || $maybe_prefix eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($maybe_prefix eq ':' or $maybe_prefix eq '-') { } 16 0 16
Condition66%2/3
$maybe_prefix eq ":" or $maybe_prefix eq "-"
l!l&&r!l&&!r
1420
MC/DC0%0/2
$maybe_prefix eq ":" or $maybe_prefix eq "-"
$maybe_prefix eq ":" $maybe_prefix eq "-"
Truth table66%2/3
A or B
A= $maybe_prefix eq ":"B= $maybe_prefix eq "-"
ABresult
1X1
011
000
114 16 push @tags, lc substr $item, 1;
115 } else {
116 0 push @funcs, $item;
117 }
118 }
119  
120 @tags = $ImportMap->keys->all
121 17 ▶ if grep {; $_ eq 'all' } @tags
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq "all";} @tags or not @tags || @funcs 1 16 17
Condition66%4/6
grep {$_ eq "all";} @tags or not @tags || @funcs
l!l&&r!l&&!r
0116
@tags || @funcs
l!l&&r!l&&!r
1601
MC/DC33%1/3
grep {$_ eq "all";} @tags or not @tags || @funcs
grep {$_ eq "all";} @tags @tags @funcs
Truth table50%2/4
A or not(B || C)
A= grep {$_ eq "all";} @tagsB= @tagsC= @funcs
ABCresult
1XX1
0001
01X0
0010
122 # empty import implies all:
123 or !@tags and !@funcs;
124  
125 # groups/tags:
126 17 for my $tag (@tags) {
127 24 ▶ my $groups = $ImportMap->get($tag)
Condition33%1/3
$Bot::Cobalt::Common::ImportMap->get($tag) || confess("Import failed; tag '${tag}' not exported")
l!l&&r!l&&!r
2400
MC/DC0%0/2
$Bot::Cobalt::Common::ImportMap->get($tag) || confess("Import failed; tag '${tag}' not exported")
$Bot::Cobalt::Common::ImportMap->get($tag) confess("Import failed; tag '${tag}' not exported")
Truth table33%1/3
A || B
A= $Bot::Cobalt::Common::ImportMap->get($tag)B= confess("Import failed; tag '${tag}' not exported")
ABresult
1X1
011
000
128 || confess "Import failed; tag '$tag' not exported";
129 24 for my $pkg ($groups->keys->all) {
130 42 ▶ if ($toimport->exists($pkg)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($toimport->exists($pkg)) { } 4 38 42
131 4 $toimport->get($pkg)->push( $groups->get($pkg)->all )
132 } else {
133 38 $toimport->set( $pkg => $groups->get($pkg) )
134 }
135 }
136 }
137  
138 # individual symbols:
139 17 for my $func (@funcs) {
140 0 ▶ my $pkg = $FuncMap->get($func)
Condition0%0/3
$FuncMap->get($func) || confess("Import failed; function '${func}' not exported")
l!l&&r!l&&!r
000
MC/DC0%0/2
$FuncMap->get($func) || confess("Import failed; function '${func}' not exported")
$FuncMap->get($func) confess("Import failed; function '${func}' not exported")
Truth table0%0/3
A || B
A= $FuncMap->get($func)B= confess("Import failed; function '${func}' not exported")
ABresult
1X1
011
000
141 || confess "Import failed; function '$func' not exported";
142 0 ▶ if ($toimport->exists($pkg)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($toimport->exists($pkg)) { } 0 0 0
143 0 $toimport->get($pkg)->push($func)
144 } else {
145 0 $toimport->set( $pkg => array($func) )
146 }
147 }
148  
149 17 my $iter = $toimport->iter;
150 17 my @failed;
151 17 ▶ while (my ($pkg, $optlist) = $iter->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = &$iter()) 38 17 55
152 38 ▶ my $importstr = $optlist->has_any ?
Branch: 1 branch
BranchTrueFalseTotal
$optlist->has_any ? : 38 0 38
153 "use $pkg qw/" . $optlist->uniq->join(' ') . "/;"
154 : "use $pkg;";
155 38 my $c = "package $target; $importstr; 1";
156 38 local $@;
157 7 ▶ eval $c and not $@ or carp $@ and push @failed, $pkg;
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
eval $c and not $@ or carp($@) and push @failed, $pkg 0 38 38
Condition25%2/8
eval $c && !$@ || carp($@) && push(@failed, $pkg)
l!l
380
eval $c and not $@
!ll&&!rl&&r
0038
carp($@) and push @failed, $pkg
!ll&&!rl&&r
000
MC/DC0%0/4
eval $c && !$@ || carp($@) && push(@failed, $pkg)
eval $c not $@ carp($@) push @failed, $pkg
Truth table14%1/7
A and not(B) || C and D
A= eval $cB= not $@C= carp($@)D= push @failed, $pkg
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
158 }
159  
160 17 ▶ if (@failed) {
Branch: 1 branch
BranchTrueFalseTotal
if (@failed) 0 17 17
161 0 croak 'Failed to import '. join ', ', @failed
162 }
163  
164 1
165 17 }
166  
167 1;
168 __END__
« blib/lib/Bot/Cobalt/Plugin/Games/Roulette.pm ↑ Summary blib/lib/Bot/Cobalt/Plugin/RDB/SearchCache.pm »