script/smartlinks.pl untested

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 105 CC 7 SCAR 31.4
CC
7
Cov
0%
main
56.0
help
2.0
BEGIN
2.0
CRAP 23.0
1 #!/usr/bin/env perl
2  
3 # util/smartlinks.pl - The successor to util/catalog_tests.pl.
4  
5 # This program is still under active development, and
6 # you're very welcome to improve it.
7 # Most of the code has already moved to the Text-SmartLinks subdirectory
8 # with the aim to make it generic enought to be usefule for any
9 # perl script, module or application.
10  
11 # Please read the Pod documentation at the end of file before reading and/or
12 # modifying the source.
13 # CAUTION: please make sure your changes don't break anything, because
14 # breakage of this script will also break http://perlcabal.org/syn/
15 # immediately. Running the tests of Text::SmartLinks and trying the script using
16 # perl smartlinks.pl --dir ../../t/ --out-dir ../../html/
17 # and then checking the result before committing is
18 # strongly recommended. Thank you for your contribution :)
19  
20 use strict;
21 use warnings;
22 no warnings 'once';
23  
24 use Getopt::Long;
25 use File::Basename;
26 use FindBin;
27 use File::Find::Rule;
28 use File::Slurp;
29 use Data::Dumper;
30  
31 #use Pod::Simple::HTML;
32  
33 use Text::SmartLinks;
34  
35 sub help () {
36 print <<_EOC_;
37 Usage:
38 $0 t/*/*.t t/*/*/*.t
39 $0 --dir t
40 $0 --css foo.css --out-dir=public_html t/syntax/*.t
41 $0 --check t/*/*.t t/*/*/*.t
42 $0 --check t/some/test.t
43 $0 --check --missing t/*/*.t t/*/*/*.t
44  
45 Options:
46 --help Show this help.
47 --check Only check the validity of the smartlinks, no
48 HTML outputs.
49 --missing Print files whitout smartlinks
50 --wiki Print out a wiki link to test files missing links
51 --count Show the count of links per file
52 --out-dir <dir> Specify the output directory for HTML files.
53 --css <file> Specify the CSS file used by the HTML outputs,
54 defaults to http://dev.perl.org/css/perl.css.
55 --test-res <ymlfile>
56 Set .yml file generated from Test::TAP::Model's
57 ``structure''. Usually <ymlfile> should be set
58 to ``smoke.yml''.
59 --pod-dir Specify the directory where the .pod and .pm files
60 are located. smarlinks.pl will recurse in the
61 subdirectories to locate the files. Defaults to lib/
62 --index Also generates an index.html page with links to
63 pages.
64 --dir <dir> Name of the directory where to look for .t files
65 recursively.
66 --line-anchor Insert line anchors to the resulting HTML pages.
67 --version <VERSION>
68 _EOC_
69 exit(0);
70 }
71  
72 sub main {
73 my ($pod_dir, $out_dir, $help, $cssfile, $yml_file, $index, $dir,$count,$wiki);
74 my $check;
75 my $line_anchor;
76 my $print_missing;
77 my $version;
78 GetOptions(
79 'check' => \$check,
80 'count' => \$count,
81 'missing' => \$print_missing,
82 'wiki' => \$wiki,
83 'pod-dir=s' => \$pod_dir,
84 'out-dir=s' => \$out_dir,
85 'css=s' => \$cssfile,
86 'help' => \$help,
87 'test-res=s' => \$yml_file,
88 'index' => \$index,
89 'dir=s' => \$dir,
90 'line-anchor' => \$line_anchor,
91 'version=s' => \$version,
92 ) or help();
93  
94 if ($help || !@ARGV && !$dir) {
95 help();
96 }
97 $cssfile ||= 'http://dev.perl.org/css/perl.css';
98  
99 my $sl = Text::SmartLinks->new({
100 count => $count,
101 check => $check,
102 line_anchor => $line_anchor,
103 print_missing => $print_missing,
104 wiki => $wiki, # #TODO: do we need this flag?
105 out_dir => $out_dir,
106 cssfile => $cssfile,
107 version => $version,
108 });
109  
110 $out_dir = $sl->out_dir;
111 mkdir $out_dir if !-d $out_dir;
112  
113 my @t_files = map glob, @ARGV;
114 push @t_files, File::Find::Rule->file()->name('*.t')->in($dir) if $dir;
115 $sl->process_test_files(@t_files);
116 $sl->process_yml_file($yml_file);
117  
118 die "--pod-dir was not given. It usually should be '.' or lib/\n" if not defined $pod_dir;
119 die "Directory '$pod_dir' does not exist\n" if not -e $pod_dir;
120 my @pod_files = sort File::Find::Rule->file()->name('*.pod', '*.pm')->relative->in($pod_dir);
121 $sl->{docs} = \@pod_files;
122 for my $pod_file (@pod_files) {
123 $sl->process_pod_file($pod_dir, $pod_file, 1);
124 }
125  
126 $sl->report_broken_links;
127 $sl->report_stats;
128 $sl->create_stats_page();
129 $sl->create_index() if $index;
130  
131 exit;
132 }
133  
134  
135 main();
136  
137 1;
138 __END__