lib/Pod/Tree/PerlBin.pm untested

filter: Statementstmt 0.0% 0 / 118 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 180 CC 2 SCAR 8.8
CC
2
Cov
0%
scan_xsubpp
6.0
new
2.0
scan
2.0
CRAP 2.4
1 package Pod::Tree::PerlBin;
2 use 5.006;
3 use strict;
4 use warnings;
5 use File::Find;
6 use HTML::Stream;
7 use Pod::Tree;
8 use Pod::Tree::HTML;
9 use Pod::Tree::PerlUtil;
10  
11 our $VERSION = '1.31';
12  
13 use base qw(Pod::Tree::PerlUtil);
14  
15 sub new {
16 my ( $class, $perl_dir, $html_dir, $link_map, %options ) = @_;
17  
18 my %defaults = (
19 col_width => 25,
20 bgcolor => '#ffffff',
21 text => '#000000'
22 );
23 my $options = { %defaults, %options, link_map => $link_map };
24  
25 my $perl_bin = {
26 perl_dir => $perl_dir,
27 html_dir => $html_dir,
28 bin_dir => 'bin',
29 top_page => 'bin.html',
30 depth => 1,
31 options => $options
32 };
33  
34 bless $perl_bin, $class;
35 }
36  
37 sub scan {
38 my ( $perl_bin, @dirs ) = @_;
39 $perl_bin->report1("scan");
40  
41 for my $dir (@dirs) {
42 opendir( DIR, $dir ) or next; # Windows apps sometimes leave non-existant dirs on $PATH
43 for my $file ( readdir(DIR) ) {
44 my $path = "$dir/$file";
45 -f $path and -x $path and -T $path or next;
46 $perl_bin->scan_file( $dir, $file );
47 }
48 }
49  
50 $perl_bin->scan_xsubpp;
51 }
52  
53 # A Very Special search for a Very Special executable
54 sub scan_xsubpp {
55 my $perl_bin = shift;
56  
57 my @inc = grep {m(^/)} @INC; # Don't ask.
58 File::Find::find( sub { $perl_bin->_scan_xsubpp }, @inc ) if @inc;
59 }
60  
61 sub _scan_xsubpp {
62 my $perl_bin = shift;
63  
64 /^xsubpp$/
65 and $perl_bin->scan_file( $File::Find::dir, $_ );
66 }
67  
68 sub scan_file {
69 my ( $perl_bin, $dir, $file ) = @_;
70  
71 my $source = "$dir/$file";
72 my $html_dir = $perl_bin->{html_dir};
73 my $bin_dir = $perl_bin->{bin_dir};
74 my $link = "$bin_dir/$file";
75 my $dest = "$html_dir/$link.html";
76  
77 my ( $name, $description ) = $perl_bin->get_name($source);
78 $name or return;
79  
80 # Translate the first copy found in $PATH
81 $perl_bin->{index}{$name} and return;
82  
83 $perl_bin->report2($source);
84  
85 my $entry = {
86 source => $source,
87 dest => $dest,
88 file => $file,
89 description => $description
90 };
91  
92 $perl_bin->{index}{$name} = $entry;
93 $perl_bin->{options}{link_map}->add_page( $file, $link );
94 $perl_bin->{options}{link_map}->add_page( $name, $link );
95 }
96  
97 sub index {
98 my $perl_bin = shift;
99 $perl_bin->report1("index");
100  
101 my $html_dir = $perl_bin->{html_dir};
102 my $bin_dir = $perl_bin->{bin_dir};
103 my $top_page = $perl_bin->{top_page};
104 my $dest = "$html_dir/$top_page";
105  
106 $perl_bin->mkdir("$html_dir/$bin_dir");
107  
108 my $fh = IO::File->new(">$dest");
109 defined $fh or die "Pod::Tree::PerlBin::index: Can't open $dest: $!\n";
110 my $stream = HTML::Stream->new($fh);
111  
112 my $options = $perl_bin->{options};
113 my $bgcolor = $options->{bgcolor};
114 my $text = $options->{text};
115 my $title = "Perl Executables";
116  
117 $stream->HTML->HEAD;
118 $stream->TITLE->text($title)->_TITLE;
119 $stream->_HEAD->BODY( BGCOLOR => $bgcolor, TEXT => $text );
120 $stream->H1->t($title)->_H1;
121  
122 $perl_bin->_emit_entries($stream);
123  
124 $stream->_BODY->_HTML;
125 }
126  
127 sub get_top_entry {
128 my $perl_bin = shift;
129  
130 +{
131 URL => $perl_bin->{top_page},
132 description => 'Executables'
133 };
134 }
135  
136 sub _emit_entries {
137 my ( $perl_bin, $stream ) = @_;
138  
139 my $bin_dir = $perl_bin->{bin_dir};
140 my $index = $perl_bin->{index};
141 my $options = $perl_bin->{options};
142 my $col_width = $options->{col_width};
143  
144 $stream->PRE;
145  
146 for my $name ( sort keys %$index ) {
147 my $entry = $index->{$name};
148 my $file = $entry->{file};
149 my $desc = $entry->{description};
150 my $pad = $col_width - length $name;
151  
152 $stream->A( HREF => "$bin_dir/$file.html" )->t($name)->_A;
153  
154 $pad < 1 and do {
155 $stream->nl;
156 $pad = $col_width;
157 };
158  
159 $stream->t( ' ' x $pad, $desc )->nl;
160 }
161  
162 $stream->_PRE;
163 }
164  
165 sub translate {
166 my $perl_bin = shift;
167 $perl_bin->report1("translate");
168  
169 my $index = $perl_bin->{index};
170 my $options = $perl_bin->{options};
171  
172 for my $name ( sort keys %$index ) {
173 $perl_bin->report2($name);
174 my $depth = $perl_bin->{depth};
175 $options->{link_map}->set_depth($depth);
176  
177 my $entry = $index->{$name};
178 my $source = $entry->{source};
179 my $dest = $entry->{dest};
180 my $html = Pod::Tree::HTML->new( $source, $dest, %$options );
181 $html->translate;
182 }
183 }
184  
185 1
186  
187 __END__