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