script/podpp

filter: Statementstmt 60.0% 33 / 55 Branchbran 33.3% 8 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod n/a totaltotal 53.9% 48 / 89 CC 8 SCAR 14.9
CC
8
Cov
52%
arg_D
12.0
arg_U
6.0
fix_DUI
4.0
CRAP 4.5
« lib/Pod/PP/State.pm ↑ Summary lib/Pod/PP/State/Info.pm »
1 #!/usr/local/bin/perl
2 10 ▶ eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
Branch: 1 branch
BranchTrueFalseTotal
if $running_under_some_shell 0 10 10
3 if $running_under_some_shell;
4
5 #
6 # $Id: podpp.PL,v 0.1 2001/04/25 10:41:49 ram Exp $
7 #
8 # Copyright (c) 2000-2001, Raphael Manfredi
9 #
10 # You may redistribute only under the terms of the Artistic License,
11 # as specified in the README file that comes with the distribution.
12 #
13 # HISTORY
14 # $Log: podpp.PL,v $
15 # Revision 0.1 2001/04/25 10:41:49 ram
16 # Baseline for first Alpha release.
17 #
18 # $EndLog$
19 #
20  
21 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 10 ▶use FindBin qw($Bin);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 10 ▶use lib "$Bin/wild_lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 10 ▶use Log::Agent;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 10 logconfig(-prefix => $0);
28  
29 10 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 10 Getopt::Long::config(qw(no_ignore_case));
31  
32 10 my @include;
33 my %defs;
34 10 my $output;
35  
36 10 fix_DUI();
37 10 ▶&usage unless GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
unless &GetOptions("h|help", \&main::usage, "o|output=s", \$output, "I=s", \&main::arg_I, "D=s", \&main::arg_D, "U=s", \&main::arg_U) 0 10 10
38 'h|help' => \&usage,
39 'o|output=s' => \$output,
40 'I=s' => \&arg_I,
41 'D=s' => \&arg_D,
42 'U=s' => \&arg_U,
43 );
44  
45 #
46 # Argument processing
47 #
48 # Fills in @include and %defs, for -I and -D args.
49 # -U args are processed by making sure the item is not listed in %defs
50 # Arguments are parsed left to right
51  
52 4 ▶sub arg_I {
Subroutine arg_I: called CC=2 SCAR=8.4
53 4 my ($option, $value) = @_;
54 4 ▶ unless (-d $value) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $value) 0 4 4
55 0 logwarn "ignoring -I $value";
56 0 return;
57 }
58 4 push(@include, $value);
59 }
60  
61 0 ▶sub arg_D {
Subroutine arg_D: not called CC=3 SCAR=24.8
62 0 my ($option, $value) = @_;
63 0 ▶ if ($value =~ /^\w+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value =~ /^\w+$/) { } 0 0 0
elsif ($value =~ /^(\w+)=(.*)/) { } 0 0 0
64 0 $defs{$value} = '';
65 0 return;
66 } elsif ($value =~ /^(\w+)=(.*)/) {
67 0 $defs{$1} = $2;
68 0 return;
69 }
70 0 logwarn "ignoring -D $value";
71 }
72  
73 0 ▶sub arg_U {
Subroutine arg_U: not called CC=2 SCAR=17.9
74 0 my ($option, $value) = @_;
75 0 ▶ unless ($value =~ /^\w+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ /^\w+$/) 0 0 0
76 0 logwarn "ignoring -U $value";
77 0 return;
78 }
79 0 delete $defs{$value};
80 }
81  
82 #
83 # fix_DUI
84 #
85 # Fix @ARGV in place
86 # Each -D, -U or -I followed by text is separated from the following
87 # text for Getopt::Long to properly parse them. Otherwise, it will
88 # complain that DFOO is not an option when faced with -DFOO=BAR
89 #
90 10 ▶sub fix_DUI {
Subroutine fix_DUI: called CC=4 SCAR=13.9
91 10 ▶ for (my $i = 0; $i < @ARGV; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @ARGV) 34 10 44
92 34 my $arg = $ARGV[$i];
93 34 ▶ last if $arg eq '--'; # End of options
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "--" 0 34 34
94 34 ▶ if ($arg =~ /^(-[DUI])(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^(-[DUI])(.+)/) 4 30 34
95 4 my ($opt, $param) = ($1, $2);
96 4 splice(@ARGV, $i, 1, $opt, $param);
97 4 $i++; # Skip inserted argument
98 }
99 }
100 }
101  
102 0 ▶sub usage {
Subroutine usage: not called CC=1 SCAR=6.9
103 0 print STDERR <<EOM;
104 Usage: podpp [-h] [-I dir] [-D sym[=val]] [-U sym] [-o file] [files]
105 -D : set symbol value
106 -I : set include directory
107 -U : undefine symbol
108 -h/help : show this help message
109 -o/output : define output file (default is stdout)
110 EOM
111 0 exit 1;
112 }
113  
114 10 require Pod::PP;
115  
116 0 my $parser = Pod::PP->make(
117 -incpath => \@include,
118 -symbols => \%defs,
119 );
120  
121 0 ▶if (defined $output) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output) 0 0 0
122 0 ▶ open STDOUT, ">$output" or logdie "can't create $output: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">$output" or logdie("can't create ${output}: $!") 0 0 0
123 }
124  
125 0 ▶$parser->parse_from_filehandle(\*STDIN) unless @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 0 0
126 0 foreach my $file (@ARGV) {
127 0 $parser->parse_from_file($file);
128 }
129  
130 =head1 NAME
131  
132 podpp - POD pre-processor
133  
134 =head1 SYNOPSIS
135  
136 B<podpp> S<[B<-h>]>
137 S<[B<-I> I<dir>]>
138 S<[B<-D> I<sym>[=I<val>]]>
139 S<[B<-U> I<sym>]>
140 S<[B<-o> I<file>]>
141 S<[I<file1>, I<file2>, ...]>
142  
143 =head1 DESCRIPTION
144  
145 B<podpp> is a pre-processor for POD, implemented on top of
146 the C<Pod::PP> module. You should refer to L<Pod::PP> for the supported
147 POD directives, since this manpage only documents the pre-processor script.
148  
149 B<podpp> either takes a list of files from the command line or reads
150 from STDIN. The output is emitted to STDOUT or to a single file, as one
151 big happy stream.
152  
153 =head1 OPTIONS
154  
155 The following options are supported:
156  
157 =over 4
158  
159 =item B<-D> I<sym>[=I<val>]
160  
161 Defines symbol I<sym>. If I<val> is specified, the symbol I<sym> is set
162 to that value, otherwise it is marked defined but will not expand to anything.
163  
164 You may choose to leave a space between C<-D> and I<sym> if you wish.
165 For instance:
166  
167 -DSYMBOL
168 -DSYMBOL=simple_value
169 -D SYMBOL
170 -D SYMBOL='string with spaces'
171  
172 You may give as many C<-D> switches as you want.
173  
174 =item B<-I> I<dir>
175  
176 Appends I<dir> to the include search path. The space between C<-I> and
177 I<dir> is optional, as in:
178  
179 -I.. -I ../h
180  
181 You may give as many C<-I> switches as necessary. The include search path
182 is initially limited to C<".">, i.e. files to be included are located from the
183 place where the file making the inclusion lies.
184  
185 =item B<-U> I<sym>
186  
187 Undefines symbol I<sym>.
188  
189 =item B<-h>
190  
191 Prints a summary of the command line options.
192  
193 =item B<-o> I<file>
194  
195 Redirect output to named I<file>, instead of regular STDOUT.
196  
197 =back
198  
199 =head1 AUTHOR
200  
201 Raphael Manfredi F<E<lt>Raphael_Manfredi@pobox.comE<gt>>
202  
203 =head1 SEE ALSO
204  
205 Pod::PP(3).
206  
207 =cut
208  
« lib/Pod/PP/State.pm ↑ Summary lib/Pod/PP/State/Info.pm »