File Coverage

blib/lib/Markdent/Role/DebugPrinter.pm
Criterion Covered Total %
statement 15 28 53.5
branch n/a
condition 0 2 0.0
subroutine 5 7 71.4
pod n/a
total 20 37 54.0


line stmt bran cond sub pod time code
1             package Markdent::Role::DebugPrinter;
2              
3 35     35   24277 use strict;
  35         80  
  35         1204  
4 35     35   238 use warnings;
  35         70  
  35         1001  
5 35     35   196 use namespace::autoclean;
  35         67  
  35         240  
6              
7             our $VERSION = '0.39';
8              
9 35     35   2864 use Markdent::Types;
  35         73  
  35         246  
10              
11 35     35   843159 use Moose::Role;
  35         131  
  35         418  
12              
13             has debug => (
14             is => 'rw',
15             isa => t('Bool'),
16             default => $ENV{MARKDENT_DEBUG} || 0,
17             );
18              
19             my $HR1 = q{=} x 70;
20             my $HR2 = q{-} x 70;
21              
22             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
23             sub _debug_parse_result {
24 0     0     my $self = shift;
25 0           my $text = shift;
26 0           my $type = shift;
27 0   0       my $extra = shift || [];
28              
29 0           my $msg = '[' . $text . "]\n" . $HR2 . "\n" . ' - ' . $type . "\n";
30 0           while ( @{$extra} ) {
  0            
31 0           my ( $key, $value ) = splice @{$extra}, 0, 2;
  0            
32 0           $msg .= sprintf( ' - %-10s : %s', $key, $value );
33 0           $msg .= "\n";
34             }
35              
36 0           $self->_print_debug($msg);
37             }
38             ## use critic
39              
40             sub _print_debug {
41 0     0     warn $HR1 . "\n" . ( ref $_[0] ) . "\n" . $_[1] . "\n";
42             }
43              
44             1;
45              
46             # ABSTRACT: A role for classes which output debugging information
47              
48             __END__
49              
50             =pod
51              
52             =encoding UTF-8
53              
54             =head1 NAME
55              
56             Markdent::Role::DebugPrinter - A role for classes which output debugging information
57              
58             =head1 VERSION
59              
60             version 0.39
61              
62             =head1 DESCRIPTION
63              
64             This role implements behavior shared by all classes which output debugging information.
65              
66             =head1 ATTRIBUTES
67              
68             This roles provides the following attributes:
69              
70             =head2 debug
71              
72             This is a read-write boolean attribute.
73              
74             It defaults to the value of C<$ENV{MARKDENT_DEBUG}>, if set, or 0.
75              
76             =head1 METHODS
77              
78             This roles provides the following methods:
79              
80             =head2 $object->_debug_parse_result( $text, $type, $extra )
81              
82             This method takes a text string, a parse result string (like "preformatted" or
83             "code_start"), and an optional array reference of extra key/value pairs.
84              
85             All of this will be concatenated together in a pretty(-ish) way and passed to
86             C<< $object->_print_debug >>.
87              
88             =head2 $object->_print_debug($text)
89              
90             This warns out the provided text along with a delimiter above the message.
91              
92             =head1 BUGS
93              
94             See L<Markdent> for bug reporting details.
95              
96             Bugs may be submitted at L<https://github.com/houseabsolute/Markdent/issues>.
97              
98             I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
99              
100             =head1 SOURCE
101              
102             The source code repository for Markdent can be found at L<https://github.com/houseabsolute/Markdent>.
103              
104             =head1 AUTHOR
105              
106             Dave Rolsky <autarch@urth.org>
107              
108             =head1 COPYRIGHT AND LICENSE
109              
110             This software is copyright (c) 2021 by Dave Rolsky.
111              
112             This is free software; you can redistribute it and/or modify it under
113             the same terms as the Perl 5 programming language system itself.
114              
115             The full text of the license can be found in the
116             F<LICENSE> file included with this distribution.
117              
118             =cut