blib/lib/Bot/Cobalt/Common.pm

filter: Statementstmt 100% 270 / 270 Branchbran 70.0% 14 / 20 Conditioncond 50.0% 12 / 24 MC/DCmcdc 23.0% 3 / 13 Subroutinesub 100% 90 / 90 Podpod n/a totaltotal 93.2% 389 / 417 CC 23 SCAR 13.5
CC
23
Cov
94%
import
20.1
__ANON__
3.0
__ANON__
2.0
CRAP 3.9
« blib/lib/Bot/Cobalt/Conf/File/Plugins.pm ↑ Summary blib/lib/Bot/Cobalt/Conf/File/Core.pm »
1 package Bot::Cobalt::Common;
2 $Bot::Cobalt::Common::VERSION = '0.021003';
3 52 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 52 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 52 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 32 ▶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 11 ▶use Bot::Cobalt::Utils ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use IRC::Utils ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use Object::Pluggable::Constants ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use Try::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 11 ▶use Types::Standard ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶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 81 ▶ ->map(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
85 81 my @func_pkg_pairs;
86 81 my $iter = $_->iter;
87 81 ▶ while (my ($pkg, $opts) = $iter->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = &$iter()) 100 80 180
88 281 ▶ $opts->visit(sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
89 281 my $maybe_prefix = substr $_, 0, 1;
90 281 ▶ push @func_pkg_pairs, ($_ => $pkg)
Branch: 1 branch
BranchTrueFalseTotal
unless $maybe_prefix eq ":" or $maybe_prefix eq "-" 250 30 280
Condition100%3/3
$maybe_prefix eq ":" or $maybe_prefix eq "-"
l!l&&r!l&&!r
1020250
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 101 }
95 @func_pkg_pairs
96 81 })
97 ->inflate;
98  
99 55 ▶sub import {
Subroutine import: called CC=20 SCAR=30.0
100 55 my (undef, @items) = @_;
101 55 my $target = caller;
102  
103 55 feature->import( ':5.10' );
104 55 strictures->import::into($target);
105 55 Try::Tiny->import::into($target);
106  
107 55 my $toimport = hash;
108  
109 # : or - prefixed tags are valid, everything else is a func/symbol:
110 55 my (@tags, @funcs);
111 55 for my $item (@items) {
112 49 my $maybe_prefix = substr $item, 0, 1;
113 49 ▶ if ($maybe_prefix eq ':' || $maybe_prefix eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($maybe_prefix eq ':' or $maybe_prefix eq '-') { } 48 0 48
Condition66%2/3
$maybe_prefix eq ":" or $maybe_prefix eq "-"
l!l&&r!l&&!r
4350
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 49 push @tags, lc substr $item, 1;
115 } else {
116 1 push @funcs, $item;
117 }
118 }
119  
120 @tags = $ImportMap->keys->all
121 55 ▶ if grep {; $_ eq 'all' } @tags
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq "all";} @tags or not @tags || @funcs 9 45 54
Condition66%4/6
grep {$_ eq "all";} @tags or not @tags || @funcs
l!l&&r!l&&!r
0945
@tags || @funcs
l!l&&r!l&&!r
4509
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 55 for my $tag (@tags) {
127 121 ▶ my $groups = $ImportMap->get($tag)
Condition50%1/2
$Bot::Cobalt::Common::ImportMap->get($tag) || confess("Import failed; tag '${tag}' not exported")
l!l
1200
MC/DC0%0/1
$Bot::Cobalt::Common::ImportMap->get($tag) || confess("Import failed; tag '${tag}' not exported")
$Bot::Cobalt::Common::ImportMap->get($tag)
Truth table50%1/2
A
A= $Bot::Cobalt::Common::ImportMap->get($tag)
Aresult
11
00
128 || confess "Import failed; tag '$tag' not exported";
129 121 for my $pkg ($groups->keys->all) {
130 187 ▶ if ($toimport->exists($pkg)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($toimport->exists($pkg)) { } 36 150 186
131 37 $toimport->get($pkg)->push( $groups->get($pkg)->all )
132 } else {
133 151 $toimport->set( $pkg => $groups->get($pkg) )
134 }
135 }
136 }
137  
138 # individual symbols:
139 55 for my $func (@funcs) {
140 1 ▶ my $pkg = $FuncMap->get($func)
Condition0%0/2
$FuncMap->get($func) || confess("Import failed; function '${func}' not exported")
l!l
00
MC/DC0%0/1
$FuncMap->get($func) || confess("Import failed; function '${func}' not exported")
$FuncMap->get($func)
Truth table0%0/2
A
A= $FuncMap->get($func)
Aresult
11
00
141 || confess "Import failed; function '$func' not exported";
142 1 ▶ if ($toimport->exists($pkg)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($toimport->exists($pkg)) { } 0 0 0
143 1 $toimport->get($pkg)->push($func)
144 } else {
145 1 $toimport->set( $pkg => array($func) )
146 }
147 }
148  
149 55 my $iter = $toimport->iter;
150 55 my @failed;
151 55 ▶ while (my ($pkg, $optlist) = $iter->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = &$iter()) 150 54 204
152 151 ▶ my $importstr = $optlist->has_any ?
Branch: 1 branch
BranchTrueFalseTotal
$optlist->has_any ? : 150 0 150
153 "use $pkg qw/" . $optlist->uniq->join(' ') . "/;"
154 : "use $pkg;";
155 151 my $c = "package $target; $importstr; 1";
156 151 local $@;
157 11 ▶ eval $c and not $@ or carp $@ and push @failed, $pkg;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval $c and not $@ or carp($@) and push @failed, $pkg 150 0 150
Condition25%2/8
eval $c && !$@ || carp($@) && push(@failed, $pkg)
l!l
1500
eval $c and not $@
!ll&&!rl&&r
00150
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 55 ▶ if (@failed) {
Branch: 1 branch
BranchTrueFalseTotal
if (@failed) 0 54 54
161 1 croak 'Failed to import '. join ', ', @failed
162 }
163  
164 1
165 55 }
166  
167 1;
168 __END__
« blib/lib/Bot/Cobalt/Conf/File/Plugins.pm ↑ Summary blib/lib/Bot/Cobalt/Conf/File/Core.pm »