File Coverage

blib/lib/Markdent/Role/EventsAsMethods.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 26 26 100.0


line stmt bran cond sub pod time code
1             package Markdent::Role::EventsAsMethods;
2              
3 35     35   29274 use strict;
  35         101  
  35         1230  
4 35     35   208 use warnings;
  35         83  
  35         1168  
5 35     35   222 use namespace::autoclean;
  35         100  
  35         293  
6              
7             our $VERSION = '0.40';
8              
9 35     35   3548 use Scalar::Util qw( blessed );
  35         89  
  35         2337  
10              
11 35     35   283 use Moose::Role;
  35         80  
  35         521  
12              
13             with 'Markdent::Role::Handler';
14              
15             sub handle_event {
16 5483     5483 1 33303 my $self = shift;
17 5483         7952 my $event = shift;
18              
19 5483         17173 my $meth = $event->event_name;
20              
21 5483         16137 $self->$meth( $event->kv_pairs_for_attributes );
22             }
23              
24             1;
25              
26             # ABSTRACT: Turns events into method calls
27              
28             __END__
29              
30             =pod
31              
32             =encoding UTF-8
33              
34             =head1 NAME
35              
36             Markdent::Role::EventsAsMethods - Turns events into method calls
37              
38             =head1 VERSION
39              
40             version 0.40
41              
42             =head1 DESCRIPTION
43              
44             This role takes an object which does L<Markdent::Role::Event> role and turns it
45             into a method call.
46              
47             =head1 METHODS
48              
49             This role provides the following methods:
50              
51             =head2 $object->handle_event($event)
52              
53             Given an object which does L<Markdent::Role::Event> role, this method makes a
54             method call on C<$object> based on the event's name.
55              
56             The method name is the same as the value of C<< $event->event_name >>. The hash
57             reference returned by C<< $event->attributes >> is turned into a set of named
58             parameters for the method. However, any keys starting with "!" in the
59             attributes will not be passed to the method.
60              
61             So, for example, a L<Markdent::Event::StartLink> event turns into a method call
62             like this:
63              
64             $handler->start_link(
65             uri => $event->uri,
66             title => $title, # optional
67             id => $id, # optional
68             is_implicit_id => $event->is_implicit_id,
69             );
70              
71             =head1 ROLES
72              
73             This role does the L<Markdent::Role::Handler> role.
74              
75             =head1 BUGS
76              
77             See L<Markdent> for bug reporting details.
78              
79             Bugs may be submitted at L<https://github.com/houseabsolute/Markdent/issues>.
80              
81             I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
82              
83             =head1 SOURCE
84              
85             The source code repository for Markdent can be found at L<https://github.com/houseabsolute/Markdent>.
86              
87             =head1 AUTHOR
88              
89             Dave Rolsky <autarch@urth.org>
90              
91             =head1 COPYRIGHT AND LICENSE
92              
93             This software is copyright (c) 2021 by Dave Rolsky.
94              
95             This is free software; you can redistribute it and/or modify it under
96             the same terms as the Perl 5 programming language system itself.
97              
98             The full text of the license can be found in the
99             F<LICENSE> file included with this distribution.
100              
101             =cut