line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (C) 2012, 2014 Rocky Bernstein <rocky@cpan.org> |
2
|
|
|
|
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 C<Devel::Trepan::Pod2Text> |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Devel::Trepan interface to convert POD into a string the debugger |
7
|
|
|
|
|
|
|
and then present using its output mechanism |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=cut |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package Devel::Trepan::Pod2Text; |
12
|
|
|
|
|
|
|
|
13
|
13
|
|
|
13
|
|
19295
|
use vars qw(@ISA @EXPORT); |
|
13
|
|
|
|
|
32
|
|
|
13
|
|
|
|
|
1131
|
|
14
|
|
|
|
|
|
|
@ISA = qw(Exporter); @EXPORT = qw(pod2string help2podstring); |
15
|
|
|
|
|
|
|
|
16
|
13
|
|
|
13
|
|
83
|
use warnings; use strict; |
|
13
|
|
|
13
|
|
43
|
|
|
13
|
|
|
|
|
317
|
|
|
13
|
|
|
|
|
160
|
|
|
13
|
|
|
|
|
34
|
|
|
13
|
|
|
|
|
443
|
|
17
|
|
|
|
|
|
|
|
18
|
13
|
|
|
13
|
|
87
|
use vars qw($HAVE_TEXT_COLOR $HAVE_TEXT); |
|
13
|
|
|
|
|
36
|
|
|
13
|
|
|
|
|
1339
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
BEGIN { |
21
|
|
|
|
|
|
|
$HAVE_TEXT_COLOR = |
22
|
13
|
50
|
|
13
|
|
47
|
eval { |
23
|
13
|
|
|
|
|
595
|
require Term::ANSIColor; |
24
|
13
|
|
|
|
|
13398
|
require Pod::Text::Color; |
25
|
|
|
|
|
|
|
} ? 1 : 0; |
26
|
|
|
|
|
|
|
|
27
|
13
|
50
|
|
|
|
60903
|
$HAVE_TEXT = eval { |
28
|
13
|
|
|
|
|
5194
|
require Pod::Text; |
29
|
|
|
|
|
|
|
} ? 1 : 0; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub pod2string($;$$) |
33
|
|
|
|
|
|
|
{ |
34
|
2
|
|
|
2
|
0
|
2164
|
my ($input_file, $color, $width) = @_; |
35
|
|
|
|
|
|
|
|
36
|
2
|
100
|
50
|
|
|
22
|
$width = ($ENV{'COLUMNS'} || 80) unless $width; |
37
|
2
|
50
|
|
|
|
11
|
$color = 0 unless $color; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Figure out what formatter we're going to use. |
40
|
2
|
|
|
|
|
7
|
my $formatter = 'Pod::Text'; |
41
|
2
|
50
|
33
|
|
|
15
|
if ($color && $HAVE_TEXT_COLOR) { |
42
|
0
|
|
|
|
|
0
|
$formatter = 'Pod::Text::Color'; |
43
|
|
|
|
|
|
|
} else { |
44
|
2
|
|
|
|
|
8
|
$formatter = 'Pod::Text'; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
2
|
|
|
|
|
28
|
my $p2t = $formatter->new(width => $width, indent => 2, utf8=>1); |
49
|
2
|
|
|
|
|
519
|
my $output_string; |
50
|
2
|
|
|
1
|
|
71
|
open(my $out_fh, '>', \$output_string); |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
51
|
2
|
|
|
|
|
1097
|
$p2t->parse_from_file($input_file, $out_fh); |
52
|
2
|
|
|
|
|
7070
|
return $output_string; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub help2podstring($;$$) |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
0
|
0
|
0
|
my ($input_string, $color, $width) = @_; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
0
|
|
|
0
|
$width = ($ENV{'COLUMNS'} || 80) unless $width; |
60
|
0
|
0
|
|
|
|
0
|
$color = 0 unless $color; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Figure out what formatter we're going to use. |
63
|
0
|
|
|
|
|
0
|
my $formatter = 'Pod::Text'; |
64
|
0
|
0
|
0
|
|
|
0
|
if ($color && $HAVE_TEXT_COLOR) { |
65
|
0
|
|
|
|
|
0
|
$formatter = 'Pod::Text::Color'; |
66
|
|
|
|
|
|
|
} else { |
67
|
0
|
|
|
|
|
0
|
$formatter = 'Pod::Text'; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
my $p2t = $formatter->new(width => $width, indent => 2, utf8 => 1); |
71
|
0
|
|
|
|
|
0
|
my $output_string; |
72
|
0
|
|
|
|
|
0
|
open(my $out_fh, '>', \$output_string); |
73
|
0
|
|
|
|
|
0
|
open(my $in_fh, '<', \$input_string); |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
0
|
$input_string = "=pod\n\n$input_string" unless |
76
|
|
|
|
|
|
|
"=pod\n" eq substr($input_string, 0, 4); |
77
|
0
|
0
|
|
|
|
0
|
$input_string .= "\n=cut\n" unless |
78
|
|
|
|
|
|
|
"\n=cut\n" eq substr($input_string, -6); |
79
|
0
|
|
|
|
|
0
|
$p2t->parse_from_file($in_fh, $out_fh); |
80
|
0
|
|
|
|
|
0
|
return $output_string; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
unless (caller) { |
84
|
|
|
|
|
|
|
print pod2string(__FILE__); |
85
|
|
|
|
|
|
|
print '-' x 30, "\n"; |
86
|
|
|
|
|
|
|
print pod2string(__FILE__, 1); |
87
|
|
|
|
|
|
|
print '-' x 30, "\n"; |
88
|
|
|
|
|
|
|
print pod2string(__FILE__, 1, 40); |
89
|
|
|
|
|
|
|
print '=' x 30, "\n"; |
90
|
|
|
|
|
|
|
print help2podstring("Now E<mdash> is the I<time>", 1, 40); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |