Markdent/Role/Event.pm

filter: Statementstmt 72.2% 78 / 108 Branchbran 44.4% 8 / 18 Conditioncond 44.0% 11 / 25 MC/DCmcdc 26.6% 4 / 15 Subroutinesub 81.2% 13 / 16 Podpod 100% 1 / 1 totaltotal 62.8% 115 / 183 CC 27 SCAR 33.7
CC
27
Cov
64%
debug_dump
110.0
__ANON__
9.1
_debug_value
6.0
CRAP 29.2
↑ Summary Markdent/CLI.pm »
1 package Markdent::Role::Event;
2  
3 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 35 our $VERSION = '0.41';
8  
9 35 ▶use Markdent::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 35 ▶use MooseX::Role::Parameterized;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 35 parameter event_class => (
14 is => 'ro',
15 isa => t('Str'),
16 required => 1,
17 );
18  
19 1280 ▶role {
Subroutine __ANON__: called CC=9 SCAR=22.1
20 1280 my $p = shift;
21  
22 1280 my $class = $p->event_class;
23 1280 my ( $action, $event ) = $class =~ /::(Start|End)?(\w+)$/;
24  
25 # It's easier to hack this in rather than trying to find a general
26 # case for upper-case abbreviations in class names.
27 1280 $event =~ s/HTML/html/;
28  
29 1280 ▶ $event =~ s/(^|.)([A-Z])/$1 ? "$1\L_$2" : "\L$2"/ge;
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 632 1035 1667
30  
31 1280 my $event_name = join q{_}, map {lc} grep {defined} $action, $event;
32 1280 ▶ method event_name => sub {$event_name};
Subroutine event_name: called CC=1 SCAR=0.0
33  
34 1280 ▶ method name => sub {$event};
Subroutine name: called CC=1 SCAR=0.0
35  
36 1280 ▶ my $is_start = ( $action || q{} ) eq 'Start';
Condition100%2/2
$action || ''
l!l
890390
MC/DC100%1/1
$action || ''
$action
Truth table100%2/2
A
A= $action
Aresult
11
00
37 1280 ▶ method is_start => sub {$is_start};
Subroutine is_start: called CC=1 SCAR=0.0
38  
39 1280 ▶ my $is_end = ( $action || q{} ) eq 'End';
Condition100%2/2
$action || ''
l!l
890390
MC/DC100%1/1
$action || ''
$action
Truth table100%2/2
A
A= $action
Aresult
11
00
40 1280 ▶ method is_end => sub {$is_end};
Subroutine is_end: called CC=1 SCAR=0.0
41  
42 1280 my $is_inline = !defined $action;
43 0 ▶ method is_inline => sub {$is_inline};
Subroutine is_inline: not called CC=1 SCAR=1.2
44  
45 1280 my @required;
46 my @optional;
47  
48 1280 for my $attr ( grep { $_->name !~ /^_/ }
49 $class->meta->get_all_attributes ) {
50  
51 1090 my $name = $attr->name;
52  
53 1090 ▶ if ( $attr->is_required ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->is_required) { } 793 297 1090
54 793 push @required, [ $name, $attr->get_read_method ];
55 }
56 else {
57 297 ▶ die
Branch: 1 branch
BranchTrueFalseTotal
unless $attr->has_predicate or $attr->has_default or $attr->has_builder 0 297 297
Condition50%3/6
$attr->has_predicate or $attr->has_default or $attr->has_builder
l!l&&r!l&&!r
29700
$attr->has_predicate or $attr->has_default
l!l&&r!l&&!r
1491480
MC/DC0%0/3
$attr->has_predicate or $attr->has_default or $attr->has_builder
$attr->has_predicate $attr->has_default $attr->has_builder
Truth table50%2/4
A or B or C
A= $attr->has_predicateB= $attr->has_defaultC= $attr->has_builder
ABCresult
1XX1
01X1
0011
0000
58 "All optional attributes for an event must have a predicate or default value ($class - $name)"
59 unless $attr->has_predicate
60 || $attr->has_default
61 || $attr->has_builder;
62  
63 297 push @optional,
64 [
65 $name,
66 $attr->get_read_method,
67 $attr->predicate
68 ];
69 }
70 }
71  
72 1280 _make_kv_pairs_for_attribute_method( \@required, \@optional );
73 35 };
74  
75 1280 ▶sub _make_kv_pairs_for_attribute_method {
Subroutine _make_kv_pairs_for_attribute_method: called CC=1 SCAR=0.0
76 1280 my @required = @{ shift() };
77 1280 my @optional = @{ shift() };
78  
79 5406 ▶ method kv_pairs_for_attributes => sub {
Subroutine kv_pairs_for_attributes: called CC=5 SCAR=16.1
Subroutine __ANON__: called CC=5 SCAR=16.1
80 5406 my $event = shift;
81  
82 5406 my %p;
83  
84 5406 for my $pair (@required) {
85 3619 my ( $name, $reader ) = @{$pair};
86  
87 3619 $p{$name} = $event->$reader();
88 }
89  
90 5406 for my $triplet (@optional) {
91 1421 my ( $name, $reader, $pred ) = @{$triplet};
92  
93 1421 ▶ next if $pred && !$event->$pred();
Branch: 2 branches
BranchTrueFalseTotal
if $pred and not $event->$pred 56 1365 1421
if $pred and not $event->$pred 0 2 2
Condition66%4/6
$pred and not $event->$pred
!ll&&!rl&&r
13075856
$pred and not $event->$pred
!ll&&!rl&&r
200
MC/DC100%2/2
$pred and not $event->$pred
$pred not $event->$pred
MC/DC0%0/2
$pred and not $event->$pred
$pred not $event->$pred
Truth table100%3/3
A and not(B)
A= $predB= not $event->$pred
ABresult
0X0
100
111
Truth table33%1/3
A and not(B)
A= $predB= not $event->$pred
ABresult
0X0
100
111
94  
95 1365 $p{$name} = $event->$name();
96 }
97  
98 5406 return %p;
99 1280 };
100 }
101  
102 0 ▶sub debug_dump {
Subroutine debug_dump: not called CC=10 SCAR=47.0
Pod documented
103 0 my $self = shift;
104  
105 0 my $dump = ' - ' . $self->event_name . "\n";
106  
107 0 for my $attr ( sort { $a->name cmp $b->name }
108 $self->meta->get_all_attributes ) {
109 0 my $name = $attr->name;
110 0 my $reader = $attr->get_read_method;
111 0 my $pred = $attr->predicate;
112  
113 0 ▶ next if $pred && !$self->$pred();
Branch: 1 branch
BranchTrueFalseTotal
if $pred and not $self->$pred 0 0 0
Condition0%0/3
$pred and not $self->$pred
!ll&&!rl&&r
000
MC/DC0%0/2
$pred and not $self->$pred
$pred not $self->$pred
Truth table0%0/3
A and not(B)
A= $predB= not $self->$pred
ABresult
0X0
100
111
114  
115 0 my $val = $self->$reader();
116  
117 0 ▶ if ( ref $val && ref $val eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val and ref $val eq 'ARRAY') { } 0 0 0
elsif (ref $val and ref $val eq 'HASH') { } 0 0 0
Condition0%0/3
ref $val and ref $val eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $val and ref $val eq "ARRAY"
ref $val ref $val eq "ARRAY"
Truth table0%0/3
A and B
A= ref $valB= ref $val eq "ARRAY"
ABresult
0X0
100
111
118 0 $dump .= sprintf( ' %-16s: |%s|', $name, $val->[0] );
119 0 $dump .= "\n";
120  
121 0 for my $v ( @{$val}[ 1 .. $#{$val} ] ) {
122 0 $self->_debug_value($v);
123  
124 0 $dump .= q{ } x 22;
125 0 $dump .= "|$v|\n";
126 }
127 }
128 ▶ elsif ( ref $val && ref $val eq 'HASH' ) {
Condition0%0/3
ref $val and ref $val eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $val and ref $val eq "HASH"
ref $val ref $val eq "HASH"
Truth table0%0/3
A and B
A= ref $valB= ref $val eq "HASH"
ABresult
0X0
100
111
129 0 $dump .= sprintf( ' %-16s:', $name );
130 0 $dump .= "\n";
131  
132 0 for my $k ( sort keys %{$val} ) {
133 0 $dump .= q{ } x 22;
134 $dump .= sprintf(
135 '%-16s: %s', $k,
136 0 $self->_debug_value( $val->{$k} )
137 );
138 0 $dump .= "\n";
139 }
140 }
141 else {
142 0 $dump .= sprintf(
143 ' %-16s: %s', $name,
144 $self->_debug_value($val)
145 );
146 0 $dump .= "\n";
147 }
148 }
149  
150 0 return $dump;
151 }
152  
153 0 ▶sub _debug_value {
Subroutine _debug_value: not called CC=2 SCAR=17.9
154 0 ▶ return defined $_[1] ? $_[1] : '<undef>';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 0 0 0
155 }
156  
157 35 1;
158  
159 # ABSTRACT: Implements behavior shared by all events
160  
161 __END__
↑ Summary Markdent/CLI.pm »