~ubuntu-branches/ubuntu/lucid/pdl/lucid

« back to all changes in this revision

Viewing changes to Doc/Pod/Select.pm

  • Committer: Bazaar Package Importer
  • Author(s): Ben Gertzfield
  • Date: 2002-04-08 18:47:16 UTC
  • Revision ID: james.westby@ubuntu.com-20020408184716-0hf64dc96kin3htp
Tags: upstream-2.3.2
ImportĀ upstreamĀ versionĀ 2.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#############################################################################
 
2
# Select.pm -- function to select portions of pod docs
 
3
#
 
4
# Based on Tom Christiansen's pod2text() function
 
5
# (with extensive modifications).
 
6
#
 
7
# Copyright (C) 1996 Tom Christiansen. All rights reserved.
 
8
# This file is part of "PodParser". PodParser is free software;
 
9
# you can redistribute it and/or modify it under the same terms
 
10
# as Perl itself.
 
11
#############################################################################
 
12
 
 
13
package PDL::Pod::Select;
 
14
 
 
15
$VERSION = 1.00;   ## Current version of this package
 
16
require  5.002;    ## requires Perl version 5.002 or later
 
17
 
 
18
=head1 NAME
 
19
 
 
20
podselect - function to extract selected sections of pod documentation
 
21
 
 
22
=head1 SYNOPSIS
 
23
 
 
24
    use PDL::Pod::Select;
 
25
    podselect (@filelist);
 
26
    podselect ({OUTPUT => "tmp.out"}, @filelist):
 
27
    podselect ({SELECT => ["NAME|SYNOPSIS", "OPTIONS"]}, @filelist):
 
28
    podselect ({OUTPUT => ">&STDERR", SELECT => ["DESCRIPTION"]}, "-");
 
29
 
 
30
=head1 DESCRIPTION
 
31
 
 
32
B<podselect()> is a function which will extract specified sections of
 
33
pod documentation from an input stream. This ability is already provided
 
34
in the B<PDL::Pod::Parser> module. Subclasses of B<PDL::Pod::Parser> that wish to
 
35
take advantage of this feature do I<not> need to derive from
 
36
B<PDL::Pod::Select>. B<PDL::Pod::Select> merely provides a single function named
 
37
B<podselect()> which provides this capability in function form (as
 
38
opposed to object form) for extracting the raw pod docs.
 
39
 
 
40
=cut
 
41
 
 
42
#############################################################################
 
43
 
 
44
use Exporter ();
 
45
use PDL::Pod::Parser;
 
46
@ISA = qw(Exporter);
 
47
@EXPORT = qw(&podselect);
 
48
 
 
49
use strict;
 
50
use diagnostics;
 
51
use Carp;
 
52
 
 
53
sub version {
 
54
    no strict;
 
55
    return  $VERSION;
 
56
}
 
57
 
 
58
 
 
59
=head2 podselect(\%options, @filelist)
 
60
 
 
61
B<podselect> will print the raw (untranslated) pod documentation of all
 
62
pod sections in the given input files specified by C<@filelist>
 
63
according to the given options.
 
64
 
 
65
If any argument to B<podselect> is a reference to a hash
 
66
(associative array) then the values with the following keys are
 
67
processed as follows:
 
68
 
 
69
=over 4
 
70
 
 
71
=item C<OUTPUT>
 
72
 
 
73
A string corresponding to the desired output file (or ">&STDOUT"
 
74
or ">&STDERR"). The default is to use standard output.
 
75
 
 
76
=item C<SELECT>
 
77
 
 
78
A reference to an array of sections specifications (as described in
 
79
L<PDL::Pod::Parser/"SECTION SPECIFICATIONS">) which indicate the desired set of pod
 
80
sections and subsections to be selected from input. If no section
 
81
specifications are given, then all sections of pod documentation are
 
82
used.
 
83
 
 
84
=back
 
85
 
 
86
All other arguments should correspond to the names of input files
 
87
containing pod documentation. A file name of "-" or "<&STDIN" will
 
88
be interpeted to mean standard input (which is the default if no
 
89
filenames are given).
 
90
 
 
91
=cut
 
92
 
 
93
sub podselect {
 
94
    my(@argv) = @_;
 
95
    my (@sections, $output);
 
96
    my $pod_parser = new PDL::Pod::Parser;
 
97
    my $num_inputs = 0;
 
98
    local($_);
 
99
    for (@argv) {
 
100
        if (ref($_)) {
 
101
            next unless (ref($_) eq 'HASH');
 
102
            $output = $_->{OUTPUT}  if (defined $_->{OUTPUT});
 
103
            if ((defined $_->{SELECT}) && (ref($_->{SELECT}) eq 'ARRAY')) {
 
104
                $pod_parser->select(@{$_->{SELECT}});
 
105
            }
 
106
        }
 
107
        else {
 
108
            $pod_parser->parse_from_file($_, $output);
 
109
            ++$num_inputs;
 
110
        }
 
111
    }
 
112
    $pod_parser->parse_from_file("-")  unless ($num_inputs > 0);
 
113
}
 
114
 
 
115
=head1 SEE ALSO
 
116
 
 
117
L<PDL::Pod::Parser>
 
118
 
 
119
=head1 AUTHOR
 
120
 
 
121
Brad Appleton E<lt>Brad_Appleton-GBDA001@email.mot.comE<gt>
 
122
 
 
123
Based on code for B<pod2text> written by
 
124
Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>
 
125
 
 
126
=cut
 
127
 
 
128
1;