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 35     35   22940 use strict;
  35         100  
  35         1203  
4 35     35   225 use warnings;
  35         89  
  35         1023  
5 35     35   214 use namespace::autoclean;
  35         94  
  35         4138  
6              
7             our $VERSION = '0.40';
8              
9 35     35   3084 use Markdent::Types;
  35         88  
  35         286  
10              
11 35     35   907406 use Moose::Role;
  35         136  
  35         410  
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 3334     3334   5578 my $self = shift;
24              
25 3334         91585 $self->handler->handle_event( $self->_make_event(@_) );
26             }
27             ## use critic
28              
29             sub _make_event {
30 5259     5259   9322 my $self = shift;
31 5259         8215 my $class = shift;
32              
33 5259 50       17230 my $real_class = $class =~ /::/ ? $class : 'Markdent::Event::' . $class;
34              
35 5259         158096 return $real_class->new(@_);
36             }
37              
38             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
39             sub _detab_text {
40 1628     1628   2801 my $self = shift;
41 1628         2409 my $text = shift;
42              
43             # Ripped off from Text::Mardkown
44 1628         2391 ${$text} =~ s{ ^
  1628         4001  
45             (.*?)
46             \t
47 3         19 }
48             { $1 . (q{ } x (4 - length($1) % 4))}xmge;
49 1628         3342  
50             return;
51             }
52              
53 3320     3320   5714 sub _debug_look_for {
54             my $self = shift;
55 3320 50       92617  
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.40
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) 2021 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