]>
Commit | Line | Data |
---|---|---|
1 | package App::Zealc::UsageExtractor; | |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
6 | ||
7 | our $VERSION = '0.000_001'; | |
8 | ||
9 | use parent qw/Pod::Simple::Methody/; | |
10 | ||
11 | use Text::Wrap qw/fill/; | |
12 | ||
13 | sub start_head1 { | |
14 | my ($self, $section) = @_; | |
15 | $self->{section} = ''; | |
16 | $self->{insection} = 1; | |
17 | } | |
18 | ||
19 | sub end_head1 { | |
20 | my ($self) = @_; | |
21 | $self->{insection} = 0; | |
22 | $self->{firstpara} = 1; | |
23 | } | |
24 | ||
25 | sub start_Para { | |
26 | my ($self) = @_; | |
27 | $self->handle_text("\n\n") unless $self->{firstpara}; | |
28 | $self->{firstpara} = 0; | |
29 | } | |
30 | ||
31 | sub handle_text { | |
32 | my ($self, $text) = @_; | |
33 | $self->{section} .= $text if $self->{insection}; | |
34 | $self->{$self->{section}} .= $text if $self->{section} && !$self->{insection}; | |
35 | } | |
36 | ||
37 | sub synopsis { | |
38 | my ($self) = @_; | |
39 | $self->{SYNOPSIS} | |
40 | } | |
41 | ||
42 | sub description { | |
43 | my ($self) = @_; | |
44 | fill '', '', $self->{DESCRIPTION} | |
45 | } | |
46 | ||
47 | sub usage { | |
48 | my ($self) = @_; | |
49 | $self->synopsis . "\n\n" . $self->description . "\n"; | |
50 | } | |
51 | ||
52 | 1; | |
53 | __END__ | |
54 | ||
55 | =encoding utf-8 | |
56 | ||
57 | =head1 NAME | |
58 | ||
59 | App::Zealc::UsageExtractor - Extract SYNOPSIS and DESCRIPTION sections from a module | |
60 | ||
61 | =head1 SYNOPSIS | |
62 | ||
63 | use App::Zealc::UsageExtractor; | |
64 | my $parser = App::Zealc::UsageExtractor->new; | |
65 | $parser->parse_file("path/to/file.pm"); | |
66 | ||
67 | say $parser->synopsis; # contents of synopsis section | |
68 | say $parser->description; # contents of description, filled | |
69 | say $parser->usage; # $parser->synopsis."\n\n".$parser->description."\n" | |
70 | ||
71 | =head1 DESCRIPTION | |
72 | ||
73 | App::Zealc::UsageExtractor is a L<Pod::Simple> subclass that extracts | |
74 | the SYNOPSIS and DESCRIPTION sections from a Pod file. | |
75 | ||
76 | =over | |
77 | ||
78 | =item synopsis | |
79 | ||
80 | The SYNOPSIS section of the file | |
81 | ||
82 | =item description | |
83 | ||
84 | The DESCRIPTION section of the file, filled using L<Text::Wrap> | |
85 | ||
86 | =item usage | |
87 | ||
88 | Equivalent to C<< $parser->synopsis."\n\n".$parser->description."\n" >> | |
89 | ||
90 | =back | |
91 | ||
92 | =head1 SEE ALSO | |
93 | ||
94 | L<zealc>, L<Zeal> | |
95 | ||
96 | =head1 AUTHOR | |
97 | ||
98 | Marius Gavrilescu, E<lt>marius@ieval.roE<gt> | |
99 | ||
100 | =head1 COPYRIGHT AND LICENSE | |
101 | ||
102 | Copyright (C) 2015 by Marius Gavrilescu | |
103 | ||
104 | This library is free software; you can redistribute it and/or modify | |
105 | it under the same terms as Perl itself, either Perl version 5.20.1 or, | |
106 | at your option, any later version of Perl 5 you may have available. | |
107 | ||
108 | ||
109 | =cut |