Debian Codegraph @

t/test2.pl

raw symbols SCIP
1 #!/usr/local/bin/perl
2
3 # Original authors: don
4 # $Revision: $
5
6
7 use strict;
8 use warnings;
9 use Carp;
10 use Getopt::Long qw(:config no_ignore_case bundling);
11 use Data::Dumper ();
12
13 use Pod::POM;
14
15 # main
16 {
17 # local($SIG{__DIE__}) = sub { &Carp::confess };
18 my $self = bless { };
19
20 my $opts = $self->get_options([ "help|h" ], { });
21 $self->check_options($opts, [ ]); # die's on bad options
22
23
24 my $top_dir;
25 # Set up @INC to get right version of module
26 use File::Spec ();
27 BEGIN {
28 my $path = File::Spec->rel2abs($0);
29 (my $dir = $path) =~ s{(?:/[^/]+){2}\Z}{};
30 # unshift @INC, $dir . "/blib/lib", $dir . "/blib/arch";
31 unshift @INC, $dir . "/lib";
32
33 $top_dir = $dir;
34 }
35
36 my $test_dir = $top_dir . "/test_doc/source";
37 my $doc_dir = $top_dir . "/test_doc";
38 my $base_dir = "/owens_lib/cpan";
39
40 # my $dest_dir = "$top_dir/test_doc/big_out";
41 my $dest_dir = "$top_dir/test_doc/source";
42
43
44 use Pod::POM::View::Restructured;
45
46 my $link_cb = sub {
47 my ($text) = @_;
48
49 if ($text eq 'DBIx::Wrapper::Request') {
50 return ('DBIx-Wrapper-Request.html', $text);
51 }
52
53 return;
54 };
55
56 my $callbacks = { link => $link_cb };
57
58 chdir $dest_dir;
59
60 my $files = [
61 { source_file => "$base_dir/Pod-POM-View-Restructured/lib/Pod/POM/View/Restructured.pm",
62 dest_file => "Pod-POM-View-Restructured.rst",
63 callbacks => $callbacks,
64 },
65 { source_file => "$base_dir/JSON-DWIW/lib/JSON/DWIW.pm",
66 dest_file => "JSON-DWIW.rst",
67 callbacks => $callbacks,
68 },
69 { source_file => "$base_dir/DBIx/Wrapper/DBIx-Wrapper/lib/DBIx/Wrapper.pm",
70 dest_file => 'DBIx-Wrapper.rst',
71 callbacks => $callbacks,
72 },
73
74 { source_file => "$base_dir/DBIx/Wrapper/DBIx-Wrapper/lib/DBIx/Wrapper/Request.pm",
75 dest_file => 'DBIx-Wrapper-Request.rst',
76 callbacks => $callbacks,
77 no_toc => 1,
78 },
79
80 ];
81
82 my $conv = Pod::POM::View::Restructured->new;
83
84
85 my $rv = $conv->convert_files($files, "$dest_dir/index.rst", 'My Big Test', $dest_dir);
86
87 print STDERR Data::Dumper->Dump([ $rv ], [ 'rv' ]) . "\n\n";
88
89 chdir $doc_dir or die "couldn't chdir to $doc_dir";
90
91 my @cmd = ('make', 'html');
92 system {$cmd[0]} @cmd;
93
94 }
95
96 exit 0;
97
98 ###############################################################################
99 # Subroutines
100
101 ########## begin option processing ##########
102 sub print_usage {
103 print STDERR qq{\nUsage: @{[ ($0 =~ m{\A.*/([^/]+)\Z})[0] || $0 ]} options
104
105 Options:
106
107 [-h | --help] # this help msg
108 \n};
109 }
110
111 sub check_options {
112 my ($self, $opts, $required) = @_;
113
114 if (not $opts or $opts->{help}) {
115 $self->print_usage;
116 exit 1;
117 }
118
119 my $opt_ok = 1;
120 $required = [ ] unless $required;
121 foreach my $key (@$required) {
122 if (defined($opts->{$key})) {
123 if (my $v = $opts->{$key}) {
124 if (my $ref = ref($v)) {
125 if ($ref eq 'ARRAY' ) {
126 unless (@$v) {
127 $opt_ok = 0;
128 warn "missing required option '$key'
129 ";
130 }
131 }
132 }
133 }
134 }
135 else {
136 $opt_ok = 0;
137 warn "missing required option '$key'\n";
138 }
139 }
140
141 unless ($opt_ok) {
142 $self->print_usage;
143 exit 1;
144 }
145
146 return $opt_ok;
147 }
148
149 sub get_options {
150 my ($self, $spec, $defaults) = @_;
151 my %opts = $defaults ? %$defaults : ();
152 $spec = [ ] unless $spec;
153
154 my $process_opt = sub {
155 my ($key, $val) = @_;
156
157 if (scalar(@_) > 2) {
158 $opts{$key}{$val} = $_[2];
159 }
160 else {
161 if ( exists($opts{$key}) and (my $v = $opts{$key}) ) {
162 if (my $ref = ref($v)) {
163 if ($ref eq 'ARRAY' ) {
164 push @{ $opts{$key} }, $val;
165 return 1;
166 }
167 }
168 }
169
170 $opts{$key} = $val;
171 }
172 };
173
174 my $opt_rv = Getopt::Long::GetOptions(map { ($_ => $process_opt) } @$spec);
175
176 return $opt_rv ? \%opts : undef;
177 }
178 ########## end option processing ##########