File Coverage

blib/lib/Markdent/Role/AnyParser.pm
Criterion Covered Total %
statement 29 34 85.2
branch 2 6 33.3
condition n/a
subroutine 9 9 100.0
pod n/a
total 40 49 81.6


line stmt bran cond sub pod time code
1             package Markdent::Role::AnyParser;
2              
3 34     34   19802 use strict;
  34         92  
  34         1117  
4 34     34   210 use warnings;
  34         106  
  34         884  
5 34     34   196 use namespace::autoclean;
  34         99  
  34         3639  
6              
7             our $VERSION = '0.38';
8              
9 34     34   2786 use Markdent::Types;
  34         86  
  34         276  
10              
11 34     34   865566 use Moose::Role;
  34         125  
  34         446  
12              
13             with 'Markdent::Role::DebugPrinter';
14              
15             has handler => (
16             is => 'ro',
17             does => t('HandlerObject'),
18             required => 1,
19             );
20              
21             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
22             sub _send_event {
23 3314     3314   5505 my $self = shift;
24              
25 3314         88729 $self->handler()->handle_event( $self->_make_event(@_) );
26             }
27             ## use critic
28              
29             sub _make_event {
30 5226     5226   8172 my $self = shift;
31 5226         8062 my $class = shift;
32              
33 5226 50       16483 my $real_class = $class =~ /::/ ? $class : 'Markdent::Event::' . $class;
34              
35 5226         153132 return $real_class->new(@_);
36             }
37              
38             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
39             sub _detab_text {
40 1619     1619   2595 my $self = shift;
41 1619         2276 my $text = shift;
42              
43             # Ripped off from Text::Mardkown
44 1619         2271 ${$text} =~ s{ ^
  1619         3675  
45             (.*?)
46             \t
47 3         23 }
48             { $1 . (q{ } x (4 - length($1) % 4))}xmge;
49 1619         3154  
50             return;
51             }
52              
53 3296     3296   5183 sub _debug_look_for {
54             my $self = shift;
55 3296 50       89048  
56             return unless $self->debug();
57 0 0          
  0            
58             my @look_debug = map { ref $_ ? "$_->[0] ($_->[1])" : $_ } @_;
59 0            
60 0           my $msg = "Looking for the following possible matches:\n";
61             $msg .= " - $_\n" for @look_debug;
62 0            
63             $self->_print_debug($msg);
64             }
65             ## use critic
66              
67             1;
68              
69             # ABSTRACT: A role for block and span parsers
70              
71             __END__
72              
73             =pod
74              
75             =encoding UTF-8
76              
77             =head1 NAME
78              
79             Markdent::Role::AnyParser - A role for block and span parsers
80              
81             =head1 VERSION
82              
83             version 0.38
84              
85             =head1 DESCRIPTION
86              
87             This role implements behavior shared by all types of parser.
88              
89             =head1 ATTRIBUTES
90              
91             This role provides the following attributes:
92              
93             =head2 handler
94              
95             This is a read-only attribute. It is an object which does the
96             L<Markdent::Role::Handler> role.
97              
98             This is required for all parsers.
99              
100             =head1 METHODS
101              
102             =head2 $parser->_detab_text(\$text)
103              
104             This takes a scalar reference to a piece of text that will be outputted and
105             replaces tabs with spaces. This is down I<after> a piece of text is parser for
106             markup.
107              
108             =head1 ROLES
109              
110             This class does the L<Markdent::Role::DebugPrinter> role.
111              
112             =head1 BUGS
113              
114             See L<Markdent> for bug reporting details.
115              
116             Bugs may be submitted at L<https://github.com/houseabsolute/Markdent/issues>.
117              
118             I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
119              
120             =head1 SOURCE
121              
122             The source code repository for Markdent can be found at L<https://github.com/houseabsolute/Markdent>.
123              
124             =head1 AUTHOR
125              
126             Dave Rolsky <autarch@urth.org>
127              
128             =head1 COPYRIGHT AND LICENSE
129              
130             This software is copyright (c) 2020 by Dave Rolsky.
131              
132             This is free software; you can redistribute it and/or modify it under
133             the same terms as the Perl 5 programming language system itself.
134              
135             The full text of the license can be found in the
136             F<LICENSE> file included with this distribution.
137              
138             =cut