File Coverage

blib/lib/Markdent/Role/FilterHandler.pm
Criterion Covered Total %
statement 19 19 100.0
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 26 28 92.8


line stmt bran cond sub pod time code
1             package Markdent::Role::FilterHandler;
2              
3 1     1   752 use strict;
  1         3  
  1         35  
4 1     1   6 use warnings;
  1         2  
  1         29  
5 1     1   8 use namespace::autoclean;
  1         2  
  1         7  
6              
7             our $VERSION = '0.38';
8              
9 1     1   90 use Markdent::Types;
  1         3  
  1         8  
10              
11 1     1   26698 use Moose::Role;
  1         3  
  1         15  
12              
13             with 'Markdent::Role::Handler';
14              
15             requires 'filter_event';
16              
17             has handler => (
18             is => 'ro',
19             does => t('HandlerObject'),
20             required => 1,
21             );
22              
23             sub handle_event {
24 14     14 0 26 my $self = shift;
25 14         22 my $event = shift;
26              
27 14         42 my $new_event = $self->filter_event($event);
28              
29 14 50       161 $self->handler()->handle_event($new_event)
30             if $new_event;
31             }
32              
33             1;
34              
35             # ABSTRACT: A role for handlers which act as filters
36              
37             __END__
38              
39             =pod
40              
41             =encoding UTF-8
42              
43             =head1 NAME
44              
45             Markdent::Role::FilterHandler - A role for handlers which act as filters
46              
47             =head1 VERSION
48              
49             version 0.38
50              
51             =head1 DESCRIPTION
52              
53             This role implements behavior and interface for filtering handlers. A filter
54             handler takes events and does something to some of them, and then passes them
55             on to another handler.
56              
57             =head1 REQUIRED METHODS
58              
59             =over 4
60              
61             =item * $handler->filter_event($event)
62              
63             This method will always be called with a single object which does the
64             L<Markdent::Role::Event> role.
65              
66             If this method returns a single event, it will be passed on to the next
67             handler. If it does not return an event, the event is dropped from the stream.
68              
69             =back
70              
71             =head1 ATTRIBUTES
72              
73             This role provides the following attributes:
74              
75             =head2 handler
76              
77             This is a read-only attribute. It is an object which does the
78             L<Markdent::Role::Handler> role.
79              
80             This is the handler to which the filter passes events after filtering.
81              
82             =head1 BUGS
83              
84             See L<Markdent> for bug reporting details.
85              
86             Bugs may be submitted at L<https://github.com/houseabsolute/Markdent/issues>.
87              
88             I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
89              
90             =head1 SOURCE
91              
92             The source code repository for Markdent can be found at L<https://github.com/houseabsolute/Markdent>.
93              
94             =head1 AUTHOR
95              
96             Dave Rolsky <autarch@urth.org>
97              
98             =head1 COPYRIGHT AND LICENSE
99              
100             This software is copyright (c) 2020 by Dave Rolsky.
101              
102             This is free software; you can redistribute it and/or modify it under
103             the same terms as the Perl 5 programming language system itself.
104              
105             The full text of the license can be found in the
106             F<LICENSE> file included with this distribution.
107              
108             =cut