File Coverage

blib/lib/Markdent/CapturedEvents.pm
Criterion Covered Total %
statement 33 33 100.0
branch n/a
condition n/a
subroutine 11 11 100.0
pod 3 3 100.0
total 47 47 100.0


line stmt bran cond sub pod time code
1             package Markdent::CapturedEvents;
2              
3 4     4   1823 use strict;
  4         8  
  4         129  
4 4     4   22 use warnings;
  4         8  
  4         106  
5 4     4   20 use namespace::autoclean;
  4         9  
  4         25  
6              
7             our $VERSION = '0.40';
8              
9 4     4   1566 use Markdent::Types;
  4         15  
  4         35  
10 4     4   106325 use Params::ValidationCompiler qw( validation_for );
  4         53287  
  4         302  
11 4     4   39 use Specio::Declare;
  4         10  
  4         47  
12              
13 4     4   2507 use Moose;
  4         1398625  
  4         36  
14 4     4   32569 use MooseX::StrictConstructor;
  4         67026  
  4         22  
15              
16             has _events => (
17             is => 'ro',
18             isa => t( 'ArrayRef', of => t('EventObject') ),
19             init_arg => 'events',
20             default => sub { [] },
21             );
22              
23             sub events {
24 3     3 1 12 @{ $_[0]->_events };
  3         91  
25             }
26              
27             {
28             my $validator = validation_for(
29             params => [ { type => t('EventObject') } ],
30             slurpy => t('EventObject'),
31             );
32              
33             sub capture_events {
34 264     264 1 464 my $self = shift;
35 264         4309 my @events = $validator->(@_);
36              
37 264         23467 push @{ $self->_events }, @events;
  264         7069  
38             }
39             }
40              
41             {
42             my $validator = validation_for(
43             params => [ { type => t('HandlerObject') } ],
44             );
45              
46             sub replay_events {
47 2     2 1 12 my $self = shift;
48 2         47 my ($handler) = $validator->(@_);
49              
50 2         556 $handler->handle_event($_) for $self->events;
51             }
52             }
53              
54             __PACKAGE__->meta->make_immutable;
55              
56             1;
57              
58             # ABSTRACT: Represents a series of captured events
59              
60             __END__
61              
62             =pod
63              
64             =encoding UTF-8
65              
66             =head1 NAME
67              
68             Markdent::CapturedEvents - Represents a series of captured events
69              
70             =head1 VERSION
71              
72             version 0.40
73              
74             =head1 DESCRIPTION
75              
76             This represents a series of captured parser events, and can be used to replay
77             them with a handle.
78              
79             =head1 METHODS
80              
81             This class provides the following methods:
82              
83             =head2 Markdent::CapturedEvents->new( events => \@events );
84              
85             Creates a new Markdent::CapturedEvents object.
86              
87             =head2 $captured->events
88              
89             Returns the captured events as an array.
90              
91             =head2 $captured->capture_events(@events)
92              
93             Captures one or more events.
94              
95             =head2 $captured->replay_events($handler)
96              
97             Given an object which does the L<Markdent::Role::Handler> role, this method
98             will replay all the captured events to that handler.
99              
100             =head1 BUGS
101              
102             See L<Markdent> for bug reporting details.
103              
104             Bugs may be submitted at L<https://github.com/houseabsolute/Markdent/issues>.
105              
106             I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
107              
108             =head1 SOURCE
109              
110             The source code repository for Markdent can be found at L<https://github.com/houseabsolute/Markdent>.
111              
112             =head1 AUTHOR
113              
114             Dave Rolsky <autarch@urth.org>
115              
116             =head1 COPYRIGHT AND LICENSE
117              
118             This software is copyright (c) 2021 by Dave Rolsky.
119              
120             This is free software; you can redistribute it and/or modify it under
121             the same terms as the Perl 5 programming language system itself.
122              
123             The full text of the license can be found in the
124             F<LICENSE> file included with this distribution.
125              
126             =cut