blib/lib/Test2/Tools/Tester.pm

filter: Statementstmt 97.8% 91 / 93 Branchbran 86.6% 26 / 30 Conditioncond 55.5% 5 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 11 / 11 Podpod 33.3% 1 / 3 totaltotal 89.4% 135 / 151 CC 19 SCAR 16.7
CC
19
Cov
92%
facets
9.0
event_groups
6.0
filter_events
5.0
CRAP 5.3
« blib/lib/Test2/Event/V2.pm ↑ Summary blib/lib/Test2/Util/Sub.pm »
1 package Test2::Tools::Tester;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.302226';
6  
7 1 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Test2::Util::Ref qw/rtype/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
11 1 ▶ if (eval {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { BEGIN {${^WARNING_BITS} = "\x45\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x51\x55\x55\x10\x55\x55\x55"} require Module::Pluggable; 1 } }) { } 0 1 1
12 1 ▶ no warnings 'deprecated';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 require Module::Pluggable;
14 0 1;
15 }) {
16 0 Module::Pluggable->import(search_path => ['Test2::EventFacet'], require => 1);
17 }
18 else {
19 1 require Test2::EventFacet::About;
20 1 require Test2::EventFacet::Amnesty;
21 1 require Test2::EventFacet::Assert;
22 1 require Test2::EventFacet::Control;
23 1 require Test2::EventFacet::Error;
24 1 require Test2::EventFacet::Hub;
25 1 require Test2::EventFacet::Info;
26 1 require Test2::EventFacet::Info::Table;
27 1 require Test2::EventFacet::Meta;
28 1 require Test2::EventFacet::Parent;
29 1 require Test2::EventFacet::Plan;
30 1 require Test2::EventFacet::Render;
31 1 require Test2::EventFacet::Trace;
32  
33 1 ▶ *plugins = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
34 return (
35 1 'Test2::EventFacet::About',
36 'Test2::EventFacet::Amnesty',
37 'Test2::EventFacet::Assert',
38 'Test2::EventFacet::Control',
39 'Test2::EventFacet::Error',
40 'Test2::EventFacet::Hub',
41 'Test2::EventFacet::Info',
42 'Test2::EventFacet::Info::Table',
43 'Test2::EventFacet::Meta',
44 'Test2::EventFacet::Parent',
45 'Test2::EventFacet::Plan',
46 'Test2::EventFacet::Render',
47 'Test2::EventFacet::Trace',
48 );
49 1 };
50 }
51 }
52  
53 1 ▶use Test2::Util::Importer 'Test2::Util::Importer' => 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 1 our @EXPORT_OK = qw{
56 facets
57 filter_events
58 event_groups
59 };
60  
61 1 my %TYPES;
62 1 for my $class (__PACKAGE__->plugins) {
63 13 my $type = $class;
64 13 $type =~ s/^Test2::EventFacet:://g;
65  
66 13 ▶ next unless $class->isa('Test2::EventFacet');
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa("Test2::EventFacet") 1 12 13
67 12 my $key;
68 12 ▶ $key = $class->facet_key if $class->can('facet_key');
Branch: 1 branch
BranchTrueFalseTotal
if $class->can("facet_key") 12 0 12
69 12 ▶ $key = lc($type) unless defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 12 12
70  
71 12 $TYPES{$type} = $class;
72 12 $TYPES{lc($type)} = $class;
73 12 $TYPES{$key} = $class;
74 }
75  
76 3 ▶sub filter_events {
Subroutine filter_events: called CC=5 SCAR=16.1
Pod undocumented
77 3 my $events = shift;
78  
79 3 ▶ my @match = map { rtype($_) eq 'REGEXP' ? $_ : qr/^\Q$_\E::/} @_;
Branch: 1 branch
BranchTrueFalseTotal
rtype($_) eq 'REGEXP' ? : 1 2 3
80  
81 3 my @out;
82 3 for my $e (@$events) {
83 15 ▶ my $trace = $e->facet_data->{trace} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $trace = $e->facet_data->{"trace"} or next 15 0 15
84 15 ▶ next unless grep { $trace->{frame}->[3] =~ $_ } @match;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$trace->{"frame"}[3] =~ /$_/;} @match 7 8 15
85 8 push @out => $e;
86 }
87  
88 3 return \@out;
89 }
90  
91 1 ▶sub event_groups {
Subroutine event_groups: called CC=6 SCAR=17.9
Pod undocumented
92 1 my $events = shift;
93  
94 1 my $out = {};
95 1 for my $e (@$events) {
96 8 my $trace = $e->facet_data->{trace};
97 8 ▶ my $tool = ($trace && $trace->{frame} && $trace->{frame}->[3]) ? $trace->{frame}->[3] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$trace && $trace->{'frame'} && $trace->{'frame'}[3] ? : 7 1 8
Condition66%4/6
$trace and $trace->{"frame"} and $trace->{"frame"}[3]
!ll&&!rl&&r
107
$trace and $trace->{"frame"}
!ll&&!rl&&r
107
MC/DC33%1/3
$trace and $trace->{"frame"} and $trace->{"frame"}[3]
$trace $trace->{"frame"} $trace->{"frame"}[3]
Truth table50%2/4
A and B and C
A= $traceB= $trace->{"frame"}C= $trace->{"frame"}[3]
ABCresult
0XX0
10X0
1100
1111
98  
99 8 ▶ unless ($tool) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tool) 1 7 8
100 1 push @{$out->{__NA__}} => $e;
101 1 next;
102 }
103  
104 7 my ($pkg, $sub) = ($tool =~ m/^(.*)(?:::|')([^:']+)$/);
105  
106 7 push @{$out->{$pkg}->{$sub}} => $e;
107 7 push @{$out->{$pkg}->{__ALL__}} => $e;
108 }
109  
110 1 return $out;
111 }
112  
113 6 ▶sub facets {
Subroutine facets: called CC=9 SCAR=22.0
Pod documented
114 6 my ($type, $events) = @_;
115  
116 6 my ($key, $is_list);
117 6 my $class = $TYPES{$type};
118 6 ▶ if ($class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class) { } 4 2 6
119 4 ▶ $key = $class->facet_key || lc($type);
Condition33%1/3
$class->facet_key || lc $type
l!l&&r!l&&!r
400
MC/DC0%0/2
$class->facet_key || lc $type
$class->facet_key lc $type
Truth table33%1/3
A || B
A= $class->facet_keyB= lc $type
ABresult
1X1
011
000
120 4 $is_list = $class->is_list;
121 }
122 else {
123 2 $key = lc($type);
124 }
125  
126 6 my @out;
127 6 for my $e (@$events) {
128 42 my $fd = $e->facet_data;
129 42 ▶ my $f = $fd->{$key} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $f = $fd->{$key} or next 9 33 42
130  
131 9 ▶ my $list = defined($is_list) ? $is_list : rtype($f) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
defined $is_list ? : 7 2 9
132  
133 9 ▶ if ($list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list) { } 6 3 9
134 6 ▶ push @out => map { $class ? $class->new($_) : $_ } @$f;
Branch: 1 branch
BranchTrueFalseTotal
$class ? : 7 2 9
135 }
136 else {
137 3 ▶ push @out => $class ? $class->new($f) : $f;
Branch: 1 branch
BranchTrueFalseTotal
$class ? : 2 1 3
138 }
139 }
140  
141 6 return \@out;
142 }
143  
144 1 1;
145  
146 __END__
« blib/lib/Test2/Event/V2.pm ↑ Summary blib/lib/Test2/Util/Sub.pm »