File Coverage

blib/lib/Markdent/Role/BalancedEvent.pm
Criterion Covered Total %
statement 31 31 100.0
branch 4 6 66.6
condition 3 9 33.3
subroutine 17 17 100.0
pod n/a
total 55 63 87.3


line stmt bran cond sub pod time code
1             package Markdent::Role::BalancedEvent;
2              
3 34     34   26550 use strict;
  34         103  
  34         1299  
4 34     34   213 use warnings;
  34         97  
  34         928  
5 34     34   207 use namespace::autoclean;
  34         193  
  34         240  
6              
7             our $VERSION = '0.38';
8              
9 34     34   3039 use List::AllUtils qw( all );
  34         82  
  34         2333  
10 34     34   247 use Markdent::Types;
  34         82  
  34         285  
11 34     34   861708 use Params::ValidationCompiler qw( validation_for );
  34         118  
  34         2363  
12 34     34   324 use Specio::Declare;
  34         107  
  34         416  
13              
14 34     34   7866 use MooseX::Role::Parameterized;
  34         104  
  34         432  
15              
16             parameter compare => (
17             isa => t( 'ArrayRef', of => t('Str') ),
18             );
19              
20             role {
21             my $p = shift;
22              
23             my @compare = @{ $p->compare() || [] };
24              
25             my $validator = validation_for(
26             params => [
27             { type => t('EventObject') },
28             ],
29             );
30              
31             method balances_event => sub {
32 535     535   849 my $self = shift;
        535      
        535      
        535      
        535      
        535      
        535      
        535      
33 535         10752 my ($other) = $validator->(@_);
34              
35 535 50       38361 return 0 unless $self->name() eq $other->name();
36              
37 535 50 33     1396 return 0
      33        
      33        
38             unless ( $self->is_start() && $other->is_end() )
39             || ( $self->is_end() && $other->is_start() );
40              
41 535 100       1642 return 1 unless @compare;
42              
43 471     471   2667 return all { $self->$_() eq $other->$_() } @compare;
  471         13770  
44             };
45             };
46              
47             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.38
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) 2020 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