script/pods2html

filter: Statementstmt 83.0% 98 / 118 Branchbran 75.0% 27 / 36 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 89.4% 17 / 19 Podpod n/a totaltotal 78.5% 143 / 182 CC 17 SCAR 12.3
CC
17
Cov
79%
Translate_Dir
7.7
Index
6.0
Emit_Entries
6.0
CRAP 3.4
« lib/Pod/Tree/Node.pm ↑ Summary lib/Pod/Tree/HTML/PerlTop.pm »
1 #!/usr/local/bin/perl
2  
3 8 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use HTML::Stream;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Pod::Tree::HTML;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 my %Options = (
15 bgcolor => '#ffffff',
16 text => '#000000',
17 hr => 1,
18 toc => 1
19 );
20  
21 8 my $ok = GetOptions(
22 \%Options, "base:s", "css:s", "bgcolor:s", "empty", "index:s",
23 "module", "text:s", "toc!", "hr:i", "variables:s"
24 );
25 8 ▶$ok or die "Bad command line options\n";
Branch: 1 branch
BranchTrueFalseTotal
$ok or die "Bad command line options\n" 8 0 8
26  
27 8 my %Index;
28 my @Dirs;
29 8 my ( $PodDir, $HTMLDir, $Template, @Variables ) = @ARGV;
30 8 ▶$HTMLDir or die "pods2html PodDir HTMLDir\n";
Branch: 1 branch
BranchTrueFalseTotal
$HTMLDir or die "pods2html PodDir HTMLDir\n" 8 0 8
31  
32 8 $PodDir = canonpath File::Spec $PodDir;
33 8 $HTMLDir = rel2abs File::Spec $HTMLDir;
34  
35 8 mkpath($HTMLDir);
36  
37 8 ▶do $Options{variables} if $Options{variables};
Branch: 1 branch
BranchTrueFalseTotal
if $Options{"variables"} 2 6 8
38  
39 8 for (@Variables) {
40 1 chomp;
41 1 my ( $name, $value ) = split /=/, $_, 2;
42 1 $name =~ s(^\$)();
43 1 ${ $Pod::Tree::HTML::{$name} } = $value;
44 }
45  
46 8 umask 0022;
47 8 find(
48 {
49 wanted => \&Translate,
50 no_chdir => 1
51 },
52 $PodDir
53 );
54 8 ▶Index() if $Options{index};
Branch: 1 branch
BranchTrueFalseTotal
if $Options{"index"} 0 8 8
55 8 ▶Cleanup() unless $Options{empty};
Branch: 1 branch
BranchTrueFalseTotal
unless $Options{"empty"} 7 1 8
56  
57 88 ▶sub Translate {
Subroutine Translate: called CC=3 SCAR=11.0
58 88 ▶ -d and &Translate_Dir;
Branch: 1 branch
BranchTrueFalseTotal
-d $_ and &Translate_Dir 34 54 88
59 88 ▶ -f and &Translate_POD;
Branch: 1 branch
BranchTrueFalseTotal
-f $_ and &Translate_POD 54 34 88
60 }
61  
62 21 ▶sub MkDir {
Subroutine MkDir: called CC=3 SCAR=11.4
63 21 my $dir = shift;
64  
65 21 ▶ -d $dir and return;
Branch: 1 branch
BranchTrueFalseTotal
-d $dir and return 0 21 21
66 21 ▶ mkdir $dir, 0755 or die "Can't mkdir $dir: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
mkdir $dir, 493 or die "Can't mkdir ${dir}: $!\n" 21 0 21
67 21 push @Dirs, $dir;
68 }
69  
70 34 ▶sub Translate_Dir {
Subroutine Translate_Dir: called CC=6 SCAR=20.5
71 34 my $dir = $File::Find::name;
72  
73 34 ▶ if ( $HTMLDir eq rel2abs File::Spec $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HTMLDir eq "File::Spec"->rel2abs($dir)) 2 32 34
74 2 $File::Find::prune = 1;
75 2 return;
76 }
77  
78 32 ▶ if ( $Options{module} and ( m(/t$) or m(/blib$) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Options{"module"} and m[/t$] || m[/blib$]) 0 32 32
Condition16%1/6
$Options{"module"} and m[/t$] || m[/blib$]
!ll&&!rl&&r
3200
m[/t$] or m[/blib$]
l!l&&r!l&&!r
000
MC/DC0%0/3
$Options{"module"} and m[/t$] || m[/blib$]
$Options{"module"} m[/t$] m[/blib$]
Truth table25%1/4
A and B or C
A= $Options{"module"}B= m[/t$]C= m[/blib$]
ABCresult
0XX0
1000
11X1
1011
79 0 $File::Find::prune = 1;
80 0 return;
81 }
82  
83 32 $dir =~ s/^\Q$PodDir/$HTMLDir/o;
84 32 ▶ -d $dir or MkDir $dir;
Branch: 1 branch
BranchTrueFalseTotal
-d $dir or MkDir($dir) 11 21 32
85 32 print "$File::Find::name\n";
86 }
87  
88 54 ▶sub Translate_POD {
Subroutine Translate_POD: called CC=3 SCAR=11.0
89 54 ▶ m( \.(pm|pod)$ )x or return;
Branch: 1 branch
BranchTrueFalseTotal
/ \.(pm|pod)$ /x or return 54 0 54
90 54 my $source = $File::Find::name;
91  
92 54 ▶ Hidden($source) and return;
Branch: 1 branch
BranchTrueFalseTotal
Hidden($source) and return 8 46 54
93 46 print "$source\n";
94  
95 46 my $dest = $source;
96 46 $dest =~ s/^\Q$PodDir/$HTMLDir/o;
97 46 $dest =~ s( \.\w+$ )(.html)x;
98  
99 46 my $depth = Depth($source);
100  
101 46 my $pod = $source;
102 46 $pod =~ s(^\Q$PodDir\E/)();
103 46 $pod =~ s( \.\w+$ )()x;
104 46 $Index{$pod} = 1;
105  
106 46 my $html = Pod::Tree::HTML->new( $source, $dest, %Options );
107 46 $html->set_options( depth => $depth );
108 46 $html->translate($Template);
109 }
110  
111 54 ▶sub Hidden {
Subroutine Hidden: called CC=2 SCAR=6.9
112 54 my $source = shift;
113 54 ▶ $source =~ m(\.pm$) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$source =~ /\.pm$/ or return 0 8 46 54
114 8 $source =~ s(\.pm$)(.pod);
115 8 -e $source;
116 }
117  
118 46 ▶sub Depth {
Subroutine Depth: called CC=2 SCAR=6.9
119 46 my $source = shift;
120 46 my $tree = Pod::Tree->new;
121 46 $tree->load_file($source);
122 46 my $children = $tree->get_root->get_children;
123 46 my @pod = grep { $_->is_pod } @$children;
124 46 my $node1 = $pod[1];
125 46 ▶ $node1 or return '';
Branch: 1 branch
BranchTrueFalseTotal
$node1 or return "" 40 6 46
126  
127 40 my $text = $node1->get_deep_text;
128 40 my ($name) = split m(\s+-+\s+), $text;
129 40 $name =~ s(^\s+)();
130  
131 40 my @name = split /::/, $name;
132 40 @name - 1;
133 }
134  
135 0 ▶sub Index {
Subroutine Index: not called CC=2 SCAR=17.9
136 0 my $index = "$HTMLDir/index.html";
137 0 my $fh = IO::File->new(">$index");
138 0 ▶ defined $fh or die "Can't open $index: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $fh or die "Can't open ${index}: $!\n" 0 0 0
139  
140 0 my $stream = HTML::Stream->new($fh);
141  
142 0 my $title = $Options{index};
143 0 my $bgcolor = $Options{bgcolor};
144 0 my $text = $Options{text};
145  
146 0 $stream->HTML->HEAD;
147 0 $stream->TITLE->text($title)->_TITLE;
148 0 $stream->_HEAD->BODY( BGCOLOR => $bgcolor, TEXT => $text );
149 0 $stream->H1->t($title)->_H1;
150  
151 0 Emit_Entries($stream);
152  
153 0 $stream->_BODY->_HTML;
154 }
155  
156 0 ▶sub Emit_Entries {
Subroutine Emit_Entries: not called CC=2 SCAR=17.9
157 0 my $stream = shift;
158  
159 0 $stream->UL;
160  
161 0 for my $entry ( sort keys %Index ) {
162 0 $stream->LI->A( HREF => "$entry.html" )->t($entry)->_A->_LI;
163 }
164  
165 0 $stream->_UL;
166 }
167  
168 7 ▶sub Cleanup {
Subroutine Cleanup: called CC=2 SCAR=6.9
169 7 ▶ while (@Dirs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@Dirs) 18 7 25
170 18 my $dir = pop @Dirs;
171 18 rmdir $dir; # does nothing unless $dir is empty
172 }
173 }
174  
175 __END__
« lib/Pod/Tree/Node.pm ↑ Summary lib/Pod/Tree/HTML/PerlTop.pm »