line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2021-2023 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
447
|
use v5.26; |
|
1
|
|
|
|
|
4
|
|
7
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
5
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
37
|
use Object::Pad 0.800; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
40
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package App::sdview 0.11; |
13
|
|
|
|
|
|
|
class App::sdview :strict(params); |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
366
|
use List::Keywords qw( first ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
C - a terminal document viewer for POD and other syntaxes |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use App::sdview; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
exit App::sdview->new->run( "some-file.pod" ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This module implements a terminal-based program for viewing structured |
30
|
|
|
|
|
|
|
documents. It currently understands POD, some simple Markdown formatting, and |
31
|
|
|
|
|
|
|
a basic understanding of nroff (for manpages). Future versions may expand on |
32
|
|
|
|
|
|
|
these abilities, extending them or adding new formats. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
To actually use it, you likely wanted wanted to see the F script. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$ sdview Some::Module |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$ sdview lib/Some/Module.pm |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$ sdview README.md |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$ sdview man/somelib.3 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Various output plugins exist. By default it will output a terminal-formatted |
45
|
|
|
|
|
|
|
rendering of the document via the F pager, but it can also output |
46
|
|
|
|
|
|
|
plaintext, POD, Markdown. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$ sdview Some::Module -o plain > module.txt |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$ sdview Some::Module -o Markdown > module.md |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Permit loaded output modules to override |
55
|
|
|
|
|
|
|
our $DEFAULT_OUTPUT = "terminal"; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
use Module::Pluggable |
58
|
1
|
|
|
|
|
6
|
search_path => "App::sdview::Parser", |
59
|
|
|
|
|
|
|
sub_name => "PARSERS", |
60
|
1
|
|
|
1
|
|
128
|
require => 1; |
|
1
|
|
|
|
|
2
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
use Module::Pluggable |
63
|
1
|
|
|
|
|
4
|
search_path => "App::sdview::Output", |
64
|
|
|
|
|
|
|
sub_name => "OUTPUTS", |
65
|
1
|
|
|
1
|
|
136
|
require => 1; |
|
1
|
|
|
|
|
2
|
|
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
method run ( $file, %opts ) |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
68
|
0
|
|
|
0
|
0
|
|
{ |
69
|
0
|
|
|
|
|
|
my @PARSER_CLASSES = sort { $a->sort_order <=> $b->sort_order } PARSERS(); |
|
0
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my @OUTPUT_CLASSES = OUTPUTS(); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $parser_class; |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if( defined $opts{format} ) { |
75
|
0
|
0
|
|
|
|
|
$parser_class = first { $_->can( "format" ) and $_->format eq $opts{format} } @PARSER_CLASSES or |
|
0
|
0
|
|
|
|
|
|
76
|
|
|
|
|
|
|
die "Unrecognised format name $opts{format}\n"; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
if( ! -f $file ) { |
80
|
0
|
|
|
|
|
|
my $name = $file; |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
foreach my $class ( $parser_class ? ( $parser_class ) : @PARSER_CLASSES ) { |
83
|
0
|
0
|
|
|
|
|
defined( $file = $class->find_file( $name ) ) and |
84
|
|
|
|
|
|
|
$parser_class = $class, last; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
defined $file or |
88
|
|
|
|
|
|
|
die "Unable to find a file for '$name'\n"; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
0
|
|
|
|
$parser_class //= do { |
92
|
0
|
0
|
|
|
|
|
first { $_->can_parse_file( $file ) } @PARSER_CLASSES or |
|
0
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
die "Unable to find a handler for $file\n"; |
94
|
|
|
|
|
|
|
}; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
0
|
|
|
|
$opts{output} //= $DEFAULT_OUTPUT; |
97
|
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
my $output_class = first { $_->can( "format" ) and $_->format eq $opts{output} } @OUTPUT_CLASSES or |
|
0
|
0
|
|
|
|
|
|
99
|
|
|
|
|
|
|
die "Unrecognised output name $opts{output}\n"; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my @paragraphs = $parser_class->new->parse_file( $file ); |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
$output_class->new->output( @paragraphs ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 TODO |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=over 4 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Customisable formatting and style information in C. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item * |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Add more formats. ReST perhaps. Maybe others too. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Improved Markdown parser. Currently the parser is very simple. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Other outputs. Consider a L-based frontend. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Also more structured file writers - ReST. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=back |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 AUTHOR |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Paul Evans |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
0x55AA; |