| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 8 | ▶ | Cleanup() unless $Options{empty}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 88 | ▶ | sub Translate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Translate: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 88 | ▶ | -d and &Translate_Dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 88 | ▶ | -f and &Translate_POD; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 21 | ▶ | mkdir $dir, 0755 or die "Can't mkdir $dir: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition16%1/6
$Options{"module"} and m[/t$] || m[/blib$]
m[/t$] or m[/blib$]
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$]
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 54 | my $source = $File::Find::name; | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 54 | ▶ | Hidden($source) and return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 18 | my $dir = pop @Dirs; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 18 | rmdir $dir; # does nothing unless $dir is empty | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | __END__ | ||||||||||||||||||||||||||||||||||||||||||