lib/Pod/pod2classdocs.pl untested

filter: Statementstmt 0.0% 0 / 78 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 29 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 148 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2 #!perl
3 use Pod::Usage;
4 use Pod::Classdoc;
5 use Cwd;
6 use Getopt::Long qw(:config no_ignore_case permute);
7 use File::Path;
8  
9 use strict;
10 use warnings;
11  
12 our $VERSION = '1.01';
13  
14 my $pwd = getcwd();
15  
16 my $home;
17 my $csspath;
18 my $jspath;
19 my $imgpath;
20 my $closeimg = 'closedbook.gif';
21 my $container = 'index.html';
22 my $help = 0;
23 my $openimg = 'openbook.gif';
24 my $path = './classdocs';
25 my $projpod = 0;
26 my $rootimg = 'globe.gif';
27 my $title = '';
28 my $verbose = 0;
29 my $noicons = 0;
30 my $jstoc = 0;
31 my $root = undef;
32 my $writeall = 1;
33 my $order;
34  
35 my @srclibs = ();
36  
37 GetOptions(
38 'a|writeall' => \$writeall,
39 'c|closeimg=s' => \$closeimg,
40 'f|file=s' => \$container,
41 'h|help' => \$help,
42 'H|home=s' => \$home,
43 'i|imgpath=s' => \$imgpath,
44 'j|jspath=s' => \$jspath,
45 'J|jstoc' => \$jstoc,
46 'O|openimg=s' => \$openimg,
47 'o|output=s' => \$path,
48 'p|project' => \$projpod,
49 'r|rootimg=s' => \$rootimg,
50 'R|root=s', => \$root,
51 's|csspath=s' => \$csspath,
52 't|title=s' => \$title,
53 'v|verbose' => \$verbose,
54 'y|order=s' => \$order,
55 'z|noicons' => \$noicons,
56 '<>' => sub { push @srclibs, @_; }
57 );
58  
59 pod2usage(1) if $help;
60  
61 die "No source libraries specified."
62 unless @srclibs;
63  
64 if ($jstoc) {
65 eval 'require HTML::ListToTree;';
66 die $@ if $@;
67 }
68  
69 $root ||= $title || 'Classdocs';
70  
71 my @order = ();
72 @order = split /\s*,\s*/, $order
73 if $order;
74  
75 mkpath $path;
76  
77 my $classdocs = Pod::Classdoc->new($path, $title, $verbose);
78  
79 $classdocs->openProject(@srclibs) or die $@;
80  
81 $classdocs->writeClassdocs or die $@;
82  
83 #
84 # generate index and container frame doc unless project docs specified
85 #
86 unless ($projpod) {
87 if ($jstoc) {
88 $jspath ||= "js/dtree.js";
89 $csspath ||= "css/dtree.css";
90 $imgpath ||= "img";
91 my $toc = $classdocs->getTOC(@order);
92 ($toc) = ($toc=~/^.*?<\!-- INDEX BEGIN -->(.+)<\!-- INDEX END/is);
93 my $tree = HTML::ListToTree->new(Text => $root, Link => $home, Source => $toc)
94 or die $@;
95 my $widget = $tree->render(
96 CloseIcon => $closeimg,
97 CSSPath => $csspath,
98 IconPath => $imgpath,
99 JSPath => $jspath,
100 UseIcons => (!$noicons),
101 OpenIcon => $openimg,
102 RootIcon => $rootimg,
103 ) or die $@;
104
105 die "Can't open $path/toc.html: $!"
106 unless open(OUTF, ">$path/toc.html");
107 print OUTF $widget;
108 close OUTF;
109 #
110 # if writeall, then generate supporting directories/files
111 #
112 if ($writeall) {
113 my ($jsfile, $cssfile);
114 ($jspath, $jsfile) = ($jspath=~/^(.*)[\/\\]([^\/\\]+)$/);
115 ($csspath, $cssfile) = ($csspath=~/^(.*)[\/\\]([^\/\\]+)$/);
116 mkpath "$path/$jspath";
117 mkpath "$path/$csspath";
118 mkpath "$path/$imgpath";
119 die $@
120 unless $tree->writeJavascript("$path/$jspath/$jsfile") &&
121 $tree->writeCSS("$path/$csspath/$cssfile") &&
122 $tree->writeIcons("$path/$imgpath");
123 }
124 }
125 else {
126 $classdocs->writeTOC or die $@;
127 }
128 $classdocs->writeFrameContainer($container, $home) or die $@;
129 }
130  
131 =pod
132  
133 =head1 NAME
134  
135 pod2classdocs
136  
137 =head1 SYNOPSIS
138  
139 pod2classdocs [options] <source-path> [ <source-path> ... ]
140  
141 Options:
142 -a|-writeall write all Javascript, CSS, and icons for
143 a Javascript tree TOC
144 -c|-closeimg <filename> image file used for HTML::ListToTree closed
145 nodes; default 'closedbook.gif'
146 -f|-file output filename for root document;
147 default 'index.html'
148 -h|-help display this help and exit
149 -H|-home <path> path to a root document added to the index tree
150 -i|-imgpath <path> path to image directory for ProjectDocs and
151 HTML::ListToTree; default <output root>/img
152 -j|-jspath <path> path to Javascript files for HTML::ListToTree;
153 default <output root>/js/dtree.js
154 -J|-jstoc use Javascript tree for table of contents (via
155 HTML::ListToTree); default is HTML list
156 -O|-openimg <filename> image file used for HTML::ListToTree open
157 nodes; default 'openbook.gif'
158 -o|-out|-output <path> target root directory path for generated
159 documents; default './classdocs'
160 -p|-project output is part of project docs (via
161 Pod::Classdoc::Project)
162 -r|-rootimg <filename> image file used for root of HTML::ListToTree
163 tree; default is openimg
164 -R|-root <name> name of tree root node
165 -s|-csspath <path> path to CSS files for HTML::ListToTree;
166 default <output root>/css/dtree.css
167 -t|-title <title> project title
168 -v|-verbose enable diagnostic messages
169 -y|-order "<pkglist>" specify order of packages in TOC; <pkglist> is
170 comma separated list of names, e.g.,
171 "DBI,DBD::_::dr,DBD::_::db,DBD::_::st"
172 -z|-noicons no icons in HTML::ListToTree tree widget;
173 default is icons on
174  
175 Multiple source library directories can be specified:
176  
177 pod2classdocs -o /path/to/outputdir /path/to/lib1 /path/to/lib2
178  
179 =head1 DESCRIPTION
180  
181 Generates classdocs via L<Pod::Classdoc> output with an L<HTML::ListToTree> index.
182