1: #!/usr/bin/perl -w
2: ## This thing is on CPAN RIGHT NOW (well finished product)
3:
4: use strict;
5: use Pod::Parser;
6:
7: package Pod::Stripper; # this one is a little more stylish (see perlstyle)
8:
9: use vars qw/ @ISA $VERSION/;
10:
11: $VERSION = 0.2;
12:
13: sub Version { $VERSION };
14:
15: @ISA = qw(Pod::Parser); # Pod'Parser is also legal
16:
17: sub begin_input {
18: my ($Stripper) = @_;
19:
20: ## SUPER cause I override parseopts, so the user can't mess w/it
21: $Stripper->SUPER::parseopts('-want_nonPODs' => 1,
22: '-process_cut_cmd' => 9,
23: ,);
24:
25: return undef;
26: }
27:
28: sub cutting {
29: my ($Stripper, $cutting) = @_;
30:
31: $Stripper->{_CUTTING} = $cutting if defined $cutting;
32:
33: return $$Stripper{_CUTTING};
34: }
35:
36: sub begin_pod {
37: my ($Stripper) = @_;
38:
39: $Stripper->cutting(1);
40:
41: return undef;
42: }
43:
44: sub end_pod {
45: my ($Stripper) = @_;
46:
47: $Stripper->cutting(0);
48:
49: return;
50: }
51:
52: sub preprocess_paragraph
53: {
54: my ($Stripper, $text) = @_;
55:
56: if( $Stripper->cutting() ) {
57: my $out_fh = $Stripper->output_handle();
58: print $out_fh $text;
59: }
60: else {
61: return $text;
62: }
63: }
64:
65: sub command
66: {
67: my ($Stripper, $command, $paragraph) = @_;
68:
69: if ($command =~ /cut/i) {
70: $Stripper->cutting(1);
71: }
72: else {
73: $Stripper->cutting(0);
74: }
75: }
76:
77: sub verbatim {undef}
78: sub textblock {undef}
79: sub parseopts {undef}
80: 1;
81: ################################################################################
82: ################################################################################
83: ################################################################################
84:
85: package main;
86:
87: unless ( caller() ) {
88: ## if you say perl Stripper.pm
89: ## Create a Stripper object and have it parse from \*DATA
90:
91: my $Stripper = new Pod::Stripper();
92:
93: seek DATA,0,0;
94:
95: $Stripper->parse_from_filehandle(\*DATA);
96: }
97:
98: "here we go again";
99: __END__
100:
101: =head1 NAME
102:
103: Pod::Stripper - strip all pod, and output what's left
104:
105: =head1 SYNOPSIS
106:
107: $>perl Stripper.pm
108:
109: or
110:
111: #!/usr/bin/perl -w
112:
113: use strict;
114: use Pod::Stripper;
115:
116: my $Stripper = new Pod::Stripper();
117:
118: $Stripper->parse_from_filehandle(\*STDIN) unless (@ARGV);
119:
120: for my $ARGV (@ARGV) {
121: $Stripper->parse_from_file($ARGV);
122: }
123:
124: =head1 DESCRIPTION
125:
126: This be C<Pod::Stripper>, a subclass of C<Pod::Parser>. It parses perl files,
127: stripping out the pod, and dumping the rest (presumably code) to wherever
128: you point it to (like you do with C<Pod::Parser>).
129:
130: You could probably subclass it, but I don't see why.
131:
132: =head2 MOTIVATION
133:
134: I basically re-wrote C<Pod::Stripper> on two separate occasions, and I know
135: at least 2 other people who'd use it, and thought It'd make a nice addition.
136:
137: C<perl -MPod::Stripper -e"Pod::Stripper-E<gt>new()-E<gt>parse_from_file(shift)">
138: C< Stripper.pm>
139:
140: =head2 EXPORTS
141:
142: None.
143: This one be object oriented (at least I'm under the impression that it is).
144:
145: =head2 SEE ALSO
146:
147: C<Pod::Parser> and L<Pod::Parser>, esp. the C<input_*> and C<output_*> methods
148:
149: =head1 AUTHOR
150:
151: D.H. aka crazyinsomniac|at|yahoo.com.
152: http://crazyinsomniac.perlmonk.org/perl/
153:
154: =head1 LICENSE
155:
156: Copyright (c) 2002 by D.H. aka crazyinsomniac|at|yahoo.com.
157: All rights reserved.
158:
159: This module is free software;
160: you can redistribute it and/or modify it under
161: the same terms as Perl itself.
162:
163: =head1 PROPS
164:
165: props to all the perlmonks at perlmonks.org, and especially danger, jmcnamara, and gmax (they squash bugs)
166:
167: =cut
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pod::Stripper
by gmax (Abbot) on Feb 02, 2002 at 15:13 UTC | |
by crazyinsomniac (Prior) on Feb 03, 2002 at 11:44 UTC | |
by crazyinsomniac (Prior) on Feb 12, 2002 at 12:40 UTC |