Markdent/Role/BalancedEvent.pm

filter: Statementstmt 100% 40 / 40 Branchbran 75.0% 6 / 8 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 83.3% 60 / 72 CC 8 SCAR 14.7
CC
8
Cov
86%
balances_event
9.4
__ANON__
2.1
BEGIN
1.0
CRAP 4.4
« Markdent/Parser.pm ↑ Summary Markdent/Parser/SpanParser.pm »
1 package Markdent::Role::BalancedEvent;
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.39';
8  
9 35 ▶use List::AllUtils qw( all );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 35 ▶use Markdent::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 35 ▶use Params::ValidationCompiler qw( validation_for );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 35 ▶use Specio::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 35 ▶use MooseX::Role::Parameterized;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 35 parameter compare => (
17 isa => t( 'ArrayRef', of => t('Str') ),
18 );
19  
20 role {
21 290 ▶ my $p = shift;
Subroutine __ANON__: called CC=2 SCAR=7.3
22  
23 290 ▶ my @compare = @{ $p->compare || [] };
Branch: 1 branch
BranchTrueFalseTotal
$p->compare or [] 70 220 290
24  
25 290 my $validator = validation_for(
26 params => [
27 { type => t('EventObject') },
28 ],
29 );
30  
31 method balances_event => sub {
32 537 ▶ my $self = shift;
Subroutine balances_event: called CC=7 SCAR=22.4
33 537 my ($other) = $validator->(@_);
34  
35 537 ▶ return 0 unless $self->name eq $other->name;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->name eq $other->name 0 537 537
36  
37 537 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_start and $other->is_end or $self->is_end and $other->is_start 0 537 537
Condition33%3/9
$self->is_start and $other->is_end or $self->is_end and $other->is_start
l!l&&r!l&&!r
05370
$self->is_start and $other->is_end
!ll&&!rl&&r
53700
$self->is_end and $other->is_start
!ll&&!rl&&r
00537
MC/DC0%0/4
$self->is_start and $other->is_end or $self->is_end and $other->is_start
$self->is_start $other->is_end $self->is_end $other->is_start
Truth table14%1/7
A and B or C and D
A= $self->is_startB= $other->is_endC= $self->is_endD= $other->is_start
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
38 unless ( $self->is_start && $other->is_end )
39 || ( $self->is_end && $other->is_start );
40  
41 537 ▶ return 1 unless @compare;
Branch: 1 branch
BranchTrueFalseTotal
unless @compare 64 473 537
42  
43 473 ▶ return all { $self->$_() eq $other->$_() } @compare;
Subroutine __ANON__: called CC=1 SCAR=0.0
44 290 };
45 35 };
46  
47 35 1;
48  
49 # ABSTRACT: A parameterized role for events which can check if they balance another event
50  
51 __END__
52  
53 =pod
54  
55 =encoding UTF-8
56  
57 =head1 NAME
58  
59 Markdent::Role::BalancedEvent - A parameterized role for events which can check if they balance another event
60  
61 =head1 VERSION
62  
63 version 0.39
64  
65 =head1 DESCRIPTION
66  
67 This role provides behavior for start and end events which can be checked for
68 a balancing event. This includes things like strong, emphasis, and code
69 start/end events.
70  
71 =head1 ROLE PARAMETERS
72  
73 This role accepts the following parameters:
74  
75 =over 4
76  
77 =item * compare => [ ... ]
78  
79 This should be a list of attribute names which will be compared between the
80 start and end events.
81  
82 =back
83  
84 =head1 METHODS
85  
86 This role provides the following methods:
87  
88 =head2 $event->balances_event($event2)
89  
90 Given an event, this returns true if two events balance each other. This is
91 done by comparing types (StartCode matches EndCode), as well as the attributes
92 provided in the compare parameter.
93  
94 =head1 BUGS
95  
96 See L<Markdent> for bug reporting details.
97  
98 Bugs may be submitted at L<https://github.com/houseabsolute/Markdent/issues>.
99  
100 I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
101  
102 =head1 SOURCE
103  
104 The source code repository for Markdent can be found at L<https://github.com/houseabsolute/Markdent>.
105  
106 =head1 AUTHOR
107  
108 Dave Rolsky <autarch@urth.org>
109  
110 =head1 COPYRIGHT AND LICENSE
111  
112 This software is copyright (c) 2021 by Dave Rolsky.
113  
114 This is free software; you can redistribute it and/or modify it under
115 the same terms as the Perl 5 programming language system itself.
116  
117 The full text of the license can be found in the
118 F<LICENSE> file included with this distribution.
119  
120 =cut
« Markdent/Parser.pm ↑ Summary Markdent/Parser/SpanParser.pm »