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