blib/lib/Devel/Trepan/Pod2Text.pm untested

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 114 CC 11 SCAR 29.5
CC
11
Cov
0%
help2podstring
42.0
pod2string
20.0
BEGIN
12.0
CRAP 19.1
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 use vars qw(@ISA @EXPORT);
14 @ISA = qw(Exporter); @EXPORT = qw(pod2string help2podstring);
15  
16 use warnings; use strict;
17  
18 use vars qw($HAVE_TEXT_COLOR $HAVE_TEXT);
19  
20 BEGIN {
21 $HAVE_TEXT_COLOR =
22 eval {
23 require Term::ANSIColor;
24 require Pod::Text::Color;
25 } ? 1 : 0;
26  
27 $HAVE_TEXT = eval {
28 require Pod::Text;
29 } ? 1 : 0;
30 }
31  
32 sub pod2string($;$$)
33 {
34 my ($input_file, $color, $width) = @_;
35  
36 $width = ($ENV{'COLUMNS'} || 80) unless $width;
37 $color = 0 unless $color;
38  
39 # Figure out what formatter we're going to use.
40 my $formatter = 'Pod::Text';
41 if ($color && $HAVE_TEXT_COLOR) {
42 $formatter = 'Pod::Text::Color';
43 } else {
44 $formatter = 'Pod::Text';
45 }
46  
47  
48 my $p2t = $formatter->new(width => $width, indent => 2, utf8=>1);
49 my $output_string;
50 open(my $out_fh, '>', \$output_string);
51 $p2t->parse_from_file($input_file, $out_fh);
52 return $output_string;
53 }
54  
55 sub help2podstring($;$$)
56 {
57 my ($input_string, $color, $width) = @_;
58  
59 $width = ($ENV{'COLUMNS'} || 80) unless $width;
60 $color = 0 unless $color;
61  
62 # Figure out what formatter we're going to use.
63 my $formatter = 'Pod::Text';
64 if ($color && $HAVE_TEXT_COLOR) {
65 $formatter = 'Pod::Text::Color';
66 } else {
67 $formatter = 'Pod::Text';
68 }
69  
70 my $p2t = $formatter->new(width => $width, indent => 2, utf8 => 1);
71 my $output_string;
72 open(my $out_fh, '>', \$output_string);
73 open(my $in_fh, '<', \$input_string);
74  
75 $input_string = "=pod\n\n$input_string" unless
76 "=pod\n" eq substr($input_string, 0, 4);
77 $input_string .= "\n=cut\n" unless
78 "\n=cut\n" eq substr($input_string, -6);
79 $p2t->parse_from_file($in_fh, $out_fh);
80 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;